> This is a page from the ElevenLabs documentation. For a complete page index, fetch https://elevenlabs.io/docs/llms.txt. For the full documentation in a single file, fetch https://elevenlabs.io/docs/llms-full.txt.

# 导入电话号码

POST https://api.elevenlabs.io/v1/convai/phone-numbers
Content-Type: application/json

从服务提供商配置导入电话号码（Twilio、Exotel 或 SIP 中继）

Reference: https://elevenlabs.io/docs/eleven-agents/api-reference/phone-numbers/create

## Servers

- `https://api.elevenlabs.io` (Production, default)
- `https://api.us.elevenlabs.io` (Production US)
- `https://api.eu.residency.elevenlabs.io` (Production EU)
- `https://api.in.residency.elevenlabs.io` (Production India)
- `https://api.sg.residency.elevenlabs.io` (Production Singapore)

## Request

### Body (application/json)

This endpoint expects a PhoneNumbersCreateRequestBody.

- `PhoneNumbersCreateRequestBody`
  - `provider`: `twilio`
    - `label` (string, required) — 电话号码标签
    - `phone_number` (string, required) — 电话号码
    - `sid` (string, required) — Twilio 账户 SID（以 `AC` 开头）或 API Key SID（以 `SK` 开头）。
    - `token` (string, required) — 与 `sid` 配对的密钥：Account SID 对应的 Account Auth Token，或 API Key SID 对应的 API Key Secret
    - `account_auth_token` (string, optional) — Twilio 账户身份验证令牌。导入 API Key 时验证入站 webhook 签名所必需。
    - `agent_id` (string, optional) — 要分配此电话号码的智能体 ID
    - `enable_sms` (boolean, optional, default: true) — 将入站 SMS 路由至 ElevenLabs。默认开启；对于不支持 SMS 的号码，设为 false 可跳过 SMS 配置。
    - `region_config` (RegionConfigRequest, optional) — Twilio 其他区域配置。
    - `supports_inbound` (boolean, optional, default: true, deprecated) — 此字段已弃用，将在未来移除。此电话号码是否支持呼入电话。
    - `supports_outbound` (boolean, optional, default: true, deprecated) — 此字段已弃用，将在未来移除。此电话号码是否支持呼出电话。
  - `provider`: `exotel`
    - `account_sid` (string, required) — Exotel 账户 SID
    - `api_key` (string, required) — Exotel API 密钥
    - `api_subdomain` (enum, required) — Exotel 区域专用 API 主机
      - Allowed values: `api.in.exotel.com`, `api.exotel.com`
    - `api_token` (string, required) — Exotel API 令牌
    - `app_id` (string, required) — 用于 Calls/connect 的 Exotel 小程序标识符
    - `label` (string, required) — 电话号码标签
    - `phone_number` (string, required) — 电话号码
    - `agent_id` (string, optional) — 要分配此电话号码的智能体 ID
    - `applet_url` (string, optional) — 可选的完整 applet URL 覆盖值。默认使用根据账户 SID 和应用 ID 生成的 Exotel start_voice URL。
    - `supports_inbound` (boolean, optional, default: true, deprecated) — 此字段已弃用，将在未来移除。此电话号码是否支持呼入电话。
    - `supports_outbound` (boolean, optional, default: true, deprecated) — 此字段已弃用，将在未来移除。此电话号码是否支持呼出电话。
  - `provider`: `sip_trunk`
    - `label` (string, required) — 电话号码标签
    - `phone_number` (string, required) — 电话号码
    - `agent_id` (string, optional) — 要分配此电话号码的智能体 ID
    - `inbound_trunk_config` (InboundSipTrunkConfigRequestModel, optional)
    - `outbound_trunk_config` (OutboundSipTrunkConfigRequestModel, optional)
    - `supports_inbound` (boolean, optional, default: true, deprecated) — 此字段已弃用，将在未来移除。此电话号码是否支持呼入电话。
    - `supports_outbound` (boolean, optional, default: true, deprecated) — 此字段已弃用，将在未来移除。此电话号码是否支持呼出电话。

## Response

### 200

成功响应

- `phone_number_id` (string, required) — 电话实体 ID

## Errors

### 422 Phone Numbers Create Request Unprocessable Entity Error

验证错误。

- `detail` (list of ValidationError, optional)

## Types

### RegionConfigRequest

- `region_id` (enum, required) — 区域 ID
  - Allowed values: `us1`, `ie1`, `au1`
- `token` (string, required) — Auth Token for this region
- `edge_location` (enum, required) — 此区域的边缘位置
  - Allowed values: `ashburn`, `dublin`, `frankfurt`, `sao-paulo`, `singapore`, `sydney`, `tokyo`, `umatilla`, `roaming`

### InboundSipTrunkConfigRequestModel

- `allowed_addresses` (list of string, optional) — 允许使用中继的 IP 地址列表。列表中的每项可以是单个 IP 地址，或表示 CIDR 块的无类别域间路由表示法。
- `allowed_numbers` (list of string, optional) — 允许使用中继的电话号码列表。
- `media_encryption` (enum, optional, default: allowed) — 是否加密媒体数据（数据层）。
  - Allowed values: `disabled`, `allowed`, `required`
- `credentials` (SipTrunkCredentialsRequestModel, optional) — 可选的摘要式身份验证凭据（用户名/密码）。
- `remote_domains` (list of string, optional) — 用于验证 TLS 证书的远程 SIP 服务器域名。
- `attributes_to_headers` (map from string to string, optional) — 用于 attributes_to_headers 的动态变量名称到请求头名称的映射

### OutboundSipTrunkConfigRequestModel

- `address` (string, required) — 发送 SIP INVITE 的主机名或 IP。
- `transport` (enum, optional, default: auto) — 用于 SIP 传输的协议（信令层）。
  - Allowed values: `auto`, `udp`, `tcp`, `tls`
- `media_encryption` (enum, optional, default: allowed) — 是否加密媒体数据（数据层）。
  - Allowed values: `disabled`, `allowed`, `required`
- `headers` (map from string to string, optional) — INVITE 请求的 SIP X-* 标头。这些标头会原样发送，可能有助于识别此通通话。
- `attributes_to_headers` (map from string to string, optional) — 用于 attributes_to_headers 的动态变量名称到请求头名称的映射
- `credentials` (SipTrunkCredentialsRequestModel, optional) — 可选的摘要式认证凭据（用户名/密码）。未提供时，默认使用 ACL 认证。
- `enabled_codecs` (list of enum, optional) — 应在外呼 SDP 中提供的媒体编解码器。为空时，将提供所有支持的编解码器。
  - Allowed values: `G722/8000`, `PCMU/8000`, `PCMA/8000`

### ValidationError

- `loc` (list of ValidationErrorLocItem, required)
- `msg` (string, required)
- `type` (string, required)

### SipTrunkCredentialsRequestModel

- `username` (string, required) — SIP 中继用户名
- `password` (string, optional) — SIP 中继密码：未指定则保持不变

### ValidationErrorLocItem

- string
- integer

## Examples

**Request**

```json
{
  "provider": "twilio",
  "label": "label",
  "phone_number": "phone_number",
  "sid": "sid",
  "token": "token"
}
```

**Response**

```json
{
  "phone_number_id": "phone_number_id"
}
```

**SDK Code**

```python
import requests

url = "https://api.elevenlabs.io/v1/convai/phone-numbers"

payload = {
    "provider": "twilio",
    "label": "label",
    "phone_number": "phone_number",
    "sid": "sid",
    "token": "token"
}
headers = {"Content-Type": "application/json"}

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

print(response.json())
```

```javascript
const url = 'https://api.elevenlabs.io/v1/convai/phone-numbers';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"provider":"twilio","label":"label","phone_number":"phone_number","sid":"sid","token":"token"}'
};

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

```go
package main

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

func main() {

	url := "https://api.elevenlabs.io/v1/convai/phone-numbers"

	payload := strings.NewReader("{\n  \"provider\": \"twilio\",\n  \"label\": \"label\",\n  \"phone_number\": \"phone_number\",\n  \"sid\": \"sid\",\n  \"token\": \"token\"\n}")

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

	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
require 'uri'
require 'net/http'

url = URI("https://api.elevenlabs.io/v1/convai/phone-numbers")

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

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"provider\": \"twilio\",\n  \"label\": \"label\",\n  \"phone_number\": \"phone_number\",\n  \"sid\": \"sid\",\n  \"token\": \"token\"\n}"

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

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

HttpResponse<String> response = Unirest.post("https://api.elevenlabs.io/v1/convai/phone-numbers")
  .header("Content-Type", "application/json")
  .body("{\n  \"provider\": \"twilio\",\n  \"label\": \"label\",\n  \"phone_number\": \"phone_number\",\n  \"sid\": \"sid\",\n  \"token\": \"token\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.elevenlabs.io/v1/convai/phone-numbers', [
  'body' => '{
  "provider": "twilio",
  "label": "label",
  "phone_number": "phone_number",
  "sid": "sid",
  "token": "token"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.elevenlabs.io/v1/convai/phone-numbers");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"provider\": \"twilio\",\n  \"label\": \"label\",\n  \"phone_number\": \"phone_number\",\n  \"sid\": \"sid\",\n  \"token\": \"token\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "provider": "twilio",
  "label": "label",
  "phone_number": "phone_number",
  "sid": "sid",
  "token": "token"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.elevenlabs.io/v1/convai/phone-numbers")! 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()
```