Skip to main content
POST
/
trunks
Create Trunk
curl --request POST \
  --url https://api.example.com/trunks \
  --header 'Content-Type: application/json' \
  --data '
{
  "name": "<string>",
  "ai_provider": "<string>",
  "sip_username": "<string>",
  "sip_password": "<string>",
  "openai_api_key": "<string>",
  "elevenlabs_api_key": "<string>",
  "elevenlabs_agent_id": "<string>",
  "custom_endpoint": "<string>",
  "system_prompt": "<string>"
}
'
{
  "id": "<string>",
  "name": "<string>",
  "status": "<string>",
  "ai_provider": "<string>",
  "sip_username": "<string>",
  "sip_endpoint": "<string>",
  "created_at": "<string>"
}

Overview

Create a new SIP trunk that links an AI agent to a SIP identity.

Request

name
string
required
Friendly name for this trunk
ai_provider
string
required
AI provider: openai, elevenlabs, or custom
sip_username
string
required
Unique SIP username for this trunk (alphanumeric and hyphens)
sip_password
string
required
SIP password for authentication (minimum 8 characters)
openai_api_key
string
OpenAI API key (required if ai_provider is openai)
elevenlabs_api_key
string
ElevenLabs API key (required if ai_provider is elevenlabs)
elevenlabs_agent_id
string
ElevenLabs agent ID (required if ai_provider is elevenlabs)
custom_endpoint
string
Custom WebSocket endpoint URL (required if ai_provider is custom)
system_prompt
string
Optional system prompt for the AI agent

Example Request

curl -X POST https://api.telepathvoice.com/v1/trunks \
  -H "Authorization: Bearer sk_live_abc123def456..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Customer Support",
    "ai_provider": "openai",
    "sip_username": "support-01",
    "sip_password": "SecurePassword123!",
    "openai_api_key": "sk-proj-...",
    "system_prompt": "You are a helpful customer support representative."
  }'

Python Example

import requests

API_KEY = "sk_live_abc123def456..."
headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json"
}

payload = {
    "name": "Customer Support",
    "ai_provider": "openai",
    "sip_username": "support-01",
    "sip_password": "SecurePassword123!",
    "openai_api_key": "sk-proj-...",
    "system_prompt": "You are a helpful customer support representative."
}

response = requests.post(
    "https://api.telepathvoice.com/v1/trunks",
    headers=headers,
    json=payload
)

trunk = response.json()

Response

id
string
Unique trunk identifier
name
string
Friendly name
status
string
Status: active or error
ai_provider
string
Which AI provider is configured
sip_username
string
SIP username (for carrier configuration)
sip_endpoint
string
Full SIP endpoint URI for carrier
created_at
string
ISO 8601 creation timestamp

Example Response

{
  "id": "conn_abc123xyz",
  "name": "Customer Support",
  "status": "active",
  "ai_provider": "openai",
  "sip_username": "support-01",
  "sip_endpoint": "sip://support-01@sip.telepathvoice.com",
  "created_at": "2024-03-05T15:30:00Z"
}

Error Responses

Missing Required Fields

{
  "error": {
    "code": "MISSING_REQUIRED",
    "message": "Missing required field: openai_api_key"
  }
}
Status Code: 400

Invalid SIP Username

{
  "error": {
    "code": "INVALID_SIP_USERNAME",
    "message": "SIP username must be unique and contain only alphanumeric characters and hyphens"
  }
}
Status Code: 400

SIP Username Already Exists

{
  "error": {
    "code": "SIP_USERNAME_EXISTS",
    "message": "SIP username 'support-01' is already in use"
  }
}
Status Code: 409

Invalid API Credentials

{
  "error": {
    "code": "INVALID_CREDENTIALS",
    "message": "The provided OpenAI API key is invalid"
  }
}
Status Code: 401

Creating Different Provider Types

OpenAI

{
  "name": "OpenAI Support Bot",
  "ai_provider": "openai",
  "sip_username": "openai-bot",
  "sip_password": "StrongPassword123!",
  "openai_api_key": "sk-proj-...",
  "system_prompt": "You are a professional support agent."
}

ElevenLabs

{
  "name": "ElevenLabs Agent",
  "ai_provider": "elevenlabs",
  "sip_username": "elevenlabs-01",
  "sip_password": "StrongPassword456!",
  "elevenlabs_api_key": "sk_...",
  "elevenlabs_agent_id": "agent_abc123..."
}

Custom WebSocket

{
  "name": "Custom AI Endpoint",
  "ai_provider": "custom",
  "sip_username": "custom-bot",
  "sip_password": "StrongPassword789!",
  "custom_endpoint": "wss://your-api.example.com/telepath"
}

Usage Examples

Create with Error Handling

def create_trunk_safely(api_key, trunk_data):
    """Create trunk with error handling"""
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    }

    try:
        response = requests.post(
            "https://api.telepathvoice.com/v1/trunks",
            headers=headers,
            json=trunk_data,
            timeout=30
        )

        if response.status_code == 201:
            return response.json()
        elif response.status_code == 409:
            error = response.json()
            raise Exception(f"Username already exists: {error['message']}")
        elif response.status_code == 401:
            raise Exception("Invalid API credentials")
        else:
            response.raise_for_status()

    except requests.exceptions.RequestException as e:
        print(f"API error: {e}")
        raise

Batch Create Trunks

def create_multiple_trunks(api_key, trunk_configs):
    """Create multiple trunks"""
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    }

    created_trunks = []

    for config in trunk_configs:
        try:
            response = requests.post(
                "https://api.telepathvoice.com/v1/trunks",
                headers=headers,
                json=config
            )

            if response.status_code == 201:
                created_trunks.append(response.json())
                print(f"✓ Created trunk: {config['name']}")
            else:
                print(f"✗ Failed to create trunk: {config['name']}")
                print(f"  Error: {response.json()['error']['message']}")

        except Exception as e:
            print(f"✗ Exception creating {config['name']}: {e}")

    return created_trunks

See Also