Communication Methods
- Client Data Channels → Used by our SDKs and WebSocket connections for bi-directional, real-time message exchange during calls. This is the primary method for client apps to interact with calls.
- Data Connection → Add a data connection to your call to receive messages via a separate WebSocket connection. This is particularly useful for:
- Telephony integrations where the client doesn’t support WebRTC
- Server-side applications that need to monitor call events or route data to external systems
- REST API → Inject messages into active calls via HTTP POST requests. See Sending Messages to Live Calls via REST API below for detailed implementation guidelines.
Messages at a Glance
Details on each message type appear below in Data Message Details.Client-to-Server Messages
Server-to-Client Messages
Messages excluded by default are sent only to connections that ask for them:
- Clients list the message types they want in
additionalMessageswhen joining the call (experimentalMessagesin older SDKs). ThedataMessageson the call’s medium is applied afterward, so you can limit what clients you don’t fully trust receive:truealways sends a message,falsenever does (even if the client asks for it), and leaving it unset lets the client choose, falling back to the default. - Data connections set
dataMessageson the data connection.
Data Message Details
All messages are JSON objects with camelCase keys containing:- A required
typefield identifying the message type - Additional fields specific to each message type
Ping
A message sent by the client to measure round-trip data message latency. Message StructurePong
A message sent by the server in response to a PingMessage. The timestamp is copied from the PingMessage. Message StructureState
A message sent by the server to indicate its current state. Message StructureTranscript
A message containing text transcripts of user and agent utterances. Message StructureThe additional transcript text added since the last transcript message. Either this or text will be set, but not both.
UserStartedSpeaking
Sent by the server when voice activity detection hears the user start speaking. Excluded by default. Message StructureUserStoppedSpeaking
Sent by the server when voice activity detection decides the user has finished speaking. Excluded by default. Message StructureUserTextMessage
A user message sent via text. The message appears to the agent as if it came from the user.On a call whose
mediumRestriction doesn’t allow text, user text messages from the client are ignored, except those sent to a side thread. Messages sent through a data connection or the REST API are still delivered.Determines whether this message can interrupt the agent and whether it should trigger a generation. Options:
- immediate → Interrupts the agent if speaking and starts a new generation immediately.
- soon → Doesn’t interrupt but starts a generation at the next opportunity.
- later → Message is considered during the next natural generation without forcing a new generation.
Optional thread ID to send this message to. Defaults to “UI” (the main conversation).
SetOutputMedium
Message sent by the client to set the server’s output medium. Message StructureOn a call whose
mediumRestriction doesn’t allow the requested medium, this message is ignored.ClientToolInvocation and DataConnectionToolInvocation
Sent by the server to ask the client or data connection to invoke a tool with the given parameters. The client or data connection is expected to send back a ClientToolResultMessage or DataConnectionToolResultMessage with a matching invocationId. Message StructureClientToolResult and DataConnectionToolResult
Contains the result of a tool invocation. Message StructureTypically the tool execution result as viewed by the agent, which is often a JSON string. May be omitted for errors.
For responseTypes other than
tool-response, this may be a JSON string for an object that further specifies how the response should be handled. See special response types.Type of response being provided. See special response types.
How the agent should react. Options: “speaks” (default), “listens”, or “speaks-once”. See Agent Responses to Tools for more.
Error classification if the tool failed. Should be omitted when result is set.Options:
- undefined → Tool with the given name does not exist
- implementation-error → Tool exists but execution failed
Human-readable error description if the tool failed. This is not seen by the model but may be used for debugging.
Optional state updates to apply to the call. See Tool State for more.
InvokingTool
Sent by the server when a tool invocation starts. Excluded by default. Message StructureThe
callToolId of the tool, as returned by List Call Tools.Whether this is a speculative invocation of a precomputable tool, whose result may go unused.
The ID of the thread that invoked the tool.
ToolUsed
Sent by the server when a tool invocation finishes, with its result. Excluded by default. Message StructureThe
callToolId of the tool, as returned by List Call Tools.Matches the invocationId of the InvokingTool message.
The tool call’s position in the thread’s messages. For threads other than
UI, it counts the thread’s own messages, which aren’t saved with the call’s.The ID of the thread that invoked the tool.
The call’s new state, if the tool changed it.
Debug
A message sent by the server to communicate debug information. Disabled by default. Message StructureDebug messages are disabled by default and must be explicitly enabled for debugging purposes.
CallEvent
Sent by the server each time a call event is recorded. Excluded by default. Message StructureThe event, in the same form as List Call Events returns it.
CallStarted
Basic call metadata shared by the server when a call begins. Message StructureThe mediums the call allows for user input and agent output: “voice”, “text”, or both. See Text-Only and Voice-Only Calls.
PlaybackClearBuffer
Message sent by the server to clear buffered output audio. Integrators should drop as much unplayed output audio as possible for interruptions to function properly. Message StructureThis message is only used with WebSocket connections. Handling this message allows for larger client buffers while maintaining responsive interrupts. Larger client buffers make choppy audio less likely in the presence of network disruption or resource contention.
ForcedAgentMessage
Forces the agent to say a specific message or invoke tools. Message StructureArray of known tool results. If specified, any toolCalls with matching invocationIds will use these results instead of executing the tool. See ClientToolResult for the structure of each result object.
If true, prevents interruption while the agent speaks this message. (Note that tools are always uninterruptible.)
Controls when the message is processed. Must be either “immediate” (may interrupt the user or agent) or “soon” (process at next opportunity).
Optional thread ID to send this message to. Defaults to “UI” (the main conversation).
HangUp
Instructs the agent to end the call with an optional farewell message. Message StructureThread Messages
The following messages are used to manage Threads — parallel conversations that run alongside the main call. For conceptual background and usage examples, see the Threads guide.SpawnThread
Spawns a new parallel thread that forks from the parent’s conversation history. See Threads for a full explanation. Message StructureUnique identifier for the new thread. If omitted, an id will be auto-generated. Leading and trailing whitespace is trimmed, and the result may be at most 64 characters.
UI and _PARENT are reserved.The thread to fork from. Defaults to “UI” (the main conversation). If the referenced thread has failed or doesn’t exist, this spawn attempt will be rejected.
Controls behavior when
newThreadId matches an existing thread. Options:reject(default) → The spawn request is rejected and a ThreadRejected message is sent.replace→ The existing thread is terminated and a new thread is spawned with the same ID. Useful for re-syncing a thread with the current conversation state. The existing thread is terminated even if the new spawn is then rejected, and its ThreadTerminated is sent before the new thread’s ThreadSpawned.
Messages to append to the forked history before the thread starts generating. Each element must be either a UserTextMessage or ForcedAgentMessage. Every ForcedAgentMessage except the last must have known results for each tool call. The last may have unmatched calls, in which case the thread will begin by executing those.
Changes to the parent thread’s tools for the new thread. Same format as the
toolOverrides in an update-tools tool response:remove(string[]) → Names of the parent’s tools to remove. May not be set together withremoveAll.removeAll(boolean) → Removes all of the parent’s tools.add(object[]) → Tools to add, in the same format asselectedToolswhen creating a call. Removals are applied first.
invalid_input cause. May not be set together with toolFilter. See Changing a Thread’s Tools.Deprecated: use
toolOverrides instead. Restricts which tools the thread can use. Specify either allowedTools (allowlist) or disallowedTools (blocklist), or both. If both are provided, the allowlist is applied first and then the blocklist is applied to the remaining tools. If neither is specified (or this field is omitted), the thread will be allowed to use all tools. The thread’s model still sees the parent’s tool definitions, and calling a filtered tool gets the same error as calling a tool that doesn’t exist.Resource constraints for the thread. Available fields:
threadOutputTokenLimit(integer) → Max total output tokens for the thread. At most 20,000.threadFuzzyInputTokenLimit(integer) → Approximate total (uncached) input token limit. At most 100,000.generationLimit(integer) → Max LLM generation rounds.generationOutputTokenLimit(integer) → Max output tokens per generation. At most 4,000, and 2,048 if unset.generationFuzzyInputTokenLimit(integer) → Approximate (uncached) input token limit per generation.
thread.limit_clamped call event is recorded.Limits are a useful way to constrain model usage (and thus costs) for a thread, but leaving threads unconstrained
is also totally reasonable, especially when the context provided to them keeps them focused on a specific task.String values of your choosing, echoed back as
metadata on the thread and side generation messages about this thread, such as ThreadState. Useful for telling threads apart, for example in a trigger’s conditions.The model the thread runs on, which must be one of the call’s
additionalModels. If unset, the thread uses its parent’s model. See Choosing a Thread’s Model.Replaces the parent’s system prompt. The thread then starts without its parent’s messages, so
additionalMessages are its first. Text models only.ThreadSpawned
Sent by the server to confirm a thread was successfully created. Message StructureThe
metadata the thread was spawned with.ThreadRejected
Sent by the server when a thread spawn request cannot be fulfilled. Message StructureThreadTerminated
Sent by the server when a thread stops running. Message StructureWhy the thread terminated:
limit→ The thread would have exceeded one of its limits.inference→ The thread’s generation failed.canceled→ The thread was canceled, for example because the call’s stage changed or the thread was replaced by one with the same ID.invalid_input→ Input the thread was spawned with, such as an added tool intoolOverrides, turned out to be invalid once the thread resolved it.internal→ Something unexpected went wrong.
The
metadata the thread was spawned with.ThreadState
Sent by the server when a spawned thread starts and each time its state changes. Excluded by default, but triggers can listen for it either way. Message StructureThe thread’s state:
initializing→ The thread is setting up.generating→ The thread is running LLM inference.calling_tool→ The thread is executing tool calls.idle→ The thread has no work to do.
How many times the thread has finished its work and gone idle, including this time. A thread that starts idle hasn’t finished any work yet.
The
metadata the thread was spawned with.SideGenerationDelta
Streaming text delta from a (non-UI) thread’s LLM generation, similar to a transcript delta. Excluded by default. Message StructureThe
metadata the thread was spawned with.SideGenerationCompleted
Sent when a (non-UI) thread’s generation round finishes successfully. Message StructureAny tool calls the LLM requested during this generation. The thread will execute these automatically.
The
metadata the thread was spawned with.Sending Messages to Live Calls via REST API
The Send Data Message to Call endpoint allows you to inject messages into active calls (calls that are joined and not yet ended).Supported Message Types
Responses
Successful messages sent via the REST API will receive a204 No Content response with an empty body.
Potential error responses include:
401 Unauthorized: Missing or invalid API key403 Forbidden: Insufficient authorization422 Unprocessable Entity: Call is not active (either not joined yet or already ended)