POST /v1/audio/speech
Convert text into spoken audio.
- Method: POST
- Path: /v1/audio/speech
- Auth: Bearer token in Authorizationheader
- Content-Type: application/json
Request Parameters
- model(string, required): Target TTS model ID (e.g.,- gpt-4o-mini-tts).
- input(string, required, max 32768): The text to synthesize.
- voice(string, required): Voice preset name (e.g.,- alloy).
- speed(number, optional, > 0): Playback speed multiplier.
- instructions(string, optional): Additional synthesis hints.
Example Request
- Python
- Node.js
- cURL
from openai import OpenAI
from pathlib import Path
client = OpenAI(base_url="https://api.naga.ac/v1", api_key="YOUR_API_KEY")
speech_file_path = Path("speech.mp3")
resp = client.audio.speech.create(
    model="gpt-4o-mini-tts",
    voice="alloy",  # type: ignore
    input="Hello from NagaAI Text-to-Speech!"
)
resp.stream_to_file(speech_file_path)
import OpenAI from "openai";
import fs from "fs";
import path from "path";
const client = new OpenAI({ baseURL: "https://api.naga.ac/v1", apiKey: "YOUR_API_KEY" });
const speechFile = path.resolve("./speech.mp3");
const mp3 = await client.audio.speech.create({
  model: "gpt-4o-mini-tts",
  voice: "alloy",
  input: "Hello from NagaAI Text-to-Speech!",
});
const buffer = Buffer.from(await mp3.arrayBuffer());
await fs.promises.writeFile(speechFile, buffer);
curl https://api.naga.ac/v1/audio/speech \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o-mini-tts",
    "voice": "alloy",
    "input": "Hello from NagaAI Text-to-Speech!"
  }' \
  --output speech.mp3
Authentication
Provide your key as a Bearer token:
Authorization: Bearer YOUR_API_KEY
Response
Binary audio is returned. With SDKs, use helpers to persist the stream. With cURL, pass --output file.ext to save.
Response Fields
The response is a binary audio file stream. The format depends on the model and can be:
- MP3 (most common)
- Opus
- AAC
- FLAC
- WAV
- PCM
Use SDK stream helpers or save directly to a file using --output flag with cURL.