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://rutoken.ai/v1. Typical models are tts-1, tts-1-hd and gpt-4o-mini-tts. 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. |
input |
string | Yes | Text to speak, up to 4096 characters. |
voice |
string | Yes | Voice, e.g. alloy, ash, coral, echo, fable, onyx, nova, sage, shimmer. Available voices depend on the model. |
instructions |
string | No | Tone and style instructions (gpt-4o-mini-tts only), e.g. "Speak in a calm, friendly voice". |
response_format |
string | No | mp3 (default), opus, aac, flac, wav or pcm. |
speed |
number | No | Playback speed from 0.25 to 4.0. Default 1.0. |
stream_format |
string | No | audio (default) or sse, for models that support streaming. |
Request example
curl https://rutoken.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://rutoken.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://rutoken.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
}
}
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.