Skip to main content
POST
/
api
/
webrtc
/
token
curl -X POST https://api.vaanivoice.ai/api/webrtc/token \
  -H "X-API-Key: vaani_<your_key>" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": "d083374a-c167-4bda-b8bc-2a418ca85f35",
    "voice_gender": "female",
    "primary_language": "en",
    "welcome_message": "Hello! How can I help you today?"
  }'
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "room_name": "room_d083374a_c167_4bda_b8bc_2a418ca85f35_abc123",
  "agent_name": "d083374a-c167-4bda-b8bc-2a418ca85f35",
  "connection_url": "wss://livekit.vaaniresearch.com"
}

Generate WebRTC Token

Generate a LiveKit-compatible WebRTC token and dispatch a voice agent. Use this token to connect a browser or mobile client directly to a Vaani voice agent over a real-time audio channel — no phone number required.

Parameters

agent_id
string
UUID (or name) of the agent to dispatch. Either agent_id or agent_name is required.
agent_name
string
Display name of the agent. Either agent_id or agent_name is required.
voice_gender
string
default:"female"
Voice gender preset: "male" | "female".
primary_language
string
default:"hi"
Primary language code for the session (e.g. "en", "hi").
secondary_language
string
default:"en"
Fallback language code for the session.
welcome_message
string
Custom greeting the agent speaks when the call connects. Overrides the agent’s default greeting.
welcome_interruptible
boolean
default:"true"
Whether the welcome message can be interrupted by the user speaking.
bg_noise_enabled
boolean
default:"false"
Enable background noise for the session.
bg_noise_volume
integer
default:"60"
Background noise volume (0–100).
voice_speed
number
default:"1.0"
Speech speed multiplier (0.6–1.4).
websocket_url
string
Override the LiveKit server WebSocket URL (advanced — leave unset to use the default).
env_flag
string
Environment flag passed to the internal backend (advanced use).
metadata
object
Arbitrary metadata key-value pairs forwarded to the agent session.

Request Example

curl -X POST https://api.vaanivoice.ai/api/webrtc/token \
  -H "X-API-Key: vaani_<your_key>" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": "d083374a-c167-4bda-b8bc-2a418ca85f35",
    "voice_gender": "female",
    "primary_language": "en",
    "welcome_message": "Hello! How can I help you today?"
  }'

Response

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "room_name": "room_d083374a_c167_4bda_b8bc_2a418ca85f35_abc123",
  "agent_name": "d083374a-c167-4bda-b8bc-2a418ca85f35",
  "connection_url": "wss://livekit.vaaniresearch.com"
}
token
string
Short-lived LiveKit JWT. Pass this to the LiveKit client SDK to connect.
room_name
string
The LiveKit room the agent has been dispatched to. The token grants access to this room only.
agent_name
string
Agent identifier that was dispatched.
connection_url
string
LiveKit server WebSocket URL (wss://...). Use this as the server URL in the LiveKit client SDK.

Connecting in the Browser

Use the LiveKit JavaScript SDK to connect:
<script src="https://unpkg.com/livekit-client/dist/livekit-client.umd.min.js"></script>
<script>
  async function startCall() {
    const res = await fetch("https://api.vaanivoice.ai/api/webrtc/token", {
      method: "POST",
      headers: { "X-API-Key": "vaani_<your_key>", "Content-Type": "application/json" },
      body: JSON.stringify({ agent_id: "your-agent-id", primary_language: "en" }),
    });
    const { token, connection_url } = await res.json();

    const room = new LivekitClient.Room();
    await room.connect(connection_url, token);

    // Publish microphone
    await room.localParticipant.setMicrophoneEnabled(true);
  }
</script>
Tokens are single-use and short-lived. Generate a new token for each call session.