Skip to main content

Create WebRTC Call

Creates a test call via the Ultravox API using WebRTC medium. The frontend uses the returned join_url with the Ultravox Client SDK to connect the user's browser microphone to the AI agent.

Endpoint

PropertyValue
Function Namecalls-create
HTTP MethodPOST
AuthenticationSupabase JWT (Bearer token)
Required RoleAny authenticated agency user

Request

Headers

Authorization: Bearer <supabase_jwt_token>
Content-Type: application/json

Body

FieldTypeRequiredDescription
agent_idstringYesUltravox agent ID from agent_mappings.ultravox_agent_id

Response

Success (201)

{
"call_id": "uuid",
"ultravox_call_id": "uv-call-abc123",
"join_url": "wss://voice.ultravox.ai/...",
"created_at": "2025-01-15T10:30:00Z"
}

Partial Success (201)

If the call is created in Ultravox but the local database insert fails, a 201 response is still returned with a warning:

{
"call_id": null,
"ultravox_call_id": "uv-call-abc123",
"join_url": "wss://voice.ultravox.ai/...",
"created_at": "2025-01-15T10:30:00Z",
"warning": "Call created but failed to save to database"
}

Error Responses

StatusCondition
400agent_id is missing
400Ultravox API key not configured for the agency
401Missing or invalid authorization header
403User is not associated with an agency
404Agent not found or does not belong to the user's agency
405HTTP method is not POST
500Failed to retrieve API credentials from the database
500Unexpected server error
502Ultravox API returned an error when creating the call

Behavior

  • Authenticates the user via Supabase JWT and retrieves their agency_id from the users table.
  • Validates that agent_id is provided and belongs to the user's agency via the agent_mappings table.
  • Retrieves the agency's decrypted Ultravox API key by calling the get_agency_credentials RPC.
  • Calls the Ultravox API (POST /api/calls) with medium: { webRtc: {} } to create a browser-based call.
  • Stores the call in the calls table with source='webrtc', direction='outbound', and metadata: { test_call: true }.
  • Returns the joinUrl from Ultravox for use with the Ultravox Client SDK.

Database Tables

Table / RPCOperationDescription
usersReadFetches user profile to determine agency_id
agent_mappingsReadValidates agent_id belongs to the user's agency
get_agency_credentials (RPC)ReadRetrieves decrypted Ultravox API key
callsInsertStores the call record with WebRTC source

External APIs

APIMethodEndpointDescription
UltravoxPOST/api/callsCreates a WebRTC call for the specified agent