curl --request POST \
--url https://api.pyai.com/v1/telephony/numbers \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--data '
{
"phone_number": "+14155550123",
"agent_id": "<string>",
"provisioning_mode": "automated"
}
'import requests
url = "https://api.pyai.com/v1/telephony/numbers"
payload = {
"phone_number": "+14155550123",
"agent_id": "<string>",
"provisioning_mode": "automated"
}
headers = {
"Idempotency-Key": "<idempotency-key>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Idempotency-Key': '<idempotency-key>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
phone_number: '+14155550123',
agent_id: '<string>',
provisioning_mode: 'automated'
})
};
fetch('https://api.pyai.com/v1/telephony/numbers', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.pyai.com/v1/telephony/numbers",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'phone_number' => '+14155550123',
'agent_id' => '<string>',
'provisioning_mode' => 'automated'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"Idempotency-Key: <idempotency-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.pyai.com/v1/telephony/numbers"
payload := strings.NewReader("{\n \"phone_number\": \"+14155550123\",\n \"agent_id\": \"<string>\",\n \"provisioning_mode\": \"automated\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.pyai.com/v1/telephony/numbers")
.header("Idempotency-Key", "<idempotency-key>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"phone_number\": \"+14155550123\",\n \"agent_id\": \"<string>\",\n \"provisioning_mode\": \"automated\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.pyai.com/v1/telephony/numbers")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"phone_number\": \"+14155550123\",\n \"agent_id\": \"<string>\",\n \"provisioning_mode\": \"automated\"\n}"
response = http.request(request)
puts response.read_body{
"object": "telephony.number",
"id": "pn_...",
"phone_number": "+14155550123",
"country": "US",
"area_code": "415",
"capabilities": {
"voice": true,
"sms": true
},
"agent_id": "<string>",
"recording": true,
"monthly_cost_cents": 123,
"status": "active",
"created_at": 123,
"released_at": 123
}{
"title": "<string>",
"status": 123,
"type": "<string>",
"detail": "<string>",
"request_id": "<string>"
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "invalid_request_error",
"param": "<string>"
}
}Provision (buy) a number
Buy a specific available number and attach it to your org, optionally binding it to an agent_id for inbound routing. When search reports assisted ordering, support may pre-order the number and you can explicitly set provisioning_mode=adopt_preowned; this never places a new order. Recording runs in PyAI’s media bridge. Connected minutes bill on telephony.minutes ($0.01/min). Requires the telephony:manage scope.
curl --request POST \
--url https://api.pyai.com/v1/telephony/numbers \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--data '
{
"phone_number": "+14155550123",
"agent_id": "<string>",
"provisioning_mode": "automated"
}
'import requests
url = "https://api.pyai.com/v1/telephony/numbers"
payload = {
"phone_number": "+14155550123",
"agent_id": "<string>",
"provisioning_mode": "automated"
}
headers = {
"Idempotency-Key": "<idempotency-key>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Idempotency-Key': '<idempotency-key>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
phone_number: '+14155550123',
agent_id: '<string>',
provisioning_mode: 'automated'
})
};
fetch('https://api.pyai.com/v1/telephony/numbers', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.pyai.com/v1/telephony/numbers",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'phone_number' => '+14155550123',
'agent_id' => '<string>',
'provisioning_mode' => 'automated'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"Idempotency-Key: <idempotency-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.pyai.com/v1/telephony/numbers"
payload := strings.NewReader("{\n \"phone_number\": \"+14155550123\",\n \"agent_id\": \"<string>\",\n \"provisioning_mode\": \"automated\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.pyai.com/v1/telephony/numbers")
.header("Idempotency-Key", "<idempotency-key>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"phone_number\": \"+14155550123\",\n \"agent_id\": \"<string>\",\n \"provisioning_mode\": \"automated\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.pyai.com/v1/telephony/numbers")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"phone_number\": \"+14155550123\",\n \"agent_id\": \"<string>\",\n \"provisioning_mode\": \"automated\"\n}"
response = http.request(request)
puts response.read_body{
"object": "telephony.number",
"id": "pn_...",
"phone_number": "+14155550123",
"country": "US",
"area_code": "415",
"capabilities": {
"voice": true,
"sms": true
},
"agent_id": "<string>",
"recording": true,
"monthly_cost_cents": 123,
"status": "active",
"created_at": 123,
"released_at": 123
}{
"title": "<string>",
"status": 123,
"type": "<string>",
"detail": "<string>",
"request_id": "<string>"
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "invalid_request_error",
"param": "<string>"
}
}Authorizations
Use Authorization: Bearer pyai_live_... (or pyai_test_...).
Headers
Required safe retry key. Reusing the key with an identical body replays the original 201 response (no second number purchase); reusing it with a different body returns 409 idempotency_conflict.
255Body
A US, Canada, or India number (E.164) from the available-numbers search.
"+14155550123"
Optional agent to route inbound calls to.
Use adopt_preowned only for a number already ordered through assisted provisioning. It never buys a number.
automated, adopt_preowned Response
Provisioned
"telephony.number"
"pn_..."
E.164.
"+14155550123"
"US"
"415"
Show child attributes
Show child attributes
Agent that answers inbound calls to this number.
Whether PyAI recording is enabled for the number.
active, released Unix ms.
Unix ms.