Text to speech
Turn text into natural-sounding audio.
/v1/audio/speech
Generates spoken audio from text. The endpoint follows the OpenAI Audio API (audio.speech), so the official OpenAI SDKs work unchanged with base_url set to https://toksi.ai/v1. Available models include OpenAI's tts-1, tts-1-hd and gpt-4o-mini-tts, and MiniMax's speech-* series such as speech-2.8-hd and speech-2.8-turbo; see the Model Square for what is enabled. The response body is the audio file itself, not JSON.
Authentication
Send your key in the Authorization: Bearer sk-xxxx header.
Request body
| Parameter | Type | Required | Description |
|---|---|---|---|
model |
string | Yes | TTS model ID, e.g. tts-1, gpt-4o-mini-tts, speech-2.8-hd. |
input |
string | Yes | Text to speak. The length limit depends on the model; OpenAI models accept up to 4096 characters. |
voice |
string | Yes | Voice ID. Available voices depend on the model: OpenAI models use alloy, ash, coral, echo, fable, onyx, nova, sage, shimmer and others; MiniMax models use IDs such as Chinese (Mandarin)_Gentle_Senior. Get the full list with List voices below. |
instructions |
string | No | Tone and style instructions (gpt-4o-mini-tts only), e.g. "Speak in a calm, friendly voice". |
response_format |
string | No | OpenAI models: mp3 (default), opus, aac, flac, wav or pcm. MiniMax models: mp3 (default), wav, pcm or flac. |
speed |
number | No | Speaking speed, default 1.0. 0.25–4.0 for OpenAI models, 0.5–2.0 for MiniMax models. |
stream_format |
string | No | audio (default) or sse, for models that support streaming. |
Request example
curl https://toksi.ai/v1/audio/speech \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
-d '{
"model": "gpt-4o-mini-tts",
"input": "Hello! Your order has been shipped and will arrive tomorrow.",
"voice": "coral",
"instructions": "Speak in a cheerful and positive tone.",
"response_format": "mp3"
}' \
--output speech.mp3
from openai import OpenAI
client = OpenAI(base_url="https://toksi.ai/v1", api_key="sk-xxxx")
with client.audio.speech.with_streaming_response.create(
model="gpt-4o-mini-tts",
voice="coral",
input="Hello! Your order has been shipped and will arrive tomorrow.",
instructions="Speak in a cheerful and positive tone.",
) as resp:
resp.stream_to_file("speech.mp3")
import fs from "node:fs";
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://toksi.ai/v1", apiKey: "sk-xxxx" });
const resp = await client.audio.speech.create({
model: "gpt-4o-mini-tts",
voice: "coral",
input: "Hello! Your order has been shipped and will arrive tomorrow.",
instructions: "Speak in a cheerful and positive tone.",
});
fs.writeFileSync("speech.mp3", Buffer.from(await resp.arrayBuffer()));
Response
On success the response is the binary audio stream with a matching Content-Type header (for example audio/mpeg for mp3). Save it to a file or play it directly.
On failure the gateway returns a JSON error:
{
"error": {
"message": "Invalid value for 'voice'.",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
List voices
GET /v1/audio/voices?model={model} returns every voice of a model. It uses the same authentication and is free. MiniMax voices come live from the provider and are cached by the gateway for 24 hours.
curl "https://toksi.ai/v1/audio/voices?model=speech-2.8-hd" \
-H "Authorization: Bearer $API_KEY"
Response:
{
"success": true,
"data": [
{
"id": "Chinese (Mandarin)_Gentle_Senior",
"name": "Gentle Senior",
"language": "zh",
"description": "..."
},
{
"id": "English_Graceful_Lady",
"name": "Graceful Lady",
"language": "en"
}
]
}
| Field | Description |
|---|---|
id |
Voice ID to pass as voice. |
name |
Voice name. |
language |
Language code, e.g. zh, yue, en, ja, ko. |
description |
Voice description; may be empty. |
Notes
- If
modelis omitted, the gateway routes the request astts-1. - Check the Model Square for the price of each TTS model.
See also: Speech to text, Errors.