Skip to main content

Create Outbound Call

Initiates an outbound phone call to a single number using an AI agent. The call is placed through Ultravox which handles the Telnyx telephony integration. Only agency owners and admins can make outbound calls.

Endpoint

PropertyValue
Function Namecalls-create-outbound
HTTP MethodPOST
AuthenticationSupabase JWT (Bearer token)
Required Roleagency_owner or agency_admin

Request

Headers

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

Body

FieldTypeRequiredDescription
agent_idstringYesUltravox agent ID from agent_mappings.ultravox_agent_id
to_numberstringYesDestination phone number in E.164 format (e.g., +15551234567)
from_numberstringNoCaller ID in E.164 format. Must be an active agency phone number. Defaults to the agency's first active number.
first_speaker"agent" | "user"NoWho speaks first when the call connects. Defaults to agent.
metadataobjectNoCustom metadata object passed through to Ultravox webhooks.

Response

Success (200)

{
"call_id": "uuid",
"ultravox_call_id": "uv-call-abc123",
"status": "initiated",
"to_number": "+15551234567",
"from_number": "+15559876543"
}

Partial Success (200)

If the call is initiated in Ultravox but the local database insert fails:

{
"call_id": null,
"ultravox_call_id": "uv-call-abc123",
"status": "initiated",
"to_number": "+15551234567",
"from_number": "+15559876543",
"warning": "Call initiated but failed to save to database"
}

Error Responses

StatusCondition
400agent_id is missing
400to_number is missing or not in E.164 format
400from_number is not in E.164 format or not active in the agency
400No active phone number available (when from_number is not provided)
400Ultravox API key not configured
400Telnyx API key not configured
401Missing or invalid authorization header
403User is not associated with an agency
403User role is not agency_owner or agency_admin
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 initiating the call

Behavior

  • Authenticates the user via Supabase JWT and verifies they have the agency_owner or agency_admin role.
  • Validates agent_id and to_number are provided, and that to_number is in E.164 format (+ followed by 7–15 digits).
  • Validates the agent belongs to the user's agency via the agent_mappings table.
  • Retrieves decrypted API keys via get_agency_credentials RPC. Both Ultravox and Telnyx keys must be configured.
  • Resolves from_number:
    • If provided, validates it exists in agency_phone_numbers with is_active=true and status='active'.
    • If omitted, selects the agency's first active phone number ordered by created_at.
  • Builds the Ultravox API payload with medium: { telnyx: { destinationPhoneNumber } }.
  • Maps first_speaker to Ultravox's enum: 'agent'FIRST_SPEAKER_AGENT, 'user'FIRST_SPEAKER_USER.
  • Calls the Ultravox API (POST /api/calls) to initiate the outbound call.
  • Stores the call in the calls table with source='api', direction='outbound', resolved from_number and to_number.

Database Tables

Table / RPCOperationDescription
usersReadFetches user profile to determine agency_id and role
agent_mappingsReadValidates agent_id belongs to the user's agency
agency_phone_numbersReadValidates or resolves the from_number caller ID
get_agency_credentials (RPC)ReadRetrieves decrypted Ultravox and Telnyx API keys
callsInsertStores the outbound call record

External APIs

APIMethodEndpointDescription
UltravoxPOST/api/callsInitiates the outbound call via Telnyx medium