Client events
Understand and handle real-time communication events in your conversational applications.
Client events are system-level events that facilitate real-time communication between the client and server. These events manage various aspects of the conversation, including audio playback, transcription, interruptions, and more.
Overview
Client events are essential for maintaining the real-time nature of conversations. They handle everything from initialization to audio playback and user interactions.
These events are part of the WebSocket communication protocol and are automatically handled by our SDKs. Understanding them is crucial for advanced implementations and debugging.
Client event types
conversation_initiation_metadata
- Automatically sent when starting a conversation
- Initializes conversation settings and parameters
ping
-
Health check event requiring immediate response
-
Automatically handled by SDK
-
Used to maintain WebSocket connection
audio
- Contains base64 encoded audio for playback
- Includes numeric event ID for tracking and sequencing
- Handles voice output streaming
user_transcript
- Contains finalized speech-to-text results
- Represents complete user utterances
- Used for conversation history
agent_response
- Contains complete agent message
- Sent with first audio chunk
- Used for display and history
agent_response_correction
- Contains truncated response after interruption
- Updates displayed message
- Maintains conversation accuracy
client_tool_call
- Represents a function call the agent wants the client to execute
- Contains tool name, tool call ID, and parameters
- Requires client-side execution of the function and sending the result back to the server
If you are using the SDK, callbacks are provided to handle sending the result back to the server.
Event flow
Here’s a typical sequence of events during a conversation:
Best practices
-
Error handling
- Implement proper error handling for each event type
- Log important events for debugging
- Handle connection interruptions gracefully
-
Audio management
- Buffer audio chunks appropriately
- Implement proper cleanup on interruption
- Handle audio resource management
-
Connection management
- Respond to PING events promptly
- Implement reconnection logic
- Monitor connection health
Troubleshooting
Connection issues
- Ensure proper WebSocket connection
- Check PING/PONG responses
- Verify API credentials
Audio problems
- Check audio chunk handling
- Verify audio format compatibility
- Monitor memory usage
Event handling
- Log all events for debugging
- Implement error boundaries
- Check event handler registration
For detailed implementation examples, check our SDK documentation.