> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.phonic.co/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.phonic.co/_mcp/server.

# Add Custom Phone Number

POST https://api.phonic.ai/v1/agents/{nameOrId}/custom-phone-numbers
Content-Type: application/json

Adds a bring-your-own phone number to an agent in the authenticated workspace and project. Use this to connect a phone number and SIP trunk the user is authorized to manage; it does not purchase a number or place a call. Stores the supplied SIP address and credentials for calls and transfers, and saves any configuration endpoint for calls on this number. The user must configure their SIP trunk to route inbound calls to Phonic. A configured endpoint receives requests during call setup; use only an endpoint the user intends Phonic to contact.

Reference: https://docs.phonic.co/api-reference/agents/add-custom-phone-number

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication header of the form `Bearer <PHONIC_API_KEY>`. Manage your API keys [here](https://phonic.co/api-keys).

## Request

### Path parameters

- `nameOrId` (string, required) — The name or the ID of the agent.

### Query parameters

- `project` (string, optional, default: main) — The name of the project containing the agent. Only used when `nameOrId` is a name.

### Headers

- `X-Sip-Address` (string, required) — SIP address of the user's SIP trunk. Required. All three SIP headers (X-Sip-Address, X-Sip-Auth-Username, X-Sip-Auth-Password) must be provided. They are used for outbound calls and call transfers from the agent.
- `X-Sip-Auth-Username` (string, required) — SIP auth username. Required. All three SIP headers (X-Sip-Address, X-Sip-Auth-Username, X-Sip-Auth-Password) must be provided. They are used for outbound calls and call transfers from the agent.
- `X-Sip-Auth-Password` (string, required) — SIP auth password. Required. All three SIP headers (X-Sip-Address, X-Sip-Auth-Username, X-Sip-Auth-Password) must be provided. They are used for outbound calls and call transfers from the agent.

### Body (application/json)

This endpoint expects an object.

- `phone_number` (string, required) — The E.164 formatted phone number to add (e.g., "+15551234567").
- `configuration_endpoint` (AgentsNameOrIdCustomPhoneNumbersPostRequestBodyContentApplicationJsonSchemaConfigurationEndpoint, optional, nullable) — When not `null`, the agent will call this endpoint to get configuration options for calls on this phone number.
- `sip` (AgentsNameOrIdCustomPhoneNumbersPostRequestBodyContentApplicationJsonSchemaSip, optional) — SIP trunk settings for this phone number, applied to both its inbound trunk and the trunk created for each outbound call. Set at creation; remove and re-add the number to change them.

## Response

### 200

Success response

- `success` (boolean, required)

## Errors

### 400 Bad Request Error

Invalid parameters or phone number already assigned

- `error` (BasicErrorError, optional)

### 401 Unauthorized Error

Unsupported authentication method

- `error` (BasicErrorError, optional)

### 403 Forbidden Error

Forbidden

- `error` (BasicErrorError, optional)

### 404 Not Found Error

Agent not found

- `error` (BasicErrorError, optional)

### 409 Conflict Error

The agent is currently being updated (please try again), or the agent is disabled.

- `error` (BasicErrorError, optional)

## Types

### AgentsNameOrIdCustomPhoneNumbersPostRequestBodyContentApplicationJsonSchemaConfigurationEndpoint

When not `null`, the agent will call this endpoint to get configuration options for calls on this phone number.

- `url` (string, required) — URL to call. Must be a publicly routable HTTPS URL without embedded credentials.
- `headers` (map from string to string, optional) — Object of key-value pairs.
- `timeout_ms` (integer, optional, default: 3000) — Timeout in milliseconds for the endpoint call.

### AgentsNameOrIdCustomPhoneNumbersPostRequestBodyContentApplicationJsonSchemaSip

SIP trunk settings for this phone number, applied to both its inbound trunk and the trunk created for each outbound call. Set at creation; remove and re-add the number to change them.

- `transport` (enum, optional, default: auto) — SIP signaling transport used for calls on this phone number. The SIP address must not carry a `;transport=` parameter; set it here instead.
  - Allowed values: `auto`, `udp`, `tcp`, `tls`
- `media_encryption` (enum, optional, default: disabled) — Whether media (SRTP) encryption is used on calls on this phone number.
  - Allowed values: `disabled`, `allowed`, `required`

### BasicErrorError

- `message` (string, required) — Error message
- `code` (string, optional) — Error code

## Examples

### Add custom phone number response

**Response**

```json
{
  "success": true
}
```

**SDK Code**

```python Add custom phone number response
import requests

url = "https://api.phonic.ai/v1/agents/nameOrId/custom-phone-numbers"

querystring = {"project":"main"}

headers = {
    "X-Sip-Address": "X-Sip-Address",
    "X-Sip-Auth-Username": "X-Sip-Auth-Username",
    "X-Sip-Auth-Password": "X-Sip-Auth-Password",
    "Authorization": "Bearer <apiKey>"
}

response = requests.post(url, headers=headers, params=querystring)

print(response.json())
```

```javascript Add custom phone number response
const url = 'https://api.phonic.ai/v1/agents/nameOrId/custom-phone-numbers?project=main';
const options = {
  method: 'POST',
  headers: {
    'X-Sip-Address': 'X-Sip-Address',
    'X-Sip-Auth-Username': 'X-Sip-Auth-Username',
    'X-Sip-Auth-Password': 'X-Sip-Auth-Password',
    Authorization: 'Bearer <apiKey>'
  }
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Add custom phone number response
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.phonic.ai/v1/agents/nameOrId/custom-phone-numbers?project=main"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("X-Sip-Address", "X-Sip-Address")
	req.Header.Add("X-Sip-Auth-Username", "X-Sip-Auth-Username")
	req.Header.Add("X-Sip-Auth-Password", "X-Sip-Auth-Password")
	req.Header.Add("Authorization", "Bearer <apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Add custom phone number response
require 'uri'
require 'net/http'

url = URI("https://api.phonic.ai/v1/agents/nameOrId/custom-phone-numbers?project=main")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-Sip-Address"] = 'X-Sip-Address'
request["X-Sip-Auth-Username"] = 'X-Sip-Auth-Username'
request["X-Sip-Auth-Password"] = 'X-Sip-Auth-Password'
request["Authorization"] = 'Bearer <apiKey>'

response = http.request(request)
puts response.read_body
```

```java Add custom phone number response
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.phonic.ai/v1/agents/nameOrId/custom-phone-numbers?project=main")
  .header("X-Sip-Address", "X-Sip-Address")
  .header("X-Sip-Auth-Username", "X-Sip-Auth-Username")
  .header("X-Sip-Auth-Password", "X-Sip-Auth-Password")
  .header("Authorization", "Bearer <apiKey>")
  .asString();
```

```php Add custom phone number response
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.phonic.ai/v1/agents/nameOrId/custom-phone-numbers?project=main', [
  'headers' => [
    'Authorization' => 'Bearer <apiKey>',
    'X-Sip-Address' => 'X-Sip-Address',
    'X-Sip-Auth-Password' => 'X-Sip-Auth-Password',
    'X-Sip-Auth-Username' => 'X-Sip-Auth-Username',
  ],
]);

echo $response->getBody();
```

```csharp Add custom phone number response
using RestSharp;

var client = new RestClient("https://api.phonic.ai/v1/agents/nameOrId/custom-phone-numbers?project=main");
var request = new RestRequest(Method.POST);
request.AddHeader("X-Sip-Address", "X-Sip-Address");
request.AddHeader("X-Sip-Auth-Username", "X-Sip-Auth-Username");
request.AddHeader("X-Sip-Auth-Password", "X-Sip-Auth-Password");
request.AddHeader("Authorization", "Bearer <apiKey>");
IRestResponse response = client.Execute(request);
```

```swift Add custom phone number response
import Foundation

let headers = [
  "X-Sip-Address": "X-Sip-Address",
  "X-Sip-Auth-Username": "X-Sip-Auth-Username",
  "X-Sip-Auth-Password": "X-Sip-Auth-Password",
  "Authorization": "Bearer <apiKey>"
]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.phonic.ai/v1/agents/nameOrId/custom-phone-numbers?project=main")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### agents_add_custom_phone_number_example

**Request**

```json
{
  "phone_number": "+15551234567",
  "configuration_endpoint": {
    "url": "https://api.example.com/config",
    "headers": {
      "Authorization": "Bearer token123"
    },
    "timeout_ms": 7000
  },
  "sip": {
    "transport": "tls",
    "media_encryption": "required"
  }
}
```

**Response**

```json
{
  "success": true
}
```

**SDK Code**

```python agents_add_custom_phone_number_example
import requests

url = "https://api.phonic.ai/v1/agents/nameOrId/custom-phone-numbers"

querystring = {"project":"main"}

payload = {
    "phone_number": "+15551234567",
    "configuration_endpoint": {
        "url": "https://api.example.com/config",
        "headers": { "Authorization": "Bearer token123" },
        "timeout_ms": 7000
    },
    "sip": {
        "transport": "tls",
        "media_encryption": "required"
    }
}
headers = {
    "X-Sip-Address": "X-Sip-Address",
    "X-Sip-Auth-Username": "X-Sip-Auth-Username",
    "X-Sip-Auth-Password": "X-Sip-Auth-Password",
    "Authorization": "Bearer <apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers, params=querystring)

print(response.json())
```

```javascript agents_add_custom_phone_number_example
const url = 'https://api.phonic.ai/v1/agents/nameOrId/custom-phone-numbers?project=main';
const options = {
  method: 'POST',
  headers: {
    'X-Sip-Address': 'X-Sip-Address',
    'X-Sip-Auth-Username': 'X-Sip-Auth-Username',
    'X-Sip-Auth-Password': 'X-Sip-Auth-Password',
    Authorization: 'Bearer <apiKey>',
    'Content-Type': 'application/json'
  },
  body: '{"phone_number":"+15551234567","configuration_endpoint":{"url":"https://api.example.com/config","headers":{"Authorization":"Bearer token123"},"timeout_ms":7000},"sip":{"transport":"tls","media_encryption":"required"}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go agents_add_custom_phone_number_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.phonic.ai/v1/agents/nameOrId/custom-phone-numbers?project=main"

	payload := strings.NewReader("{\n  \"phone_number\": \"+15551234567\",\n  \"configuration_endpoint\": {\n    \"url\": \"https://api.example.com/config\",\n    \"headers\": {\n      \"Authorization\": \"Bearer token123\"\n    },\n    \"timeout_ms\": 7000\n  },\n  \"sip\": {\n    \"transport\": \"tls\",\n    \"media_encryption\": \"required\"\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("X-Sip-Address", "X-Sip-Address")
	req.Header.Add("X-Sip-Auth-Username", "X-Sip-Auth-Username")
	req.Header.Add("X-Sip-Auth-Password", "X-Sip-Auth-Password")
	req.Header.Add("Authorization", "Bearer <apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby agents_add_custom_phone_number_example
require 'uri'
require 'net/http'

url = URI("https://api.phonic.ai/v1/agents/nameOrId/custom-phone-numbers?project=main")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-Sip-Address"] = 'X-Sip-Address'
request["X-Sip-Auth-Username"] = 'X-Sip-Auth-Username'
request["X-Sip-Auth-Password"] = 'X-Sip-Auth-Password'
request["Authorization"] = 'Bearer <apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"phone_number\": \"+15551234567\",\n  \"configuration_endpoint\": {\n    \"url\": \"https://api.example.com/config\",\n    \"headers\": {\n      \"Authorization\": \"Bearer token123\"\n    },\n    \"timeout_ms\": 7000\n  },\n  \"sip\": {\n    \"transport\": \"tls\",\n    \"media_encryption\": \"required\"\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java agents_add_custom_phone_number_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.phonic.ai/v1/agents/nameOrId/custom-phone-numbers?project=main")
  .header("X-Sip-Address", "X-Sip-Address")
  .header("X-Sip-Auth-Username", "X-Sip-Auth-Username")
  .header("X-Sip-Auth-Password", "X-Sip-Auth-Password")
  .header("Authorization", "Bearer <apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"phone_number\": \"+15551234567\",\n  \"configuration_endpoint\": {\n    \"url\": \"https://api.example.com/config\",\n    \"headers\": {\n      \"Authorization\": \"Bearer token123\"\n    },\n    \"timeout_ms\": 7000\n  },\n  \"sip\": {\n    \"transport\": \"tls\",\n    \"media_encryption\": \"required\"\n  }\n}")
  .asString();
```

```php agents_add_custom_phone_number_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.phonic.ai/v1/agents/nameOrId/custom-phone-numbers?project=main', [
  'body' => '{
  "phone_number": "+15551234567",
  "configuration_endpoint": {
    "url": "https://api.example.com/config",
    "headers": {
      "Authorization": "Bearer token123"
    },
    "timeout_ms": 7000
  },
  "sip": {
    "transport": "tls",
    "media_encryption": "required"
  }
}',
  'headers' => [
    'Authorization' => 'Bearer <apiKey>',
    'Content-Type' => 'application/json',
    'X-Sip-Address' => 'X-Sip-Address',
    'X-Sip-Auth-Password' => 'X-Sip-Auth-Password',
    'X-Sip-Auth-Username' => 'X-Sip-Auth-Username',
  ],
]);

echo $response->getBody();
```

```csharp agents_add_custom_phone_number_example
using RestSharp;

var client = new RestClient("https://api.phonic.ai/v1/agents/nameOrId/custom-phone-numbers?project=main");
var request = new RestRequest(Method.POST);
request.AddHeader("X-Sip-Address", "X-Sip-Address");
request.AddHeader("X-Sip-Auth-Username", "X-Sip-Auth-Username");
request.AddHeader("X-Sip-Auth-Password", "X-Sip-Auth-Password");
request.AddHeader("Authorization", "Bearer <apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"phone_number\": \"+15551234567\",\n  \"configuration_endpoint\": {\n    \"url\": \"https://api.example.com/config\",\n    \"headers\": {\n      \"Authorization\": \"Bearer token123\"\n    },\n    \"timeout_ms\": 7000\n  },\n  \"sip\": {\n    \"transport\": \"tls\",\n    \"media_encryption\": \"required\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift agents_add_custom_phone_number_example
import Foundation

let headers = [
  "X-Sip-Address": "X-Sip-Address",
  "X-Sip-Auth-Username": "X-Sip-Auth-Username",
  "X-Sip-Auth-Password": "X-Sip-Auth-Password",
  "Authorization": "Bearer <apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "phone_number": "+15551234567",
  "configuration_endpoint": [
    "url": "https://api.example.com/config",
    "headers": ["Authorization": "Bearer token123"],
    "timeout_ms": 7000
  ],
  "sip": [
    "transport": "tls",
    "media_encryption": "required"
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.phonic.ai/v1/agents/nameOrId/custom-phone-numbers?project=main")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```