Skip to main content
Your backend authenticates to Karta and creates a signed URL. Your browser connects using that URL.

Create the URL

Use the ID of a live voice agent in your Karta account:
agent_override is best-effort. If its schema is malformed or unsupported, the session is still created with the stored agent configuration and the response includes a warning explaining why the override was ignored. A successful request returns 201 Created:
For example, an invalid override still returns 201 Created:
See Create WebSocket session for request fields, response fields, and HTTP errors.

Expiry and reconnection

The signed URL:
  • Expires five minutes after it is created.
  • Can open only one WebSocket connection.
  • Cannot be reused when reconnecting.
  • After the connection opens successfully, the conversation can continue beyond five minutes.
Treat the signed URL as a temporary credential. Do not share it or write the complete URL to logs.

Connect to the session

Open the signed_url returned by the session request. Use the URL exactly as returned.

Audio format

Use the audio format below to send user audio and decode agent audio.

Connection flow

  1. Open the signed WebSocket URL.
  2. Send one conversation initiation request.
  3. Wait for the conversation metadata response.
  4. Send user audio requests.
  5. Play agent audio responses in the order received.
  6. Close the WebSocket to end the conversation, or handle a server-initiated conversation end.

Client-to-server messages

Conversation initiation

Send this once after the WebSocket opens:
agent_override.language_config.primary_language can select any language already configured as the agent’s primary or secondary language. The selected language also determines the welcome message from languageDefaultsConfig. When provided during both session creation and conversation initiation, the session-creation override wins. An invalid override in the conversation-initiation message is ignored and the conversation continues with the stored agent configuration.

Contextual update

Once the conversation is active, add or replace LLM dynamic variables without interrupting it:
At least one value inside contextual_update_values is required. The update is asynchronous and does not produce a direct server response.

User audio

Send this message while the user is speaking:
Use chunks between 20 and 100 milliseconds:

Server-to-client messages

Conversation metadata

Sent after the conversation initiation request:

Agent audio

Sent whenever the agent produces audio:
Decode audio_event.audio_base_64, queue each chunk, and play chunks in the order received without overlapping them.

Conversation ended

Sent after the final agent audio when Karta ends the underlying agent session, including after an inactivity timeout:
Stop audio capture and release call resources when this message arrives. Karta then closes the WebSocket normally with code 1000; clients may also close it immediately after handling the message.

WebSocket close codes

Never reconnect with the same signed URL.

Minimal JavaScript example

After implementing session creation on your application server, request the signed URL from your server and connect: