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.
| Field | Value |
|---|---|
| Base URL | https://api.gate.ai/openai/v1 |
| Auth | Authorization: Bearer <API_KEY> |
| Format | OpenAI-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
/audio/speechSubmit 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
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| Authorization | header | string | Yes | Gate.AI API Key. Format: Bearer <API_KEY> |
| Content-Type | header | string | Yes | Request body format: application/json |
Request Body
| Name | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Text-to-speech model ID. Currently only gpt-4o-mini-tts is supported |
| input | string | Yes | Text to synthesize |
| voice | string | Yes | Voice name, such as alloy |
| response_format | string | No | Output audio format, such as wav or mp3. Defaults to wav |
| stream_format | string | No | Set 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
1{2 "model": "gpt-4o-mini-tts",3 "input": "今天天气很好,我们一起去海边散步吧。",4 "voice": "alloy",5 "response_format": "mp3"6}Response Fields
| Name | Type | Description |
|---|---|---|
| audio bytes | binary | Default binary audio response data |
| speech.audio.delta | SSE event | SSE audio chunk event carrying a base64-encoded audio segment |
| speech.audio.done | SSE event | SSE completion event carrying usage and model_extend |
| usage | object | Text-to-speech usage. For binary responses it is written to backend logs; for SSE it appears on the final frame |
| model_extend.cost | string | Actual billed amount in USD. Billing is based on model_extend.cost |
Response Example
1HTTP/1.1 200 OK2Content-Type: audio/mpeg34(binary audio bytes)Response
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 200 | OK | Success. Returns transcription text, audio data, or SSE events synchronously. | AudioResponse |
| 400 | Bad Request | Invalid parameters, malformed body, or missing required fields such as model, file, or input. | OpenAIErrorResponse |
| 401 | Unauthorized | API key is invalid or missing. | OpenAIErrorResponse |
| 402 | Payment Required | Insufficient balance. | InsufficientBalanceResponse |
| 404 | Not Found | Model not found, or the audio endpoint is not enabled. | OpenAIErrorResponse |
| 413 | Payload Too Large | Uploaded file or request body is too large. | OpenAIErrorResponse |
| 429 | Too Many Requests | Too many requests. Please slow down. | OpenAIErrorResponse |
| 500 | Internal Server Error | Internal server error. | OpenAIErrorResponse |
| 502 | Bad Gateway | Upstream audio service failed. | OpenAIErrorResponse |