For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Platform docsVideosCommunitySign up
CapabilitiesGetting startedVoice AI OrchestrationVoxEngine PlatformAPI ReferenceFAQ
CapabilitiesGetting startedVoice AI OrchestrationVoxEngine PlatformAPI ReferenceFAQ
      • Overview
        • Cartesia
        • Deepgram
        • ElevenLabs
        • Gemini
        • Grok
        • Inworld
        • OpenAI
        • Pipecat
        • Ultravox
        • Yandex
  • Management API
    • Reference
    • Authorization
    • Errors
  • Web SDK
    • Overview
  • Android SDK
    • Overview
  • Android SDK v3
    • Overview
  • iOS SDK
    • Overview
  • React Native SDK
    • Overview
  • Flutter SDK
    • Overview
LogoLogo
Platform docsVideosCommunitySign up
On this page
  • Related guides
  • Contents
  • Usage
  • Factory functions
  • createAgentsClient
  • createRealtimeTTSPlayer
  • AgentsClient
  • Methods
  • addEventListener
  • clearMediaBuffer
  • close
  • custom
  • dtmf
  • id
  • removeEventListener
  • sendMediaTo
  • start
  • stopMediaTo
  • webSocketId
  • Events
  • WebSocketMediaStarted
  • WebSocketMediaEnded
  • AgentsEvents
VoxEngineVoice AI

Cartesia

Agents WebSocket client for Cartesia Line voice agent scenarios.
||View as Markdown|
Was this page helpful?
Edit this page
Previous

ResultSubtype

Next

CCAI

Built with

Cartesia provides a VoxEngine client for connecting a call or media unit to the Cartesia Agents WebSocket API.

Use Cartesia.createAgentsClient(...) to create an AgentsClient for the current scenario.

Related guides

Cartesia connector overview

Learn how Cartesia Line fits into a VoxEngine call flow.

Contents

  • Usage: required module import and basic flow.
  • Factory functions: create the Cartesia Agents client.
  • Methods: start, DTMF, and custom agent messages.
  • Events: WebSocket media bridge events.
  • AgentsEvents: Cartesia Agents event names and payload fields.

Usage

Add the module before using the namespace:

1require(Modules.Cartesia);

Create the client, bridge media, and listen for Cartesia Agents events.

Factory functions

createAgentsClient

Creates a Cartesia.AgentsClient instance.

1createAgentsClient(parameters: AgentsClientParameters): Promise<Cartesia.AgentsClient>

Parameters

ParameterTypeReq.Description
parametersAgentsClientParameters✓

Returns

TypeDescription
Promise<Cartesia.AgentsClient>Resolves to the Cartesia.AgentsClient instance.

createRealtimeTTSPlayer

Creates a new Cartesia.RealtimeTTSPlayer instance with the specified text (TTS is used to play the text). You can attach media streams later via the Cartesia.RealtimeTTSPlayer.sendMediaTo or VoxEngine.sendMediaBetween methods.

1createRealtimeTTSPlayer(text: string, parameters?: RealtimeTTSPlayerParameters): RealtimeTTSPlayer

Parameters

ParameterTypeReq.Description
textstring✓
parametersRealtimeTTSPlayerParameters✗

Returns

TypeDescription
RealtimeTTSPlayerThe requested RealtimeTTSPlayer value.

AgentsClient

Methods

addEventListener

Adds a handler for the specified Cartesia.AgentsEvents or Cartesia.Events event. Use only functions as handlers; anything except a function leads to the error and scenario termination when a handler is called.

1addEventListener(event: Cartesia.Events | Cartesia.AgentsEvents | string, callback: (event: object) => any): void

Parameters

ParameterTypeReq.Description
eventCartesia.Events | Cartesia.AgentsEvents | string✓Event constant or event name to subscribe to.
callback(event: object) => any✓Function called when the event is emitted.

Returns

TypeDescription
voidDoes not return a value.

clearMediaBuffer

Clears the Cartesia WebSocket media buffer.

1clearMediaBuffer(parameters?: ClearMediaBufferParameters): void

Parameters

ParameterTypeReq.Description
parametersClearMediaBufferParameters✗

Returns

TypeDescription
voidDoes not return a value.

close

Closes the Cartesia connection (over WebSocket) or connection attempt.

1close(): void

Parameters

This method does not accept parameters.

Returns

TypeDescription
voidDoes not return a value.

custom

Sends custom metadata to the agent. https://docs.cartesia.ai/line/integrations/web-calls#custom-event

1custom(parameters: Object): void

Parameters

ParameterTypeReq.Description
parametersObject✓

Returns

TypeDescription
voidDoes not return a value.

dtmf

Sends DTMF (dual-tone multi-frequency) tones. https://docs.cartesia.ai/line/integrations/web-calls#dtmf-event

1dtmf(parameters: Object): void

Parameters

ParameterTypeReq.Description
parametersObject✓

Returns

TypeDescription
voidDoes not return a value.

id

Returns the AgentsClient id.

1id(): string

Parameters

This method does not accept parameters.

Returns

TypeDescription
stringThe requested string value.

removeEventListener

Removes a handler for the specified Cartesia.AgentsEvents or Cartesia.Events event.

1removeEventListener(event: Cartesia.Events | Cartesia.AgentsEvents | string, callback?: (event: object) => any): void

Parameters

ParameterTypeReq.Description
eventCartesia.Events | Cartesia.AgentsEvents | string✓Event constant or event name to subscribe to.
callback(event: object) => any✗Function called when the event is emitted.

Returns

TypeDescription
voidDoes not return a value.

sendMediaTo

Starts sending media from the Cartesia (via WebSocket) to the media unit. Cartesia works in real time.

1sendMediaTo(mediaUnit: VoxMediaUnit, parameters?: SendMediaParameters): void

Parameters

ParameterTypeReq.Description
mediaUnitVoxMediaUnit✓
parametersSendMediaParameters✗

Returns

TypeDescription
voidDoes not return a value.

start

Initializes the audio stream configuration. https://docs.cartesia.ai/line/integrations/web-calls#start-event

1start(parameters: Object): void

Parameters

ParameterTypeReq.Description
parametersObject✓

Returns

TypeDescription
voidDoes not return a value.

stopMediaTo

Stops sending media from the Cartesia (via WebSocket) to the media unit.

1stopMediaTo(mediaUnit: VoxMediaUnit): void

Parameters

ParameterTypeReq.Description
mediaUnitVoxMediaUnit✓

Returns

TypeDescription
voidDoes not return a value.

webSocketId

Returns the Cartesia WebSocket id.

1webSocketId(): string

Parameters

This method does not accept parameters.

Returns

TypeDescription
stringThe requested string value.

Events

These events describe audio received through the Cartesia WebSocket media bridge.

WebSocketMediaStarted

Triggered when the audio stream sent by a third party through a Cartesia WebSocket is started playing.

Event constant: Events.WebSocketMediaStarted

Payload

FieldTypeReq.Description
clientAgentsClient✓The Cartesia.AgentsClient instance.
tagstring✗Special tag to name audio streams sent over one WebSocket connection. With it, one can send 2 audios to 2 different media units at the same time.
encodingstring✗Audio encoding formats.
customParameters{ [key: string]: string }✗Custom parameters.

WebSocketMediaEnded

Triggers after the end of the audio stream sent by a third party through a Cartesia WebSocket (1 second of silence).

Event constant: Events.WebSocketMediaEnded

Payload

FieldTypeReq.Description
clientAgentsClient✓The Cartesia.AgentsClient instance.
tagstring✗Special tag to name audio streams sent over one WebSocket connection. With it, one can send 2 audios to 2 different media units at the same time.
mediaInfoWebSocketMediaInfo✗Information about the audio stream that can be obtained after the stream stops or pauses (1 second of silence).

AgentsEvents

These events mirror server messages from the Cartesia Agents WebSocket API. The data field contains the provider event payload.

Unknown

The unknown event.

Event constant: AgentsEvents.Unknown

Payload

FieldTypeReq.Description
clientAgentsClient✓The Cartesia.AgentsClient instance.
dataObject✗This event payload is provider-specific. See the partner event documentation for the full payload shape.
HTTPResponse

The HTTP response event.

Event constant: AgentsEvents.HTTPResponse

Payload

FieldTypeReq.Description
clientAgentsClient✓The Cartesia.AgentsClient instance.
dataObject✗This event payload is provider-specific. See the partner event documentation for the full payload shape.
ACK

Server acknowledgment of the start event, confirming stream configuration. https://docs.cartesia.ai/line/integrations/web-calls#ack-event

Event constant: AgentsEvents.ACK

Payload

FieldTypeReq.Description
clientAgentsClient✓The Cartesia.AgentsClient instance.
dataObject✗This event payload is provider-specific. See the partner event documentation for the full payload shape.
Clear

Indicates the agent wants to clear/interrupt the current audio stream. https://docs.cartesia.ai/line/integrations/web-calls#clear-event

Event constant: AgentsEvents.Clear

Payload

FieldTypeReq.Description
clientAgentsClient✓The Cartesia.AgentsClient instance.
dataObject✗This event payload is provider-specific. See the partner event documentation for the full payload shape.
DTMF

Server sends DTMF tones from the agent. https://docs.cartesia.ai/line/integrations/web-calls#dtmf-event-2

Event constant: AgentsEvents.DTMF

Payload

FieldTypeReq.Description
clientAgentsClient✓The Cartesia.AgentsClient instance.
dataObject✗This event payload is provider-specific. See the partner event documentation for the full payload shape.
Custom

Server sends custom metadata from the agent. https://docs.cartesia.ai/line/integrations/web-calls#custom-event-2

Event constant: AgentsEvents.Custom

Payload

FieldTypeReq.Description
clientAgentsClient✓The Cartesia.AgentsClient instance.
dataObject✗The event’s data.
WebSocketError

The WebSocket error response event.

Event constant: AgentsEvents.WebSocketError

Payload

FieldTypeReq.Description
clientAgentsClient✓The Cartesia.AgentsClient instance.
dataObject✗The event’s data.
ConnectorInformation

Contains information about connector.

Event constant: AgentsEvents.ConnectorInformation

Payload

FieldTypeReq.Description
clientAgentsClient✓The Cartesia.AgentsClient instance.
dataObject✗The event’s data.