Python SDK
The official AgentPhone Python library provides convenient access to the AgentPhone API with both synchronous and asynchronous clients. These examples target published agentphone==0.20.1. Python method names and snake_case arguments differ from the TypeScript SDK and REST JSON fields.
Installation
For async support:
Set AGENTPHONE_API_KEY in the server process before running examples.
Quick start
Async usage
The quick start buys a number and places a real call. Read pricing and outbound calling requirements and use a recipient you control. The SDK does not expose every REST field; use authenticated HTTP for unsupported operations and sub-account headers.
Resources
Agents
Per-agent webhooks
Numbers
Messages
Contacts
Conversations
Calls
Webhooks (project-level)
Usage
Error handling
Webhook verification
Each delivery is signed over "{timestamp}.{raw_body}". The signature arrives in the X-Webhook-Signature header and the timestamp in X-Webhook-Timestamp, so pass both along with the raw body and your secret. Both helpers also enforce a 5-minute replay window by default (tolerance=300; pass tolerance=None to skip it). Requires agentphone >= 0.17.0.
The typed event model in 0.20.1 includes a subset of the webhook fields. For data.messageId, group context, attachments, reactions, or contact sharing, call verify_webhook() first and then parse the raw JSON so those fields remain available. Use data.group.groupId when replying to a group; do not route a group response to the individual sender.
Flask example
Save the signing secret returned when you configure the webhook, then run export AGENTPHONE_WEBHOOK_SECRET="YOUR_WEBHOOK_SIGNING_SECRET" in the server environment before starting this app. This is separate from AGENTPHONE_API_KEY.

