ElevenLabs text to speech
Generate and stream speech with the official ElevenLabs JavaScript or Python SDK.
Set the ElevenLabs client's base URL to https://api.allmodels.io/el and use your AllModels API key.
Generate an audio file
https://api.allmodels.io/el/v1/text-to-speech/{voice_id}ElevenLabsimport { writeFile } from "node:fs/promises";
import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";
const client = new ElevenLabsClient({
apiKey: process.env.ALLMODELS_API_KEY,
baseUrl: "https://api.allmodels.io/el"
});
const audio = await client.textToSpeech.convert("pNInz6obpgDQGcFmaJgB", {
text: "Hello from AllModels",
modelId: "elevenlabs/eleven-turbo-v2-5",
outputFormat: "mp3_44100_128"
});
const chunks = await Array.fromAsync(audio, (chunk) => Buffer.from(chunk));
await writeFile("speech.mp3", Buffer.concat(chunks));Stream audio
Use the streaming method to process audio before the full response has arrived.
https://api.allmodels.io/el/v1/text-to-speech/{voice_id}/streamElevenLabsconst audio = await client.textToSpeech.stream("eve", {
text: "This response starts playing before generation is complete.",
modelId: "grok/grok-tts",
outputFormat: "mp3_44100_128"
});
for await (const chunk of audio) {
process.stdout.write(Buffer.from(chunk));
}Stream text into TTS
Use the Python SDK when text arrives incrementally. convert_realtime() connects to the ElevenLabs-compatible WebSocket, accepts an iterator of text chunks, and yields audio chunks.
wss://api.allmodels.io/el/v1/text-to-speech/{voice_id}/stream-inputElevenLabsimport os
from elevenlabs.client import ElevenLabs
client = ElevenLabs(
api_key=os.environ["ALLMODELS_API_KEY"],
base_url="https://api.allmodels.io/el",
)
def text_chunks():
yield "This text can arrive "
yield "one chunk at a time."
audio = client.text_to_speech.convert_realtime(
"pNInz6obpgDQGcFmaJgB",
text=text_chunks(),
model_id="elevenlabs/eleven-turbo-v2-5",
output_format="mp3_44100_128",
)
with open("speech.mp3", "wb") as output:
for chunk in audio:
output.write(chunk)The JavaScript SDK does not currently expose a client for this route. See the message-level reference when implementing incremental TTS outside the Python SDK.
Fields and formats
| Field | Description |
|---|---|
voice_id | Provider voice ID or supported voice alias. |
text | Text to synthesize. |
model_id | Model name or accepted alias. |
output_format | ElevenLabs-style format such as mp3_44100_128 or pcm_16000. |
voice_settings | Voice controls such as speed, where supported. |
AllModels does not convert audio between formats. If the selected model cannot produce the requested format, the API returns invalid_output_format.
Provider preferences can be sent through the SDK request as shown in the compatibility overview.
See the API reference for convert, stream, and convert_realtime.
