Skip to main content

Asterisk AI Agent Gateway — Python SDK

Realtime protocol v1 client. Exchanges your API key for a five-minute token, registers the agent slug, heartbeats, reconnects with a fresh token, and hides the 16-byte binary audio envelope.

pip install asterisk-ai-agent-gateway-sdk
import asyncio, os
from asterisk_ai_gateway import GatewayClient

client = GatewayClient(
    gateway_url=os.environ["GATEWAY_URL"],
    api_key=os.environ["GATEWAY_API_KEY"],   # keep in a secret store
    agent_slug="support-agent",
)

async def on_event(event):
    if event["type"] == "call.started":
        await client.send_dtmf(event["call_id"], "1")   # needs calls:dtmf

async def on_audio(call_id, pcm):        # PCM s16le, mono, rate from call.started
    await client.send_audio(call_id, pcm)

asyncio.run(client.run(on_event=on_event, on_audio=on_audio))

Run one client per agent_slug: the gateway keeps one live connection per slug, and the most recent registration wins. A replaced client receives close code 4409, raises SessionSupersededError, and stops without reconnecting; the gateway hangs up the calls it owned.

GatewayClient.run() and stream() retry authentication failures three times after the initial attempt (four attempts total). The shared budget covers token exchange HTTP 401/403, WebSocket handshake 401/403, and close code 4401. Each retry exchanges the key for a fresh token after 1, 2, then 4 seconds, capped by max_backoff; the budget resets only after session.ready. Set reconnect=False to disable retries; close() or task cancellation stops pending retries. After the budget, AuthenticationError ends the flow, and a revoked key cannot be revived. Direct realtime_token() is a single request and does not retry itself. Other transport failures reconnect with exponential backoff up to max_backoff. Authentication and transport failures share that backoff, so preceding transport failures can increase the next authentication retry's delay.

See examples/echo_agent.py and docs/partner/integration-guide.html.

Metadata

Release files for asterisk-ai-agent-gateway-sdk 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asterisk-ai-agent-gateway-sdk 0.3.2
File Size Uploaded Provenance Actions
asterisk_ai_agent_gateway_sdk-0.3.2.tar.gz 9.7 kB With provenance Details for asterisk_ai_agent_gateway_sdk-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for asterisk-ai-agent-gateway-sdk 0.3.2
File Interpreter ABI Platform Actions
asterisk_ai_agent_gateway_sdk-0.3.2-py3-none-any.whl Python 3 none any Details for asterisk_ai_agent_gateway_sdk-0.3.2-py3-none-any.whl

Total release size: 19.5 kB

Release files / asterisk_ai_agent_gateway_sdk-0.3.2.tar.gz

Download URL asterisk_ai_agent_gateway_sdk-0.3.2.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
932719d3b6eaf0d7abc94928c06ee38e54785a4a290875daa407fc87efd9c57a
BLAKE2b-256 checksum
How to use checksums
f4ea7d0c89e389e69d916c077a868b5351402d89d3f4ba6fbbf64074dc8a7911
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.

Transparency log

Release files / asterisk_ai_agent_gateway_sdk-0.3.2-py3-none-any.whl

Download URL asterisk_ai_agent_gateway_sdk-0.3.2-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a1bf3da6fd57fb1ff8d6237d7d0a7cfd94a9e1af9da30452c35d476409e61fe1
BLAKE2b-256 checksum
How to use checksums
fd7d971914a8432207ce4f14f6e648707abf8a613f56b0f88285c180d921ed6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.

Transparency log

Security for asterisk-ai-agent-gateway-sdk 0.3.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for asterisk_ai_agent_gateway_sdk-0.3.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page