How Events Work
The Anam SDK uses an event-driven architecture where your application listens for specific events and reacts accordingly. This allows you to:- Update your UI based on connection status
- Track conversation history in real-time
- Handle user interruptions
- Monitor stream quality and performance
Available Events
Connection Events
These events track the connection lifecycle between your client and Anam’s streaming infrastructure:CONNECTION_ESTABLISHED
Fired when the WebRTC connection is successfully established.
SESSION_READY
Fired after the session initializes and all backend components are ready. Use this to remove loading indicators.
CONNECTION_CLOSED
Fired when the connection is terminated. Receives a reason code and optional details.
Video Events
VIDEO_STREAM_STARTED
Fired when the video MediaStream becomes available.
VIDEO_PLAY_STARTED
Fired when the first video frames begin playing. Ideal for removing loading indicators.
Audio Events
AUDIO_STREAM_STARTED
Fired when the audio MediaStream from the persona becomes available.
INPUT_AUDIO_STREAM_STARTED
Fired when microphone input is successfully initialized.
INPUT_AUDIO_DEVICE_CHANGED
Fired when the input audio device changes.
Microphone Permission Events
These events track the state of microphone permission requests:MIC_PERMISSION_PENDING
Fired when the browser is requesting microphone permission from the user.
MIC_PERMISSION_GRANTED
Fired when the user grants microphone permission.
MIC_PERMISSION_DENIED
Fired when the user denies microphone permission.
Conversation Events
These events help you track and respond to conversation flow:MESSAGE_HISTORY_UPDATED
Provides the complete conversation history each time a participant finishes speaking.
MESSAGE_STREAM_EVENT_RECEIVED
Provides real-time transcription updates as speech occurs.
Reasoning Events
These events provide insight into the persona’s reasoning process (when using models that support it):REASONING_HISTORY_UPDATED
Provides the complete reasoning history.
REASONING_STREAM_EVENT_RECEIVED
Provides real-time reasoning updates as the persona thinks.
Talk Stream Events
TALK_STREAM_INTERRUPTED
Fired when a user interrupts a TalkMessageStream by speaking. Receives the correlation ID directly.
Server Events
SERVER_WARNING
Fired when the server sends a warning message.
Tool Call Events
All tool calls emit lifecycle events —started, completed, and failed — that you can use to trigger client-side actions or for monitoring.
For client tools, use registerToolCallHandler to define per-tool handlers, this will automatically emit completed or failed events when the handler completes.
Using registerToolCallHandler (Recommended)
Register handlers for specific tools by name. For client tools, the return value from onStart is sent back to the LLM as the tool result:
TOOL_CALL_STARTED
Fired when any tool call begins. Receives a ToolCallStartedPayload with the tool name, type, and arguments.
TOOL_CALL_COMPLETED
Fired when a tool call completes successfully. Includes the result and execution time.
TOOL_CALL_FAILED
Fired when a tool call fails. Includes the error message and execution time.
CLIENT_TOOL_EVENT_RECEIVED (Deprecated)
A legacy event for client tools. Replaced by TOOL_CALL_STARTED and registerToolCallHandler as of SDK v4.9.0.
Client tools enable voice-driven or chat-driven UI control. For a complete guide on creating and configuring client tools, see the Client Tools Guide.
