Text to speech
Generate speech with the AllModels native API, raw HTTP, or a compatible SDK.
AllModels TTS endpoint
GET
/v1/ttsNative WebSocket/v1/tts is the native AllModels text-to-speech endpoint. It accepts text incrementally over a WebSocket and returns provider-native audio messages.
If your application already has the complete text and prefers a normal HTTP request, use the HTTP, ElevenLabs, or OpenAI examples below. They perform the same text-to-speech task through the corresponding compatibility transport.
For incremental text, frame handling, flushing, and backpressure, see Stream generated speech.
Generate speech from complete text
import { writeFile } from "node:fs/promises";const response = await fetch("https://api.allmodels.io/oai/audio/speech", { method: "POST", headers: { Authorization: `Bearer ${process.env.ALLMODELS_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ "model": "grok/grok-tts", "voice": "eve", "input": "Hello from AllModels", "response_format": "mp3"})});if (!response.ok) throw new Error(`AllModels request failed: ${response.status}`);await writeFile("speech.mp3", Buffer.from(await response.arrayBuffer()));Field names by client
| Concept | Native /v1/tts | ElevenLabs SDK | OpenAI SDK / HTTP |
|---|---|---|---|
| Text | WebSocket text frame | text | input |
| Model | model query parameter | model_id | model |
| Voice | voice query parameter | voice_id argument | voice |
| Output format | format query parameter | output_format | response_format |
| Provider preferences | Query parameters | JavaScript request query or Python request body | Request body |
| Provider options | provider_options query parameters | JavaScript request query or Python request body | Request body |
See the native TTS API reference for connection parameters, Audio formats for output choices, and SDK Compatibility for ElevenLabs or OpenAI details.
