Text-to-Speech API Reference

    Submit text through the Gate.AI text-to-speech endpoint and generate audio synchronously. By default the response is binary audio; with stream_format=sse, the endpoint returns speech.audio.delta frames and a final speech.audio.done frame with usage and model_extend.

    FieldValue
    Base URLhttps://api.gate.ai/openai/v1
    AuthAuthorization: Bearer <API_KEY>
    FormatOpenAI-compatible; uses a JSON request body, returns binary audio by default, and can stream audio chunks over SSE

    Audio endpoints live under /openai/v1. Speech-to-text and text-to-speech are synchronous capabilities: no job_id is returned and no polling is required. For default binary TTS responses, billing details are recorded in Console Generations.

    Text to Speech

    POST/audio/speech

    Submit text to synthesize speech and synchronously receive audio. The default response body is a binary audio stream whose Content-Type follows response_format; SSE mode returns base64 audio chunks and final billing details.

    Request Parameters

    NameInTypeRequiredDescription
    AuthorizationheaderstringYesGate.AI API Key. Format: Bearer <API_KEY>
    Content-TypeheaderstringYesRequest body format: application/json

    Request Body

    NameTypeRequiredDescription
    modelstringYesText-to-speech model ID. Currently only gpt-4o-mini-tts is supported
    inputstringYesText to synthesize
    voicestringYesVoice name, such as alloy
    response_formatstringNoOutput audio format, such as wav or mp3. Defaults to wav
    stream_formatstringNoSet to sse to return text/event-stream. speech.audio.delta frames contain base64 audio chunks, and speech.audio.done includes usage and model_extend

    Example

    json
    1{2  "model": "gpt-4o-mini-tts",3  "input": "今天天气很好,我们一起去海边散步吧。",4  "voice": "alloy",5  "response_format": "mp3"6}

    Response Fields

    NameTypeDescription
    audio bytesbinaryDefault binary audio response data
    speech.audio.deltaSSE eventSSE audio chunk event carrying a base64-encoded audio segment
    speech.audio.doneSSE eventSSE completion event carrying usage and model_extend
    usageobjectText-to-speech usage. For binary responses it is written to backend logs; for SSE it appears on the final frame
    model_extend.coststringActual billed amount in USD. Billing is based on model_extend.cost

    Response Example

    text
    1HTTP/1.1 200 OK2Content-Type: audio/mpeg34(binary audio bytes)

    Response

    StatusMeaningDescriptionSchema
    200OKSuccess. Returns transcription text, audio data, or SSE events synchronously.AudioResponse
    400Bad RequestInvalid parameters, malformed body, or missing required fields such as model, file, or input.OpenAIErrorResponse
    401UnauthorizedAPI key is invalid or missing.OpenAIErrorResponse
    402Payment RequiredInsufficient balance.InsufficientBalanceResponse
    404Not FoundModel not found, or the audio endpoint is not enabled.OpenAIErrorResponse
    413Payload Too LargeUploaded file or request body is too large.OpenAIErrorResponse
    429Too Many RequestsToo many requests. Please slow down.OpenAIErrorResponse
    500Internal Server ErrorInternal server error.OpenAIErrorResponse
    502Bad GatewayUpstream audio service failed.OpenAIErrorResponse