Skip to main content
The WebSocket API provides low-level access to Deepslate Realtime for server-side integrations. Use this for telephony backends, SIP gateways, or custom voice pipelines.
This interface is for server-side use only. End users should connect through WebRTC or your application’s frontend. Never expose your API key to clients.

Prerequisites

Connect

Connect to the WebSocket endpoint with your API key in the headers:

Initialize Session

The first message must be an InitializeSessionRequest to configure audio format, VAD, and model behavior:
Set supportsPlaybackReporting: true if your client can report how many audio bytes have been played. This enables accurate context truncation when the user interrupts the model mid-response. See Playback Position Reporting.
See the API Reference for all configuration options including TTS providers and tool definitions.

Send Audio

Stream audio as UserInput messages. Audio must match your inputAudioLine configuration:
The mode field controls how the input interacts with ongoing inference: You can also send text input instead of audio by using textData in place of audioData.
Audio format must exactly match your session configuration. For 16-bit signed PCM at 16kHz mono, each sample is 2 bytes, little-endian.

Handle Responses

The server sends ClientBoundMessage with one of several payload types.
Text-only vs. TTS mode
  • ModelTextFragment — sent only when no TTS provider is configured. Contains streamed text tokens as the model generates them.
  • ModelAudioChunk — sent only when a TTS provider is configured. Contains synthesized audio. The transcript field is optional and may be omitted entirely: Deepslate’s hosted TTS does not include it; third-party providers (e.g., ElevenLabs) may include it for alignment data.

Handle Interruptions

When the user starts speaking, the server sends PlaybackClearBuffer proactively to ensure any ongoing playback is stopped. This is sent regardless of whether there is currently TTS playback. You should immediately discard any queued audio that hasn’t played yet:

Trigger Inference

Use TriggerInference to make the model respond immediately without waiting for user speech. The primary use case is generating a greeting when the session opens.
TriggerInference is designed for generating a greeting before any user input. Using it directly after a model response may produce unpredictable results.

Reconfigure Session

Use ReconfigureSessionRequest to update the input audio format or system prompt mid-session without reconnecting. You can update either field or both.
Reconfiguration is not guaranteed to be seamless. There may be brief audio glitches or dropped audio around the transition.

Direct Speech

Use DirectSpeech to speak text via TTS immediately, bypassing the LLM. Any active inference is cancelled and the audio buffer is cleared before the text is spoken.
When includeInHistory is false, the message is marked as ephemeral in the chat history — it is audible to the user but invisible to the LLM’s context.

Conversation Query

Use ConversationQuery to run a one-shot LLM inference over the current conversation history without modifying it. The result is returned as a ConversationQueryResult. This is useful for side tasks like summarization or classification that should not affect the ongoing conversation.
At least one of prompt or instructions must be provided. If prompt is absent, the session’s current system prompt is used.

Playback Position Reporting

If you declared supportsPlaybackReporting: true during session initialization, send PlaybackPositionReport messages regularly as audio plays. This gives the server accurate data to truncate the LLM context to exactly what the user heard when they interrupt.
Without playback reporting, the server falls back to elapsed-time estimation for context truncation, which is less precise.

Export Chat History

Use ExportChatHistoryRequest to retrieve the full conversation history at any point. Set awaitPending: true to wait for any in-flight transcriptions to finish before the history is returned.
Each ChatMessage includes a role (SYSTEM, USER, or ASSISTANT), ordered content blocks, a deliveryStatus (DELIVERY_COMPLETE, DELIVERY_INTERRUPTED), and an ephemeral flag for messages spoken via DirectSpeech with includeInHistory: false. Audio content blocks (input_audio and tts_audio) include a transcription string that is populated asynchronously for user audio turns.

Tool Calling

Enable the model to call functions by defining tools and handling requests.

Define Tools

Send an UpdateToolDefinitionsRequest to register available tools. Each tool needs a name, description, and JSON Schema parameters:
Calling UpdateToolDefinitionsRequest replaces all existing tools. Send an empty array to clear all tools.

Handle Tool Requests

When the model wants to use a tool, you receive a ToolCallRequest. You must respond with a ToolCallResponse:
Every ToolCallRequest must receive a ToolCallResponse, even if the tool execution fails. The model waits for the response before continuing.

Complete Example

A Node.js client with microphone input and speaker output:

Next Steps

API Reference

Full message schemas, all configuration options, and tool calling

WebRTC

Browser-based integration for end-user applications

LiveKit Plugin

LiveKit Agents plugin for Deepslate integration

Pipecat Plugin

Pipecat framework plugin for Deepslate integration