Skip to main content

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

  1. Install build tools (one-time):

    pip install hatch twine
    
  2. Build the package:

    hatch build
    

    This creates a dist/ folder with the .tar.gz and .whl files.

  3. 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
    
  4. Publishing a new version — bump the version in pyproject.toml first:

    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

agentphone-0.1.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentphone-0.1.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file agentphone-0.1.0.tar.gz.

File metadata

  • Download URL: agentphone-0.1.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for agentphone-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8d4b335b244f93df4d65853f1c5162f2b56526e6d5d862fd0045dc0b2a3a66f7
MD5 b636dbb8555e85b88ac480cd8ffde280
BLAKE2b-256 33405f9156144c2c260fcfa96921df803573f75b7ae9fb5975595f744ed6e7bc

See more details on using hashes here.

File details

Details for the file agentphone-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: agentphone-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for agentphone-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 052c7654a13e839961efb8d3a485a9f5fb4f5fe4f80947bdd4907fcc8cb4c612
MD5 57eb42a73bc88afce63ec9884641d3ce
BLAKE2b-256 873edb128fae3be99b2366d3bb26112f88fce1878058fc39dc1cef134109fd6b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page