Skip to main content

ElevenLabs

ElevenLabs provides high-quality AI voice technology, including speech-to-text capabilities through their transcription API.

PropertyDetails
DescriptionElevenLabs offers advanced AI voice technology with speech-to-text transcription and text-to-speech capabilities that support multiple languages and speaker diarization.
Provider Route on LiteLLMelevenlabs/
Provider DocElevenLabs API ↗
Supported Endpoints/audio/transcriptions, /audio/speech, /v1/realtime

Quick Start​

LiteLLM Python SDK​

Basic audio transcription with ElevenLabs
import litellm

# Transcribe audio file
with open("audio.mp3", "rb") as audio_file:
response = litellm.transcription(
model="elevenlabs/scribe_v1",
file=audio_file,
api_key="your-elevenlabs-api-key" # or set ELEVENLABS_API_KEY env var
)

print(response.text)

LiteLLM Proxy​

1. Configure your proxy​

ElevenLabs configuration in config.yaml
model_list:
- model_name: elevenlabs-transcription
litellm_params:
model: elevenlabs/scribe_v1
api_key: os.environ/ELEVENLABS_API_KEY

general_settings:
master_key: your-master-key

2. Start the proxy​

Start LiteLLM proxy server
litellm --config config.yaml

# Proxy will be available at http://localhost:4000

3. Make transcription requests​

Audio transcription with curl
curl http://localhost:4000/v1/audio/transcriptions \
-H "Authorization: Bearer $LITELLM_API_KEY" \
-H "Content-Type: multipart/form-data" \
-F file="@audio.mp3" \
-F model="elevenlabs-transcription" \
-F language="en" \
-F temperature="0.3"

Response Format​

ElevenLabs returns transcription responses in OpenAI-compatible format:

Example transcription response
{
"text": "Hello, this is a sample transcription with multiple speakers.",
"task": "transcribe",
"language": "en",
"words": [
{
"word": "Hello",
"start": 0.0,
"end": 0.5
},
{
"word": "this",
"start": 0.5,
"end": 0.8
}
]
}

Common Issues​

  1. Invalid API Key: Ensure ELEVENLABS_API_KEY is set correctly

Realtime Transcription (Scribe v2 Realtime)​

Since v1.113.0

LiteLLM serves scribe_v2_realtime through the proxy's OpenAI-compatible /v1/realtime WebSocket. Clients speak the OpenAI Realtime transcription protocol; LiteLLM opens the ElevenLabs realtime speech-to-text socket after the client's first session.update, forwards the audio and maps ElevenLabs transcripts back to OpenAI events. The model is realtime only; for file transcription use scribe_v2 on /audio/transcriptions.

1. Add the model to your config​

config.yaml
model_list:
- model_name: scribe-realtime
litellm_params:
model: elevenlabs/scribe_v2_realtime
api_key: os.environ/ELEVENLABS_API_KEY
# optional ElevenLabs settings
keyterms: ["LiteLLM", "Scribe"]
no_verbatim: true
vad_silence_threshold_secs: 1.2

api_key falls back to ELEVENLABS_API_KEY and is sent only in the xi-api-key header. api_base is optional and falls back to ELEVENLABS_API_BASE; set it to a regional host such as https://api.eu.residency.elevenlabs.io. It must be an absolute https:// or wss:// URL; LiteLLM keeps its host and port and replaces the path with /v1/speech-to-text/realtime. Embedded credentials and URL fragments are rejected.

These optional litellm_params become ElevenLabs session settings. Invalid values fail the session before anything is sent to ElevenLabs.

SettingTypeEffect
keytermslist of stringsBias recognition toward these terms
secondary_languageslist of ISO language codesAdditional languages to expect
no_verbatimboolRemove filler words and disfluencies
filter_background_audioboolSuppress background audio
vad_thresholdnumber, at least 0Voice activity detection threshold
vad_silence_threshold_secsnumber, at least 0Silence that ends a VAD segment
min_speech_duration_msinteger, at least 0Shortest speech that counts
min_silence_duration_msinteger, at least 0Shortest silence that counts
enable_loggingboolfalse turns on ElevenLabs zero retention mode, which ElevenLabs limits to enterprise accounts
Start LiteLLM Proxy
litellm --config config.yaml

# RUNNING on http://0.0.0.0:4000

2. Connect​

ws://localhost:4000/v1/realtime?model=scribe-realtime

Authenticate with Authorization: Bearer <proxy key>. LiteLLM sends session.created right away with default settings (24 kHz PCM, server VAD); nothing is sent to ElevenLabs yet.

3. Configure the session​

Send one session.update (or transcription_session.update). LiteLLM opens the ElevenLabs session with these settings and sends session.updated, with the same session id, once ElevenLabs accepts it. Later updates are ignored. Audio sent before session.updated is buffered and replayed, so you can start streaming right away. If no session.update arrives and the buffer fills up (200 messages or 10 MB), later audio is dropped until the update arrives.

session.update
{
"type": "session.update",
"session": {
"type": "transcription",
"audio": {
"input": {
"format": {"type": "audio/pcm", "rate": 24000},
"turn_detection": {"type": "server_vad"},
"transcription": {"model": "scribe_v2_realtime", "language": "en"}
}
}
}
}
FieldRules
formattype must be audio/pcm and channels must be 1. rate must be 8000, 16000, 22050, 24000, 44100 or 48000; omitted means 24 kHz.
transcription.modelOptional. Only scribe_v2_realtime or elevenlabs/scribe_v2_realtime is accepted. Any other value, the proxy alias included, is rejected, or ignored when drop_params is set.
transcription.languageOptional ISO 639-1 or ISO 639-3 code. Region suffixes are dropped, so en-US becomes en.
turn_detectionOmitted or {"type": "server_vad"} selects ElevenLabs VAD commits; null selects manual commits. Any other type is rejected, or falls back to server VAD when drop_params is set.
Beta layoutinput_audio_format: "pcm16" plus input_audio_transcription is accepted at 24 kHz.

An invalid session.update (bad format, rate, model, language or turn detection type) gets an error event of type invalid_request_error that names the problem, and then the connection closes. Invalid audio after setup, such as invalid base64 or an odd number of PCM bytes, closes the same way.

4. Stream audio​

input_audio_buffer.append carries base64 mono PCM16 at the configured rate. LiteLLM forwards it as ElevenLabs input_audio_chunk messages, splitting large appends into chunks of at most 32000 bytes. input_audio_buffer.commit and input_audio_buffer.end commit the audio sent since the last commit, in either mode. A commit with no new audio is not forwarded, because ElevenLabs closes the session on an empty commit. ElevenLabs also closes the session on a commit with less than 0.3 s of new audio, so LiteLLM pads a shorter commit or clear with silence up to 0.3 s, and that silence is billed like other audio. A commit whose audio has no speech still gets a completed event, with an empty transcript. input_audio_buffer.clear commits the pending audio and drops that segment's transcript, so the next completed event covers only audio sent after the clear. Each clear drops only the transcript of its own segment, even when the transcript of an earlier commit has not arrived yet. The cleared audio is still billed. Once ElevenLabs answers the cleared segment, LiteLLM sends input_audio_buffer.speech_stopped if that segment already got speech_started, and then input_audio_buffer.cleared. A clear with no new audio since the last commit sends nothing. Every other client event, including response.create, is dropped.

With server VAD, ElevenLabs commits a segment after a pause of vad_silence_threshold_secs, so keep streaming audio (silence included) in real time, or send input_audio_buffer.commit to commit at once.

5. Read transcripts​

EventFieldsWhen
session.createdsession.type: transcription, default 24 kHz server VAD settingsOn connect
session.updatedEffective settings, same session.idAfter ElevenLabs accepts your session.update
input_audio_buffer.speech_starteditem_idFirst partial transcript of a segment
conversation.item.input_audio_transcription.deltaitem_id, content_index: 0, deltaNew confirmed words, and the rest of the segment on commit
input_audio_buffer.speech_stoppeditem_idThe segment is committed or cleared
conversation.item.input_audio_transcription.completeditem_id, content_index: 0, transcript, usage: {"type": "duration", "seconds": 7.57}Final transcript for the segment
input_audio_buffer.clearedElevenLabs answered the segment an input_audio_buffer.clear committed
errorerror.type, error.message: ElevenLabs realtime transcription failed: <type>ElevenLabs reported an error such as auth_error or quota_exceeded

ElevenLabs keeps revising the last word of each partial transcript, so a delta carries a word only after a later partial confirms it. When the segment is committed, LiteLLM sends the rest of the transcript as a last delta before speech_stopped, so the deltas of a segment add up to its completed transcript. For text without spaces, such as Chinese and Japanese, and for text whose last word has no spaces, such as Japanese with an English word in it, a delta carries the characters two partials agree on, minus the last character and any trailing punctuation, which ElevenLabs often revises. If ElevenLabs revises text a delta already carried, later deltas continue from the same word or character position, so the joined deltas can differ from completed in the revised words. A revision that changes the number of words, such as twenty five becoming $25, can make the next delta skip or repeat a word. The completed transcript is the authoritative text for the segment.

error.type is invalid_request_error for errors the client causes (auth_error, quota_exceeded, rate_limited, invalid_request, input_error, commit_throttled, unaccepted_terms, queue_overflow, session_time_limit_exceeded, chunk_size_exceeded and insufficient_audio_activity), and server_error for every other ElevenLabs error. ElevenLabs closes the session after every error. An invalid ElevenLabs key arrives as an error event with auth_error, followed by a normal close, and the session is logged as a failure rather than a success. If LiteLLM cannot open the ElevenLabs socket at all (a network failure, a timeout or an HTTP rejection of the handshake), the proxy closes the client connection with code 1011 and a reason such as ElevenLabs realtime connection failed (HTTP 403).

Health checks​

Health checks for scribe_v2_realtime open the ElevenLabs realtime socket with the deployment's settings and wait for session_started, without sending audio, so they cost nothing. A rejected key or a socket that closes first marks the deployment unhealthy with the ElevenLabs error, for example ElevenLabs realtime transcription failed: auth_error.

Pricing and usage​

Scribe v2 Realtime is billed per second of input audio (input_cost_per_second in the model cost map). usage.seconds is the audio LiteLLM sent to ElevenLabs since the previous completed event, silence included. Audio after the last completed event is billed when the session closes. When the deployment sets keyterms, each second is also billed at the keyterm prompting add-on rate, elevenlabs/scribe_v2_realtime/keyterms in the model cost map. Deployment custom pricing replaces only the base rate, and the add-on rate always comes from the cost map.

Example Python client​

Server VAD: configure, stream a mono PCM16 WAV file in 100 ms chunks in real time, add silence so ElevenLabs commits, then print transcript events.

Scribe v2 Realtime client
import asyncio
import base64
import json
import os
import wave

import websockets

URL = "ws://localhost:4000/v1/realtime?model=scribe-realtime"
HEADERS = {"Authorization": f'Bearer {os.environ["LITELLM_API_KEY"]}'}


async def main():
with wave.open("speech.wav") as w: # mono PCM16
rate, audio = w.getframerate(), w.readframes(w.getnframes())
step = rate * 2 // 10
async with websockets.connect(URL, additional_headers=HEADERS) as ws:
await ws.send(json.dumps({
"type": "session.update",
"session": {
"type": "transcription",
"audio": {"input": {
"format": {"type": "audio/pcm", "rate": rate},
"turn_detection": {"type": "server_vad"},
"transcription": {"model": "scribe_v2_realtime"},
}},
},
}))

async def send_audio():
for i in range(0, len(audio), step):
chunk = base64.b64encode(audio[i : i + step]).decode()
await ws.send(json.dumps({"type": "input_audio_buffer.append", "audio": chunk}))
await asyncio.sleep(0.1)
silence = base64.b64encode(b"\x00\x00" * rate * 3).decode()
await ws.send(json.dumps({"type": "input_audio_buffer.append", "audio": silence}))

sender = asyncio.create_task(send_audio())
async for raw in ws:
event = json.loads(raw)
if event["type"].endswith(".delta"):
print(event["delta"], end="", flush=True)
elif event["type"].endswith(".completed"):
print("\n" + event["transcript"], event.get("usage"))
break
elif event["type"] == "error":
print(event["error"])
break
sender.cancel()


asyncio.run(main())

Text-to-Speech (TTS)​

ElevenLabs provides high-quality text-to-speech capabilities through their TTS API, supporting multiple voices, languages, and audio formats.

Overview​

PropertyDetails
DescriptionConvert text to natural-sounding speech using ElevenLabs' advanced TTS models
Provider Route on LiteLLMelevenlabs/
Supported Operations/audio/speech
Link to Provider DocElevenLabs TTS API ↗

Supported Models​

ModelRouteDescription
Eleven v3elevenlabs/eleven_v3Most expressive model. 70+ languages, audio tags support for sound effects and pauses.
Eleven Multilingual v2elevenlabs/eleven_multilingual_v2Default TTS model. 29 languages, stable and production-ready.

Quick Start​

LiteLLM Python SDK​

ElevenLabs Text-to-Speech with SDK
import litellm
import os

os.environ["ELEVENLABS_API_KEY"] = "your-elevenlabs-api-key"

# Basic usage with voice mapping
audio = litellm.speech(
model="elevenlabs/eleven_multilingual_v2",
input="Testing ElevenLabs speech from LiteLLM.",
voice="alloy", # Maps to ElevenLabs voice ID automatically
)

# Save audio to file
with open("test_output.mp3", "wb") as f:
f.write(audio.read())

Using Eleven v3 with Audio Tags​

Eleven v3 supports audio tags for adding sound effects and pauses directly in the text:

Eleven v3 with audio tags
import litellm
import os

os.environ["ELEVENLABS_API_KEY"] = "your-elevenlabs-api-key"

audio = litellm.speech(
model="elevenlabs/eleven_v3",
input='Welcome back. <sfx>applause</sfx> Today we have a special guest. <pause duration="1.5s"/> Let me introduce them.',
voice="alloy",
)

with open("eleven_v3_output.mp3", "wb") as f:
f.write(audio.read())

Advanced Usage: Overriding Parameters and ElevenLabs-Specific Features​

Advanced TTS with custom parameters
import litellm
import os

os.environ["ELEVENLABS_API_KEY"] = "your-elevenlabs-api-key"

# Example showing parameter overriding and ElevenLabs-specific parameters
audio = litellm.speech(
model="elevenlabs/eleven_multilingual_v2",
input="Testing ElevenLabs speech from LiteLLM.",
voice="alloy", # Can use mapped voice name or raw ElevenLabs voice_id
response_format="pcm", # Maps to ElevenLabs output_format
speed=1.1, # Maps to voice_settings.speed
# ElevenLabs-specific parameters - passed directly to API
pronunciation_dictionary_locators=[
{"pronunciation_dictionary_id": "dict_123", "version_id": "v1"}
],
model_id="eleven_multilingual_v2", # Override model if needed
)

# Save audio to file
with open("test_output.mp3", "wb") as f:
f.write(audio.read())

Voice Mapping​

LiteLLM automatically maps common OpenAI voice names to ElevenLabs voice IDs:

OpenAI VoiceElevenLabs Voice IDDescription
alloy21m00Tcm4TlvDq8ikWAMRachel - Neutral and balanced
amber5Q0t7uMcjvnagumLfvZiPaul - Warm and friendly
ashAZnzlk1XvdvUeBnXmlldDomi - Energetic
augustD38z5RcWu1voky8WS1jaFin - Professional
blue2EiwWnXFnvU5JabPnv8nClyde - Deep and authoritative
coral9BWtsMINqrJLrRacOk9xAria - Expressive
lilyEXAVITQu4vr4xnSDxMaLSarah - Friendly
onyx29vD33N1CtxCmqQRPOHJDrew - Strong
sageCwhRBWXzGAHq8TQ4Fs17Roger - Calm
verseCYw3kZ02Hs0563khs1FjDave - Conversational

Using Custom Voice IDs: You can also pass any ElevenLabs voice ID directly. If the voice name is not in the mapping, LiteLLM will use it as-is:

Using custom ElevenLabs voice ID
audio = litellm.speech(
model="elevenlabs/eleven_multilingual_v2",
input="Testing with a custom voice.",
voice="21m00Tcm4TlvDq8ikWAM", # Direct ElevenLabs voice ID
)

Response Format Mapping​

LiteLLM maps OpenAI response formats to ElevenLabs output formats:

OpenAI FormatElevenLabs Format
mp3mp3_44100_128
pcmpcm_44100
opusopus_48000_128

You can also pass ElevenLabs-specific output formats directly using the output_format parameter.

Supported Parameters​

All Supported Parameters
audio = litellm.speech(
model="elevenlabs/eleven_multilingual_v2", # Required
input="Text to convert to speech", # Required
voice="alloy", # Required: Voice selection (mapped or raw ID)
response_format="mp3", # Optional: Audio format (mp3, pcm, opus)
speed=1.0, # Optional: Speech speed (maps to voice_settings.speed)
# ElevenLabs-specific parameters (passed directly):
model_id="eleven_multilingual_v2", # Optional: Override model
voice_settings={ # Optional: Voice customization
"stability": 0.5,
"similarity_boost": 0.75,
"speed": 1.0
},
pronunciation_dictionary_locators=[ # Optional: Custom pronunciation
{"pronunciation_dictionary_id": "dict_123", "version_id": "v1"}
],
)

LiteLLM Proxy​

1. Configure your proxy​

ElevenLabs TTS configuration in config.yaml
model_list:
- model_name: elevenlabs-tts
litellm_params:
model: elevenlabs/eleven_multilingual_v2
api_key: os.environ/ELEVENLABS_API_KEY

general_settings:
master_key: your-master-key

2. Make TTS requests​

Simple Usage (OpenAI Parameters)​

You can use standard OpenAI-compatible parameters without any provider-specific configuration:

Simple TTS request with curl
curl http://localhost:4000/v1/audio/speech \
-H "Authorization: Bearer $LITELLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "elevenlabs-tts",
"input": "Testing ElevenLabs speech via the LiteLLM proxy.",
"voice": "alloy",
"response_format": "mp3"
}' \
--output speech.mp3
Simple TTS with OpenAI SDK
from openai import OpenAI

client = OpenAI(
base_url="http://localhost:4000",
api_key="your-litellm-api-key"
)

response = client.audio.speech.create(
model="elevenlabs-tts",
input="Testing ElevenLabs speech via the LiteLLM proxy.",
voice="alloy",
response_format="mp3"
)

# Save audio
with open("speech.mp3", "wb") as f:
f.write(response.content)
Advanced Usage (ElevenLabs-Specific Parameters)​

Note: When using the proxy, provider-specific parameters (like pronunciation_dictionary_locators, voice_settings, etc.) must be passed in the extra_body field.

Advanced TTS request with curl
curl http://localhost:4000/v1/audio/speech \
-H "Authorization: Bearer $LITELLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "elevenlabs-tts",
"input": "Testing ElevenLabs speech via the LiteLLM proxy.",
"voice": "alloy",
"response_format": "pcm",
"extra_body": {
"pronunciation_dictionary_locators": [
{"pronunciation_dictionary_id": "dict_123", "version_id": "v1"}
],
"voice_settings": {
"speed": 1.1,
"stability": 0.5,
"similarity_boost": 0.75
}
}
}' \
--output speech.mp3
Advanced TTS with OpenAI SDK
from openai import OpenAI

client = OpenAI(
base_url="http://localhost:4000",
api_key="your-litellm-api-key"
)

response = client.audio.speech.create(
model="elevenlabs-tts",
input="Testing ElevenLabs speech via the LiteLLM proxy.",
voice="alloy",
response_format="pcm",
extra_body={
"pronunciation_dictionary_locators": [
{"pronunciation_dictionary_id": "dict_123", "version_id": "v1"}
],
"voice_settings": {
"speed": 1.1,
"stability": 0.5,
"similarity_boost": 0.75
}
}
)

# Save audio
with open("speech.mp3", "wb") as f:
f.write(response.content)
⌂ 换网址