#is there any exposed api, for backend to send message to a speicific conversation?

1 messages · Page 1 of 1 (latest)

gritty snowBOT
#
AI-generated Answer for zqilk

Short answer: not via REST. To inject text into an ongoing conversation you use WebSockets.

What’s available in the official docs:

  • If your backend holds the live conversation socket, you can send a user_message over that socket to inject text into that specific conversation. See client‑to‑server events (type: user_message). (elevenlabs.io)
  • If you need to attach to an already running conversation by ID from the backend, there’s an enterprise-only monitoring WebSocket you can connect to with wss://api.elevenlabs.io/v1/convai/conversations/{conversation_id}/monitor. From there you can enable human takeover and send_human_message to the user. (elevenlabs.io)
  • There is a REST endpoint to read conversation details, but no REST endpoint to post a message to a conversation. (elevenlabs.io)
  • For text-only “Chat Mode,” SDKs expose sendUserMessage on the active conversation session; this still rides the live socket you created for that session. (elevenlabs.io)

If you can share whether you need enterprise monitoring/human-takeover or you just want to programmatically message during your own session, I can point you to the exact snippet. (elevenlabs.io)

Sources:
Client to server events | ElevenLabs Documentation
Real-time monitoring | ElevenLabs Documentation
Get conversation details | ElevenLabs Documentation
Chat Mode | ElevenLabs Documentation
Client to server events | ElevenLabs Documentation

west patrol
#

so how should my backend coinnect to the conversation thorugh the websocket? how can i establish the connection

gritty snowBOT
#
AI-generated Answer for zqilk

Here’s the officially supported way to open a backend WebSocket to an ElevenLabs agent conversation:

  1. Pick the correct endpoint
  1. Establish the WebSocket from your backend
  • Use any standard WebSocket client (Node, Python, etc.) and connect to either:
    • wss://api.elevenlabs.io/v1/convai/conversation?agent_id=<id> (public), or
    • the signed_url you fetched (private). (elevenlabs.io)
  1. Start/drive the conversation
  • On connect you’ll exchange events defined in the Agent WebSocket API. You can:
    • Send conversation_initiation_client_data to override agent/tts settings,
    • Send user_message or user_audio_chunk to talk to the agent,
    • Send contextual_update for non-interrupting context,
    • Reply with pong when the server pings. (elevenlabs.io)
  1. Useful references and examples
  • WebSocket how-to (auth, signed URL, example cURL, event overview). (elevenlabs.io)
  • Agent WebSocket API reference (handshake URL, message types, and sample payloads). (elevenlabs.io)
  • JS SDK docs show the same signed-URL flow on the server if you prefer using the SDK alongside your backend. (elevenlabs.io)

Note: If you’d rather use WebRTC (client or SDK), that’s supported as an alternative connection type; switch via connectionType in the SDK and use a conversation token instead of a signed WebSocket URL. (elevenlabs.io)

Sources:
WebSocket | ElevenLabs Documentation
WebSocket | ElevenLabs Documentation
WebSocket | ElevenLabs Documentation
Agent WebSockets | ElevenLabs Documentation
WebSocket | ElevenLabs Documentation
Agent WebSockets | ElevenLabs Documentation
JavaScript SDK | ElevenLabs Documentation
ElevenLabs Conversational AI now supports WebRTC

west patrol
#

so the agent must be in a conversation so it should be active, and the message sent will be sending to the converastion its in?

gritty snowBOT
#
AI-generated Answer for zqilk

Short answer: yes.

  • When you start a session (WebSocket or WebRTC) with an agent, a new conversation is created. The server immediately sends conversation_initiation_metadata that includes conversation_id. Any events you send on that connection (for example type: "user_message") are appended to that specific conversation and trigger the agent’s reply. (elevenlabs.io)
  • Practically, this means the agent must be in an active session for your backend to deliver a message; messages are scoped to the live conversation represented by that socket/WebRTC session. There isn’t a documented REST endpoint to push a new user message into an arbitrary existing conversation outside the active session. (elevenlabs.io)
  • You can later query the conversation by ID over REST (status, transcript, metadata), but that does not send new messages. (elevenlabs.io)

Relevant docs:

Sources:
Client events | ElevenLabs Documentation
WebSocket | ElevenLabs Documentation
Get conversation details | ElevenLabs Documentation
WebSocket | ElevenLabs Documentation
Client to server events | ElevenLabs Documentation
Client events | ElevenLabs Documentation
Chat Mode | ElevenLabs Documentation
Get conversation details | ElevenLabs Documentation

west patrol
#

wait it starts a new conversation with the agent? what if i started the conversation uysing

await conversation.startSession({
agentId: agentId || localStorage.getItem('currentAgentId') || AGENT_ID,
connectionType: 'webrtc', // Use WebRTC for better quality
});

how would it work now? or i have to start convo using WebSocket, if i did it in my way, how can i send the message to that conversation later after the conversation statred

gritty snowBOT
#
AI-generated Answer for zqilk

Short answer:

  • startSession always creates a new conversation and returns its conversationId. WebRTC is fully supported (you don’t need to switch to WebSocket). (elevenlabs.io)

Details and how to send a message later:

  • Getting the conversation ID

    • The SDK’s startSession resolves to a conversationId you can store. You can also confirm or fetch details later via GET /v1/convai/conversations/:conversation_id. (elevenlabs.io)
  • Private/authenticated sessions with WebRTC

    • For private agents, obtain a WebRTC conversation token from your backend via GET /v1/convai/conversation/token and pass it to startSession. (elevenlabs.io)
  • Sending a message to an already-started conversation from your backend

    • Enterprise option (server-side injection): Use the real‑time monitoring WebSocket and attach by conversationId:
      • Connect: wss://api.elevenlabs.io/v1/convai/conversations/{conversation_id}/monitor (requires Agents Write scope). (elevenlabs.io)
      • For chat conversations, you can take over and send text:
        • enable_human_takeover, then send_human_message with { text: "..." }, and disable_human_takeover when done. (elevenlabs.io)
      • Note: This monitoring/command channel is enterprise‑only. (elevenlabs.io)
    • Non‑enterprise option (client relays):
      • There is no documented public REST endpoint to push a user message into a live conversation. Instead, send the message from the client that owns the active connection using client‑to‑server events such as:
        • type: "user_message" (injects text as if the user said it)
        • type: "contextual_update" (adds background context without interrupting flow) (elevenlabs.io)
  • WebRTC vs WebSocket

    • Both transports start a new conversation and yield a conversationId; the monitoring endpoint attaches by conversationId regardless of how the session was started. (elevenlabs.io)

If you need, I can sketch the minimal server flow for the monitoring socket using your conversationId.

Sources:
React SDK | ElevenLabs Documentation
React SDK | ElevenLabs Documentation
Get conversation token | ElevenLabs Documentation
Real-time monitoring | ElevenLabs Documentation
Real-time monitoring | ElevenLabs Documentation
Real-time monitoring | ElevenLabs Documentation
Client to server events | ElevenLabs Documentation
React SDK | ElevenLabs Documentation

west patrol
#

so u mention send the message from the client that owns the active connection using client‑to‑server events such as, and i notice in the documentation, it uses a websocket instance right, how can i create that using the startSession or the conversation id then

gritty snowBOT
#
AI-generated Answer for zqilk

Short answer:

  • To create the WebSocket, start the session with connectionType: 'websocket'. The SDK opens the WS for you; you don’t manually pass a conversation_id to attach. For public agents use agentId; for private agents fetch a signedUrl from your backend and pass it to startSession. (elevenlabs.io)
  • If you already started the session with WebRTC, keep using the same Conversation instance to send messages (e.g., sendUserMessage). There’s no standard endpoint to “attach a new WebSocket by conversation_id” to an existing session. (elevenlabs.io)

How to open the connection

  • WebSocket (public agent):
    const conversation = await Conversation.startSession({
    agentId: '<agent_id>',
    connectionType: 'websocket'
    });
    // send a message
    conversation.sendUserMessage('hi'); (elevenlabs.io)
  • WebSocket (private agent):
    // server: GET /v1/convai/conversation/get-signed-url?agent_id=... with xi-api-key
    // client:
    const signedUrl = await fetch('/signed-url').then(r => r.text());
    const conversation = await Conversation.startSession({ signedUrl, connectionType: 'websocket' }); (elevenlabs.io)
  • WebRTC:
    // server: GET /v1/convai/conversation/token?agent_id=...
    const token = await fetch('/conversation-token').then(r => r.text());
    const conversation = await Conversation.startSession({ conversationToken: token, connectionType: 'webrtc' });
    // still use the same Conversation methods to send messages
    conversation.sendUserMessage('hi'); (elevenlabs.io)

Sending messages/events

  • With either connection type, use the Conversation methods:
    • sendUserMessage(text): prompts the agent to respond
    • sendContextualUpdate(text): non-interrupting context
    • sendUserActivity(): typing/interaction signal
    • getId(): returns the conversation ID if you need to reference it elsewhere
      These map to the WebSocket client-to-server events documented in the API reference. (elevenlabs.io)

Attaching by conversation_id

  • Not supported for general use. The normal WS endpoint initiates a new conversation using agent_id (or a signed URL). You can’t open a new client WS bound to an existing conversation via conversation_id. (elevenlabs.io)
  • Enterprise-only: there is a separate monitoring WS you can connect to an active conversation by ID and, among other controls, send a human message during chat takeover:
    wss://api.elevenlabs.io/v1/convai/conversations/{conversation_id}/monitor. (elevenlabs.io)

If you need, I can show a minimal server route for signed URLs or WebRTC tokens.

Sources:
JavaScript SDK | ElevenLabs Documentation
JavaScript SDK | ElevenLabs Documentation
JavaScript SDK | ElevenLabs Documentation
JavaScript SDK | ElevenLabs Documentation
JavaScript SDK | ElevenLabs Documentation
JavaScript SDK | ElevenLabs Documentation
WebSocket | ElevenLabs Documentation
Real-time monitoring | ElevenLabs Documentation

west patrol
#

ok so i just need to store the conversation instance in my backend