Skip to main content

Overview

Creates a LiveKit WebRTC voice session for real-time voice interactions. Returns a participant token to connect directly to LiveKit. Authentication: X-API-Key header required (server-side only) Use Case: Voice calls via browser microphone (not text chat)

Request

Headers:
Body:

Request Fields


Response

Status: 200 OK

Response Fields


What Happens on Creation

  1. API Key Validated
    • Key checked against database
    • Organization resolved
    • User ID extracted
  2. Agent Verified
    • Agent must belong to organization
    • Architecture must be Pipeline or Realtime
    • Text agents rejected
  3. Credit Check
    • Organization credits verified
    • Fail-closed: insufficient credits = 402 error
  4. Room Created
    • LiveKit room created via API
    • Agent worker dispatched immediately
    • Room name pattern: agent_{agent_id}_{user_id}_{timestamp}
  5. Token Generated
    • Short-lived participant token (1 hour)
    • Grants: room join, publish, subscribe
    • Identity set to user ID

Error Responses

400 Bad Request

401 Unauthorized

402 Payment Required

404 Not Found

500 Server Error


Examples

cURL

JavaScript (Backend Proxy)

React (Connect to LiveKit)

Next.js API Route


LiveKit Integration

Room Name Pattern

Example: agent_5b710eca_user123_1705312800000 The agent worker parses this to determine which agent to dispatch.

Token Grants

Generated token includes these grants:

Token Expiry

  • Validity: 1 hour
  • Use Case: Enough time for typical voice calls
  • After Expiry: Must create new session

Agent Architecture Requirements

Error if Text Agent:

Best Practices

1. Never Expose API Key

2. Handle Connection Errors

3. Clean Up on Disconnect

4. Check Credits Before Creating



Next Steps

LiveKit Documentation

Learn about LiveKit WebRTC integration.

Voice Agents Guide

Build voice agents with Pipeline or Realtime architecture.