Handle errors and disconnects
Catch connection failures, react to dropped sessions with your own reconnect logic, and read the acknowledgments Convai returns for each message.
Handle the failures a Convai Web SDK session can hit: a connection that never opens, a session that drops, and a message that Convai rejects. Use this page when you move from a prototype to an application that has to recover on its own.
Where failures surface
connect() cannot open a session
The connect() promise rejects, and the error event fires with the same error.
The character never signals that it is ready
The error event fires (LiveKit transport only).
The session ends, intentionally or not
The disconnect event fires with a reason code.
Convai accepts or rejects a message you sent
The serverResponse event fires.
The character chose not to answer
The llmNoResponse event fires.
The session is about to time out for inactivity
The idleWarning event fires.
Catch connection failures
Wrap connect() in try/catch. The SDK emits error with the same value it rethrows, so handle it in one place to avoid reporting it twice.
try {
await client.connect();
} catch (err) {
showError(err instanceof Error ? err.message : String(err));
}connect() throws these errors before any request is sent:
No configuration provided. Pass config to connect() or store it in the client
No configuration was passed to the constructor or to connect().
Either apiKey or authToken is required, and characterId is required
A credential or the character ID is missing.
When Convai answers /connect with an error status, the error message is the message, error, or detail field of the response body. A validation error that lists several problems is joined into one message as field: problem; field: problem. A response without a readable body produces HTTP <status> followed by the body text.
The error event payload is typed unknown, because it carries whatever failed. Narrow it before reading properties:
On the LiveKit transport, the SDK waits for the character to signal readiness after connecting. If no signal arrives in 45 seconds, error fires with bot-ready not received within 45000ms. The session stays connected; disconnect and connect again to recover.
React to disconnects
The disconnect event receives a DisconnectReason code. When the transport gives no reason, the SDK reports 0. A disconnect() call on the WebSocket transport reports 1. The last reason is also on client.state.disconnectReason, which is null while connected.
getDisconnectReasonMessage() turns a code into text. Both it and DisconnectReasonEnum are exported from @convai/web-sdk/core, @convai/web-sdk/react, and @convai/web-sdk/vanilla.
Code
DisconnectReasonEnum key
getDisconnectReasonMessage() text
0
UNKNOWN_REASON
Network unavailable or unknown cause
1
CLIENT_INITIATED
User disconnected
2
DUPLICATE_IDENTITY
Another client with same identity joined
3
SERVER_SHUTDOWN
Server is shutting down
4
PARTICIPANT_REMOVED
Removed by RemoveParticipant API
5
ROOM_DELETED
Room ended via DeleteRoom API
6
STATE_MISMATCH
State mismatch
7
JOIN_FAILURE
Failed to join
8
MIGRATION
Participant moved to different room
9
SIGNAL_CLOSE
Signal connection closed
Any other code returns Disconnected, and null returns Connected.
Reconnect with backoff
The SDK never reconnects on its own: it configures its LiveKit room with a policy that refuses every retry. Reconnect from your disconnect handler when the reason is not intentional.
reconnect() connects again with the last configuration, including the character session ID Convai returned, so the conversation resumes. It throws No stored config available for reconnection if connect() never ran with a configuration.
Check that messages were accepted
Most send methods return void and do nothing when the transport is not ready, without throwing. This covers sendUserTextMessage(), sendTriggerMessage(), sendInterruptMessage(), updateContext(), updateDynamicInfo(), updateTemplateKeys(), updateSceneMetadata(), toggleTts(), toggleStt(), and resetIdleTimer(). Send only after botReady has fired:
sendActionResult() is the exception: it throws when the session is not ready or the result is invalid. See Handle character actions.
Convai acknowledges messages with the serverResponse event. event_type is the message type you sent, status is success, error, processing, or pending, message is a description or null, and extras holds event-specific data or null.
Handle silent turns and idle sessions
llmNoResponse fires when the character deliberately does not answer a turn. Clear any thinking indicator when it fires.
idleWarning fires before Convai closes an inactive session. Its payload is { remainingSeconds }, a number or null. Call resetIdleTimer() on end-user activity to keep the session open.
Guard media controls
Microphone, camera, and screen-share methods are asynchronous and reject when the browser denies a permission or a device is unavailable. Catch the rejection and show a message:
Next steps
Web SDK event referenceConvaiClient referenceConnect with an auth tokenLast updated
Was this helpful?