Learn more">
Skip to navigation
/n Build a voice agent with the ElevenLabs SDK.\n </Card>\n\n <Card title=\"JavaScript SDK reference\" icon=\"fa-brands fa-js\" href=https://elevenlabs.io/"/docs/eleven-api/resources/libraries/speech-engine/javascript-sdk-reference/">/n Classes, methods, and events for the JavaScript SDK.\n </Card>\n\n <Card title=\"Python SDK reference\" icon=\"fa-brands fa-python\" href=https://elevenlabs.io/"/docs/eleven-api/resources/libraries/speech-engine/python-sdk-reference/">/n Classes, methods, and events for the Python SDK.\n </Card>\n</CardGroup>\n\n## How it works\n\nSpeech Engine connects your server to ElevenLabs over WebSocket. Each connection represents one conversation.\n\n```mermaid\nsequenceDiagram\n participant Browser\n participant ElevenLabs\n\n box Your Server\n participant SDK as Speech Engine SDK\n participant LLM\n end\n\n Browser->>ElevenLabs: User speaks (audio)\n ElevenLabs->>SDK: Transcript (WebSocket)\n SDK->>LLM: Conversation history\n LLM->>SDK: Streamed response\n SDK->>ElevenLabs: Text chunks\n ElevenLabs->>Browser: Agent speaks (audio)\n```\n\n1. A user speaks in the browser. ElevenLabs captures the audio and transcribes it.\n2. The transcript is sent to your server along with the full conversation history.\n3. Your server passes the transcript to your LLM and streams the response back.\n4. ElevenLabs converts the text to speech and plays it in the browser.\n\n## When to use Speech Engine\n\nSpeech Engine is designed for developers who want to bring their own LLM and control the conversation logic on their own server. Use it when you need to:\n\n* Add voice to an existing text-based chat agent\n* Use a specific LLM, fine-tuned model, or custom inference pipeline\n* Keep full control over conversation routing, context management, and tool calling\n* Integrate voice into an existing server application (Express, FastAPI, etc.)\n\nIf you want a fully hosted solution where ElevenLabs provides the LLM, knowledge base, and tools, use [ElevenAgents](/docs/eleven-agents/overview) instead.\n\n## Key features\n\n* **Any LLM** - use OpenAI, Anthropic, Google Gemini, or any model that produces text. The SDK auto-extracts text from OpenAI, Anthropic, and Gemini stream formats.\n* **Interruption handling** - when the user speaks mid-response, the SDK cancels the in-flight LLM request automatically via an `AbortSignal` (TypeScript) or task cancellation (Python).\n* **Streaming** - responses are streamed to the browser as they are generated. Pass a string, an async iterable, or a native LLM stream object.\n* **Turn-taking** - the SDK manages conversation turns, so your server only needs to respond to transcripts.\n\n## Conversation duration\n\nSpeech Engine supports conversations of up to 40 minutes (2,400 seconds). By default, a\nconversation ends after 600 seconds (10 minutes). To allow longer conversations, raise\n`conversation.max_duration_seconds` in the API or **Max conversation duration** in the dashboard's\n**Advanced** tab. See\n[Configuring the maximum conversation duration](/docs/eleven-api/guides/cookbooks/speech-engine#configuring-the-maximum-conversation-duration).\nIf you need conversations longer than 40 minutes, [contact our team](https://elevenlabs.io/contact-sales).\n\n## IP allowlisting\n\nIf your server is behind a firewall or uses IP-based access controls, you can allowlist the static egress IPs from which ElevenLabs WebSocket connections originate. See [IP allowlisting](/docs/eleven-api/resources/ip-allowlisting) for the complete list of IP addresses.\n\n<Tip>\n Using IP allowlisting ensures your server only accepts WebSocket connections from ElevenLabs'\n systems.\n</Tip>\n\n## FAQ\n\n<AccordionGroup>\n <Accordion title=\"What LLMs are supported?\">\n Any LLM that produces text. The SDK has built-in stream extraction for OpenAI (Responses API and\n Chat Completions API), Anthropic Messages API, and Google Gemini API. For other providers, pass\n a plain string or an async iterable of string chunks.\n </Accordion>\n\n <Accordion title=\"What is the difference between Speech Engine and ElevenAgents?\">\n ElevenAgents is a fully hosted platform where ElevenLabs provides the LLM, knowledge base, and\n tools. Speech Engine is for developers who want to bring their own LLM and control the\n conversation logic on their own server.\n </Accordion>\n\n <Accordion title=\"What server frameworks are supported?\">\n In TypeScript, you can attach Speech Engine to any Node.js HTTP server (Express, Fastify, or\n plain `http.createServer()`), or run a standalone WebSocket server. In Python, the SDK provides\n a standalone server via `engine.serve()`, or you can integrate with FastAPI, Starlette, or any\n ASGI framework using `engine.create_session()`.\n </Accordion>\n</AccordionGroup>\n"],"perViewerCopy":[0,true],"askAiEnabled":[0,false],"skillsConfig":[0],"availability":[0],"pageActions":[0,{"options":[0,{"copyPage":[0,true],"viewAsMarkdown":[0,true],"askAi":[0,true],"openAi":[0,true],"claude":[0,true],"cursor":[0,true],"claudeCode":[0,true],"vscode":[0,false],"custom":[1,[[0,{"title":[0,"LLMs full"],"subtitle":[0,"See the entire documentation site as markdown for LLMs"],"url":[0,"https://elevenlabs.io/docs/llms-full.txt"],"icon":[0,"fa-solid fa-file-code"]}]]]}]}],"pageActionsStyle":[0,"default"],"pageActionFiles":[0],"showRssFeedButton":[0,false],"showPageActions":[0,true]}" ssr client="deferred" opts="{"name":"PageHeaderIsland","value":true}" await-children>

Speech Engine

Add voice to your own chat agent or LLM with ElevenLabs.

Overview

ElevenLabs Speech Engine adds voice capabilities to any chat agent. ElevenLabs handles speech-to-text and text-to-speech while your server provides the LLM logic. The SDK manages connection lifecycle, turn-taking, and interruption detection so you can focus on your agent’s behavior.

How it works

Speech Engine connects your server to ElevenLabs over WebSocket. Each connection represents one conversation.

  1. A user speaks in the browser. ElevenLabs captures the audio and transcribes it.
  2. The transcript is sent to your server along with the full conversation history.
  3. Your server passes the transcript to your LLM and streams the response back.
  4. ElevenLabs converts the text to speech and plays it in the browser.

When to use Speech Engine

Speech Engine is designed for developers who want to bring their own LLM and control the conversation logic on their own server. Use it when you need to:

  • Add voice to an existing text-based chat agent
  • Use a specific LLM, fine-tuned model, or custom inference pipeline
  • Keep full control over conversation routing, context management, and tool calling
  • Integrate voice into an existing server application (Express, FastAPI, etc.)

If you want a fully hosted solution where ElevenLabs provides the LLM, knowledge base, and tools, use ElevenAgents instead.

Key features

  • Any LLM - use OpenAI, Anthropic, Google Gemini, or any model that produces text. The SDK auto-extracts text from OpenAI, Anthropic, and Gemini stream formats.
  • Interruption handling - when the user speaks mid-response, the SDK cancels the in-flight LLM request automatically via an AbortSignal (TypeScript) or task cancellation (Python).
  • Streaming - responses are streamed to the browser as they are generated. Pass a string, an async iterable, or a native LLM stream object.
  • Turn-taking - the SDK manages conversation turns, so your server only needs to respond to transcripts.

Conversation duration

Speech Engine supports conversations of up to 40 minutes (2,400 seconds). By default, a conversation ends after 600 seconds (10 minutes). To allow longer conversations, raise conversation.max_duration_seconds in the API or Max conversation duration in the dashboard’s Advanced tab. See Configuring the maximum conversation duration. If you need conversations longer than 40 minutes, contact our team.

IP allowlisting

If your server is behind a firewall or uses IP-based access controls, you can allowlist the static egress IPs from which ElevenLabs WebSocket connections originate. See IP allowlisting for the complete list of IP addresses.

Using IP allowlisting ensures your server only accepts WebSocket connections from ElevenLabs’ systems.

FAQ

Any LLM that produces text. The SDK has built-in stream extraction for OpenAI (Responses API and Chat Completions API), Anthropic Messages API, and Google Gemini API. For other providers, pass a plain string or an async iterable of string chunks.

ElevenAgents is a fully hosted platform where ElevenLabs provides the LLM, knowledge base, and tools. Speech Engine is for developers who want to bring their own LLM and control the conversation logic on their own server.

In TypeScript, you can attach Speech Engine to any Node.js HTTP server (Express, Fastify, or plain http.createServer()), or run a standalone WebSocket server. In Python, the SDK provides a standalone server via engine.serve(), or you can integrate with FastAPI, Starlette, or any ASGI framework using engine.create_session().