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:Request Fields
| Field | Type | Required | Description |
|---|---|---|---|
agent_id | string | ✅ | Agent ID (must be Pipeline or Realtime architecture) |
Response
Status:200 OK
Response Fields
| Field | Type | Description |
|---|---|---|
room_name | string | LiveKit room name (parse to get agent_id) |
token | string | LiveKit participant token (1 hour expiry) |
livekit_url | string | LiveKit WebSocket URL |
agent_name | string | Display name of the agent |
What Happens on Creation
-
API Key Validated
- Key checked against database
- Organization resolved
- User ID extracted
-
Agent Verified
- Agent must belong to organization
- Architecture must be Pipeline or Realtime
- Text agents rejected
-
Credit Check
- Organization credits verified
- Fail-closed: insufficient credits = 402 error
-
Room Created
- LiveKit room created via API
- Agent worker dispatched immediately
- Room name pattern:
agent_{agent_id}_{user_id}_{timestamp}
-
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
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
| Architecture | Supported | Notes |
|---|---|---|
| Pipeline | ✅ Yes | Full STT/LLM/TTS pipeline |
| Realtime | ✅ Yes | OpenAI Realtime or Gemini Live |
| Text | ❌ No | Text agents cannot handle voice |
Best Practices
1. Never Expose API Key
2. Handle Connection Errors
3. Clean Up on Disconnect
4. Check Credits Before Creating
Related Endpoints
- Create Chat Session — Text chat session
- Send Message — Send text messages
- End Session — End and cleanup
Next Steps
LiveKit Documentation
Learn about LiveKit WebRTC integration.
Voice Agents Guide
Build voice agents with Pipeline or Realtime architecture.