ElevenLabs Text to Speech
Generate single-voice speech with binary or timestamped HTTP responses and single- or multi-context WebSockets.
Set MODELSELL_BASE_URL, MODELSELL_WS_URL, MODELSELL_API_KEY, and an available ELEVENLABS_VOICE_ID as shown in the ElevenLabs quickstart. The voice_id in the path selects a voice the upstream channel can use. List voices
| Transport | Models |
|---|---|
| HTTP synthesis | eleven_v4, eleven_v3, eleven_multilingual_v2, eleven_flash_v2_5, eleven_flash_v2, eleven_turbo_v2_5, eleven_turbo_v2 |
| HTTP synthesis with account-specific access | eleven_storytel_v2 |
| Text to Speech WebSockets | eleven_multilingual_v2, eleven_flash_v2_5, eleven_flash_v2, eleven_turbo_v2_5, eleven_turbo_v2 |
Use Text to Dialogue for eleven_v4_turbo and eleven_v3_conversational. The Turbo v2 models are deprecated. Their corresponding Flash versions are the supported replacements. Input length limits vary by model. ElevenLabs models · Storytel
HTTP synthesis and streaming
All four POST routes take the complete text in the JSON body. model_id defaults to eleven_multilingual_v2. Use the output_format query parameter to select the encoding, sample rate, and bitrate. The example uses mp3_44100_128. Higher bitrates and some PCM or WAV formats depend on the upstream plan. Create speech
| ModelSell path | Successful response |
|---|---|
/elevenlabs/v1/text-to-speech/{voice_id} | Binary audio |
/elevenlabs/v1/text-to-speech/{voice_id}/stream | Binary audio streamed as it is generated |
/elevenlabs/v1/text-to-speech/{voice_id}/with-timestamps | One JSON object with audio_base64, alignment, and normalized_alignment |
/elevenlabs/v1/text-to-speech/{voice_id}/stream/with-timestamps | Stream of JSON objects with audio and alignment chunks |
curl --fail-with-body --no-buffer \
"$MODELSELL_BASE_URL/elevenlabs/v1/text-to-speech/$ELEVENLABS_VOICE_ID/stream?output_format=mp3_44100_128" \
-H "xi-api-key: $MODELSELL_API_KEY" \
-H 'Content-Type: application/json' \
--data '{"model_id":"eleven_v4","text":"Welcome to the studio.","voice_settings":{"speed":1.0}}' \
--output speech.mp3With the timestamp routes, parse the JSON first and decode each audio_base64 value to recover the audio. Alignment contains the characters and parallel start and end time arrays in seconds. A streaming response can split JSON across network reads. Read complete records before decoding them. HTTP audio stream · Timestamps · Timestamp stream
Common request parameters
| Parameter | Location | Purpose |
|---|---|---|
voice_id | Path | Voice used to read the text. |
text | JSON, required | Text to read. The character limit depends on the model. |
model_id | JSON | Synthesis model. |
output_format | Query | Audio format, for example mp3_44100_128. |
voice_settings | JSON | Overrides saved voice settings. Depending on the model, options include speed, stability, similarity_boost, style, and use_speaker_boost. |
language_code, apply_text_normalization | JSON | Select language and text normalization. The normalization options are auto, on, and off, subject to model support. |
previous_text, next_text | JSON | Supply adjacent text to improve continuity between clips. |
For shared channels, omit provider-owned pronunciation dictionaries and historical request IDs. Request fields
Python SDK
Install elevenlabs and point base_url to the ModelSell /elevenlabs prefix. The example writes the returned audio chunks to an MP3. Official Python SDK
from os import environ
from elevenlabs.client import ElevenLabs
client = ElevenLabs(
base_url=environ["MODELSELL_BASE_URL"].rstrip("/") + "/elevenlabs",
api_key=environ["MODELSELL_API_KEY"],
)
audio = client.text_to_speech.convert(
voice_id=environ["ELEVENLABS_VOICE_ID"],
model_id="eleven_v4",
text="Welcome to the studio.",
output_format="mp3_44100_128",
)
with open("speech.mp3", "wb") as output:
for chunk in audio:
output.write(chunk)Text to Speech WebSockets
Use GET /elevenlabs/v1/text-to-speech/{voice_id}/stream-input?model_id=... to submit text incrementally. Initialize with a single space, send text chunks with trailing spaces, and send empty text to finish. flush: true asks the service to synthesize buffered text. Decode the audio fields in order and wait for the final frame. sync_alignment=true requests alignment on audio chunks. Synthesis WebSocket · Buffering and flush
Install websocket-client before running the Python example.
import base64
import json
import os
from urllib.parse import quote, urlencode
from websocket import create_connection
base = os.environ["MODELSELL_WS_URL"].rstrip("/")
voice = quote(os.environ["ELEVENLABS_VOICE_ID"], safe="")
query = urlencode({"model_id": "eleven_flash_v2_5", "output_format": "mp3_44100_128"})
socket = create_connection(
f"{base}/elevenlabs/v1/text-to-speech/{voice}/stream-input?{query}",
header=[f"Authorization: Bearer {os.environ['MODELSELL_API_KEY']}"],
timeout=30,
)
try:
socket.send(json.dumps({"text": " "}))
socket.send(json.dumps({"text": "Welcome to the studio. ", "flush": True}))
socket.send(json.dumps({"text": ""}))
with open("speech-ws.mp3", "wb") as output:
while True:
event = json.loads(socket.recv())
if event.get("error"):
raise RuntimeError(event)
if event.get("audio"):
output.write(base64.b64decode(event["audio"]))
if event.get("is_final") or event.get("isFinal"):
break
finally:
socket.close()For independent text streams sharing one voice, use GET /elevenlabs/v1/text-to-speech/{voice_id}/multi-stream-input?model_id=.... Give each stream a context_id. Initialize and send text for each context, then use close_context to finish that context. Route the returned audio using its context_id. Use close_socket when all contexts are finished. Multi-context WebSocket
HTTP usage uses the upstream character-cost when present and otherwise estimates the submitted text. WebSocket usage counts submitted text characters. ElevenLabs generation metadata