AI voice agents are transforming how businesses handle phone calls — but to make or receive real calls, your AI agent needs a real phone number. This guide walks through exactly how to connect a virtual number to an AI voice agent using the PBXme API.
What Is an AI Voice Agent?
An AI voice agent is a software system that can handle phone calls autonomously — answering questions, qualifying leads, booking appointments, or routing callers — without a human operator. Built on large language models (LLMs) like GPT-4 or Claude, these agents listen to speech, generate responses, and speak back using text-to-speech (TTS) engines. Popular platforms for building AI voice agents include Bland.ai, Vapi, Retell AI, and custom stacks combining Twilio or PBXme with Deepgram, ElevenLabs, and an LLM backend. The missing piece for most AI agents is a real phone number — a local number in the right country that callers can actually dial. That’s where the PBXme API comes in.
What You Need Before You Start
- A PBXme account with API access
- A virtual phone number provisioned in your target country
- An AI voice agent platform (Bland.ai, Vapi, Retell, or custom)
- A public HTTPS webhook URL to receive inbound call events
Step 1 — Provision a Virtual Number via the PBXme API
First, authenticate with the PBXme API and retrieve a number for your target country. The API uses a two-step auth flow: login to get an account token, then use that token for all subsequent calls. Authenticate:
import requests
auth_response = requests.post("https://newsip.pbxme.com/api/login", json={
"email": "your@email.com",
"password": "yourpassword"
})
token = auth_response.json()["account_token"]
headers = {"Authorization": f"Bearer {token}"}Browse available numbers:
numbers = requests.get(
"https://newsip.pbxme.com/api/dids/available",
params={"country_code": "US"},
headers=headers
)
print(numbers.json())Once you’ve selected a number, provision it to your account via the portal or API. Your number is now live and ready to receive calls.
Step 2 — Configure a Webhook to Receive Inbound Calls
When someone dials your virtual number, PBXme needs to know where to send the call. For an AI agent, you point the number’s forwarding destination to your agent’s webhook endpoint — the URL your AI platform exposes to handle incoming calls. In your PBXme portal:
- Go to your number’s settings
- Set the forwarding type to SIP or Webhook depending on your platform
- Enter your AI agent’s inbound call URL (e.g.
https://your-agent.example.com/inbound) - Save the configuration
For platforms like Vapi or Retell AI, your webhook URL is provided in their dashboard after you create an agent. For custom builds, you’ll stand up a small HTTP server to receive the call event.
Step 3 — Handle the Inbound Call in Your AI Agent
When a call arrives, your webhook receives a POST request with call metadata. Your agent then:
- Answers the call and begins listening
- Converts speech to text (STT) using Deepgram, Whisper, or your platform’s built-in engine
- Passes the transcript to your LLM with a system prompt defining the agent’s role
- Converts the LLM’s text response back to speech (TTS) using ElevenLabs, Azure, or similar
- Streams the audio back to the caller
Here is a minimal Python example using Flask to receive the inbound webhook and respond:
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route("/inbound", methods=["POST"])
def handle_inbound_call():
call_data = request.get_json()
caller_number = call_data.get("from")
# Hand off to your AI agent logic here
response = {
"action": "speak",
"text": "Hello, you've reached our AI assistant. How can I help you today?"
}
return jsonify(response)
if __name__ == "__main__":
app.run(port=5000)Step 4 — Make Outbound Calls from Your AI Agent
AI agents that handle outbound calls — sales dialers, appointment reminders, follow-up bots — need to place calls programmatically. With PBXme, your agent can initiate a call via the API and connect the answered call to your agent’s audio stream.
outbound = requests.post(
"https://newsip.pbxme.com/api/calls/originate",
headers=headers,
json={
"from": "+12025550100", # your PBXme virtual number
"to": "+14155550199", # destination number
"webhook_url": "https://your-agent.example.com/outbound"
}
)
print(outbound.json())Compatible AI Voice Agent Platforms
| Platform | Best For | PBXme Integration |
|---|---|---|
| Bland.ai | Sales & outbound calling | Via SIP trunk or number import |
| Vapi | Inbound & outbound agents | Via SIP or webhook |
| Retell AI | Customer service bots | Via SIP trunk |
| Custom LLM stack | Full control over logic | Via REST API + webhooks |
Why Use PBXme for AI Agent Phone Numbers?
- 145+ countries — get a local number in any market your agent needs to operate in
- Full REST API — provision numbers, configure routing, and handle webhooks programmatically
- Free PBX included — IVR, call queues, and routing logic available without extra cost
- SIP trunk support — connect your agent via SIP for low-latency audio
- Instant setup — numbers are live immediately, no paperwork or waiting period
Frequently Asked Questions
Can I use PBXme numbers with AI voice agent platforms like Vapi or Bland.ai?
Yes. PBXme virtual numbers can be connected to AI voice agent platforms via SIP trunk or webhook. Your agent receives inbound calls and can place outbound calls using the PBXme API and your provisioned number.
Do I need a SIP phone to use the PBXme API?
No. The PBXme REST API handles call control programmatically. For AI agents, you typically connect via SIP or webhook — no physical phone required.
Can my AI agent have a local phone number in multiple countries?
Yes. PBXme offers virtual numbers in 145+ countries. You can provision a separate local number for each market your AI agent operates in, all managed from one account.
Is there a sandbox to test the API before going live?
Yes. PBXme provides an API sandbox environment where you can test call flows and number provisioning without affecting live traffic.
What programming languages does the PBXme API support?
The PBXme API is a standard REST API that works with any language capable of making HTTP requests — Python, Node.js, PHP, Ruby, Go, and more.
