Skip to main content

POST /v1/audio/speech

Convert text into spoken audio.

  • Method: POST
  • Path: /v1/audio/speech
  • Auth: Bearer token in Authorization header
  • 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 requests

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)

Response

Binary audio is returned. With SDKs, use helpers to persist the stream. With cURL, pass --output file.ext to save.