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.2.0.tar.gz (10.9 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.2.0-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

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

Hashes for agentphone-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8eee9c38afdfcaaf3a92f17d38455413c4d6b537484af3f139fa8945a40c97e1
MD5 fb206097dd5a687e9017d3e6147e76d4
BLAKE2b-256 e66cebf5f20e17d35a47dc607d944c5b609f90b89d8a03c603ef78cd86399da7

See more details on using hashes here.

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

Hashes for agentphone-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f5ec7127ec62fa61c08f005c1a6beade078128596287031ab2fcda7b22b2d80
MD5 0cbd16ff7386a73c3e30ed50dfbe5783
BLAKE2b-256 d0754f51ff22830af5fdca5c7bcadc2e38da0839617c96ea5222daa956a88741

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