The ElevenLabs API: Integrate Voice Into Your Apps
- Authenticate to the ElevenLabs API and make a basic TTS request using an official SDK
- Explain when to use streaming TTS versus the standard TTS endpoint
- Identify the ElevenLabs MCP server and describe what it enables
Why the API
The ElevenLabs browser interface is ideal for manual production work. The API is for everything else: when you need to generate audio at scale, embed voice generation into a product, automate a workflow, or trigger speech synthesis from your own application's events. The API exposes every product area — TTS, voice cloning, dubbing, sound effects, speech to text — through a unified REST interface.
Authentication
Every API request requires an API key. Generate your key in the ElevenLabs dashboard under Profile Settings. Pass it as the xi-api-key header on every request:
xi-api-key: your-api-key-here
Keep your API key out of client-side code (browser JavaScript) — it would be exposed to anyone who views your page source. For client-side applications, proxy requests through your own server that holds the key.
Official SDKs
ElevenLabs publishes official SDKs for Python and JavaScript/TypeScript. The JavaScript SDK (@elevenlabs/elevenlabs-js) includes full TypeScript types. Both SDKs mirror the REST API surface and handle authentication, streaming, and error handling for you.
Install the Python SDK:
pip install elevenlabs
Install the JavaScript SDK:
npm install @elevenlabs/elevenlabs-js
A minimal Python TTS generation looks like this:
from elevenlabs.client import ElevenLabs
client = ElevenLabs(api_key="your-key")
audio = client.text_to_speech.convert(
voice_id="voice-id-here",
text="Hello, this is a test.",
model_id="eleven_v4"
)
with open("output.mp3", "wb") as f:
f.write(audio)
Streaming TTS
For real-time applications, use the streaming TTS endpoint. Instead of waiting for the entire audio file to generate before returning it, the streaming endpoint sends audio chunks as they are produced. The first audio chunk typically arrives within 100–300 ms depending on the model, which is fast enough to feel immediate to a listener.
The Python SDK's text_to_speech.stream() method returns a generator that yields audio chunks. Pass them to your audio playback system as they arrive rather than buffering the full file first.
Key API Endpoints
The MCP Server
ElevenLabs provides an official MCP (Model Context Protocol) server. This lets you use ElevenLabs voice generation directly from Claude, Cursor, or any other MCP-compatible AI tool. Connect the MCP server to your AI coding assistant and you can generate speech, list voices, and trigger audio generation through natural language without writing API calls manually.
The MCP server is the fastest way to integrate ElevenLabs into an AI-assisted development workflow. Instead of looking up endpoint documentation, you describe what you want and the AI calls the API on your behalf.
Credit Consumption and Rate Limits
API calls consume credits from your plan just as browser-based generation does. Track your credit usage in the dashboard to avoid unexpected overages. Rate limits vary by plan — higher tiers get more concurrent requests and higher requests-per-minute caps. For high-volume production use cases, review the current rate limit documentation and consider a higher plan tier before hitting production traffic.
Try This
Install the ElevenLabs Python or JavaScript SDK and write a script that generates a 50-word piece of audio using a voice from your library and saves it as an MP3. Then modify the script to use the streaming endpoint and print the size of each chunk as it arrives. Notice the difference in how quickly you get usable audio: with the standard endpoint you wait for the full file; with streaming the first chunk arrives in well under a second.
- Authenticate with the xi-api-key header; never expose the key in client-side code — proxy requests through your server
- Streaming TTS returns audio chunks as they are generated — first audio arrives in 100–300 ms, fast enough for real-time applications
- The official MCP server lets Claude and other MCP clients call ElevenLabs voice generation through natural language — the fastest way to integrate ElevenLabs into an AI workflow