Audio
POST
/v1/audio/speechbinary audio streamPOST
/v1/audio/transcriptionsmultipart/form-dataSpeech (text-to-speech)
Returns audio bytes. The gateway streams the provider's response through without buffering (chunked transfer), so playback can start before synthesis finishes.
bash
curl "https://api.smartapihub.com/v1/audio/speech" \
-H "Authorization: Bearer $LLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/tts-1",
"input": "The gateway routes each request to the best available provider.",
"voice": "alloy",
"response_format": "mp3",
"speed": 1.0
}' --output speech.mp3| Field | Type | Notes |
|---|---|---|
model | string, required | Speech model id. |
input | string ≤ 40,000 chars, required | Text to speak. |
voice | string, required | Provider/model-specific voice name. |
response_format | mp3 | opus | aac | flac | wav | pcm | Default mp3. Sets the response Content-Type (audio/mpeg, audio/ogg, audio/aac, audio/flac, audio/wav, audio/pcm). |
speed | number 0.25–4 | |
routing | object | Routing override. |
Response headers include X-Request-Id, X-LLM-Provider, X-LLM-Model, X-LLM-Routing-Reason and X-LLM-Cost-Micro. Speech is priced per character or per audio second depending on the model (see the model's pricing keys).
Streaming behaviour
- Headers are sent as soon as the provider starts responding; bytes are forwarded as they arrive.
- Retries and fallback apply only before the first byte is forwarded. A provider failure after that closes the connection early; check that the received byte count matches
Content-Lengthwhen the provider supplies one, or that the container decodes cleanly. Idempotency-Keyis accepted (optional).
typescript
const res = await client.audio.speech.create({
model: 'openai/tts-1',
voice: 'alloy',
input: 'Hello from the gateway.',
response_format: 'mp3',
});
await fs.promises.writeFile('speech.mp3', Buffer.from(await res.arrayBuffer()));python
with client.audio.speech.with_streaming_response.create(
model="openai/tts-1", voice="alloy", input="Hello from the gateway."
) as response:
response.stream_to_file("speech.mp3")Transcriptions (speech-to-text)
Upload an audio file as multipart/form-data.
bash
curl "https://api.smartapihub.com/v1/audio/transcriptions" \
-H "Authorization: Bearer $LLM_API_KEY" \
-F model="openai/whisper-1" \
-F file=@meeting.mp3 \
-F language=en \
-F response_format=json| Form field | Notes |
|---|---|
file | required. Audio file; total request ≤ 25 MiB. |
model | required. Transcription model id. |
language | ISO-639-1 hint (e.g. en). |
response_format | json (default), text, verbose_json, srt, vtt — subject to model support. |
Response for json:
json
{ "text": "Welcome everyone, let's get started with the roadmap review." }verbose_json additionally returns language, duration and segments[] where the provider supplies them. Transcription is priced per audio second.
typescript
const transcription = await client.audio.transcriptions.create({
model: 'openai/whisper-1',
file: fs.createReadStream('meeting.mp3'),
});
console.log(transcription.text);python
with open("meeting.mp3", "rb") as f:
transcription = client.audio.transcriptions.create(model="openai/whisper-1", file=f)
print(transcription.text)Errors
| HTTP | code | Cause |
|---|---|---|
| 400 | validation_failed | Missing voice/input/file, out-of-range speed. |
| 413 | request_too_large | Multipart body over 25 MiB. |
| 415 | unsupported_media_type | Transcriptions called without multipart. |
| 403 | modality_not_allowed | Key scope excludes audio. |