AgentPhone Python SDK — give your AI agents phone numbers, SMS, and voice calls
Project description
AgentPhone Python SDK
Official Python SDK for AgentPhone — give your AI agents real phone numbers, SMS, and voice calls.
Installation
pip install agentphone
For async support:
pip install agentphone[async]
Quickstart
from agentphone import AgentPhone
client = AgentPhone(api_key="your-api-key")
# Create an agent and buy a number
agent = client.agents.create(name="My Agent")
number = client.numbers.buy(country="US", agent_id=agent.id)
# Make an AI conversation call — no webhook needed
call = client.calls.make_conversation(
agent_id=agent.id,
to_number="+14155551234",
topic="You are a friendly assistant. Ask about their day.",
initial_greeting="Hey! This is an AI calling from AgentPhone.",
)
print(call.status) # registered
Async
from agentphone import AsyncAgentPhone
async with AsyncAgentPhone(api_key="your-api-key") as client:
numbers = await client.numbers.list()
call = await client.calls.make_conversation(...)
Resources
| Resource | Methods |
|---|---|
client.numbers |
list(), buy(), release(), get_messages() |
client.agents |
list(), create(), get(), attach_number() |
client.calls |
list(), get(), make(), make_conversation() |
client.conversations |
list(), get() |
client.webhooks |
get(), set(), delete(), list_deliveries(), test() |
Webhook Verification
from agentphone import construct_event, WebhookVerificationError
@app.post("/webhook")
async def handle(request: Request):
body = await request.body()
sig = request.headers["X-Webhook-Signature"]
try:
event = construct_event(body, sig, secret="whsec_...")
except WebhookVerificationError:
return Response(status_code=403)
if event.event == "agent.message":
print(f"SMS from {event.data.from_number}: {event.data.message}")
Error Handling
from agentphone import AgentPhoneError, AuthenticationError, NotFoundError
try:
call = client.calls.get("bad-id")
except NotFoundError:
print("Call not found")
except AgentPhoneError as e:
print(f"API error {e.status}: {e.message}")
Publishing to PyPI
-
Install build tools (one-time):
pip install hatch twine
-
Build the package:
hatch buildThis creates a
dist/folder with the.tar.gzand.whlfiles. -
Upload to PyPI:
twine upload dist/*
You'll be prompted for your PyPI credentials. To use an API token instead:
twine upload dist/* -u __token__ -p pypi-your-token-here
-
Publishing a new version — bump the version in
pyproject.tomlfirst:version = "0.1.1"
Then rebuild and upload:
hatch build && twine upload dist/*
Requirements
- Python 3.9+
requests(sync client)httpx(async client, optional)
Links
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentphone-0.2.0.tar.gz.
File metadata
- Download URL: agentphone-0.2.0.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8eee9c38afdfcaaf3a92f17d38455413c4d6b537484af3f139fa8945a40c97e1
|
|
| MD5 |
fb206097dd5a687e9017d3e6147e76d4
|
|
| BLAKE2b-256 |
e66cebf5f20e17d35a47dc607d944c5b609f90b89d8a03c603ef78cd86399da7
|
File details
Details for the file agentphone-0.2.0-py3-none-any.whl.
File metadata
- Download URL: agentphone-0.2.0-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f5ec7127ec62fa61c08f005c1a6beade078128596287031ab2fcda7b22b2d80
|
|
| MD5 |
0cbd16ff7386a73c3e30ed50dfbe5783
|
|
| BLAKE2b-256 |
d0754f51ff22830af5fdca5c7bcadc2e38da0839617c96ea5222daa956a88741
|