Skip to Content
API referenceOpenAI CompatibleAudio Speech

Audio Speech API

Turns text into speech. Compatible with OpenAI’s POST /v1/audio/speech; the response body is the audio file itself (binary), not JSON.

FamilyModelNotes
ElevenLabselevenlabs/eleven_v4See ElevenLabs
Gemini TTSgoogle/gemini-3.8-flash-tts and othersSee Gemini TTS

Accepted values for voice, response_format and other parameters vary by model; the family pages are authoritative.

Quickstart

base_urlhttps://api.ofox.io/v1
Endpointhttps://api.ofox.io/v1/audio/speech
Model IDgoogle/gemini-3.8-flash-tts
speech.py
import os from openai import OpenAI client = OpenAI(base_url="https://api.ofox.io/v1", api_key=os.environ["OFOX_API_KEY"]) with client.audio.speech.with_streaming_response.create( model="google/gemini-3.8-flash-tts", voice="Kore", input="Hello, and welcome to OfoxAI text to speech.", response_format="wav", ) as resp: resp.stream_to_file("speech.wav")

Request parameters

modelrequiredstring

Model ID; see the table above.

inputrequiredstring

The text to synthesize. An empty value returns 400.

voicestring

The voice. Required for Gemini TTS, where it takes a Google voice name (e.g. Kore); for ElevenLabs it takes a voice ID (e.g. 21m00Tcm4TlvDq8ikWAM). OpenAI voice names (e.g. alloy) do not work with either family.

Audio format. Accepted values vary by model: Gemini TTS supports wav and pcm; ElevenLabs supports mp3, opus, wav and pcm. An unsupported format returns 400.

Tone and style instructions, such as “read this in a cheerful tone”. Applies to Gemini TTS.

Language code, such as cmn-CN (Gemini TTS) or zh (ElevenLabs). If omitted, the model infers the language from the text.

stream_formatstring· valuessse

With sse, audio chunks are streamed as Server-Sent Events. Applies to Gemini TTS.

Provider-specific parameters, passed through to the provider, e.g. ElevenLabs’ {"elevenlabs": {"voice_settings": {...}}}. See each family page.

Response

On success, HTTP 200 with the audio file as the response body; Content-Type matches the format:

response_formatContent-Type
mp3audio/mpeg
wavaudio/wav
opusaudio/ogg
pcmaudio/L16;rate=<sample rate>;channels=1, headerless 16-bit PCM

Write the response body straight to a file. Errors are returned as JSON with Content-Type application/json, so check the status code first to avoid saving an error message as an audio file.

Common errors

HTTPError messageCauseFix
400model and input are required.model is missing, or input is emptySupply the missing parameters
400voice is required for speech completionvoice not sent for Gemini TTSPass a voice name, such as Kore
400unsupported Gemini response_format: mp3The model does not support the chosen formatUse a format listed on the family page
400Request contains an invalid argument.The Gemini TTS voice name does not existUse a valid voice name
404A voice with voice_id 'alloy' was not found.The ElevenLabs voice ID does not existUse a valid voice ID
400 endpoint_not_supportedModel 'openai/gpt-5.4' does not support the /v1/audio/speech endpoint on this platform.The chosen model is not a speech synthesis modelUse a model from the table above

For the full list of error codes, see Error handling.

Last updated on