Prerequisites
- A Deepslate API key
- Node.js 18+ with the
wsandprotobufjspackages - The proto definition file
Connect
Connect to the WebSocket endpoint with your API key in the headers:Initialize Session
The first message must be anInitializeSessionRequest to configure audio format, VAD, and model behavior:
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.
Send Audio
Stream audio asUserInput messages. Audio must match your inputAudioLine configuration:
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 sendsClientBoundMessage 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. Thetranscriptfield 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 sendsPlaybackClearBuffer 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
UseTriggerInference to make the model respond immediately without waiting for user speech. The primary use case is generating a greeting when the session opens.
Reconfigure Session
UseReconfigureSessionRequest 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
UseDirectSpeech 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.
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
UseConversationQuery 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.
prompt or instructions must be provided. If prompt is absent, the session’s current system prompt is used.
Playback Position Reporting
If you declaredsupportsPlaybackReporting: 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.
Export Chat History
UseExportChatHistoryRequest 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.
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 anUpdateToolDefinitionsRequest 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 aToolCallRequest. You must respond with a ToolCallResponse:
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