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 accepts a single live connection per slug and answers a second one with agent-in-use.

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.1

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.1
File Size Uploaded Provenance Actions
asterisk_ai_agent_gateway_sdk-0.3.1.tar.gz 8.1 kB With provenance Details for asterisk_ai_agent_gateway_sdk-0.3.1.tar.gz

Built distribution (wheel)

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

Total release size: 17.5 kB

Release files / asterisk_ai_agent_gateway_sdk-0.3.1.tar.gz

Download URL asterisk_ai_agent_gateway_sdk-0.3.1.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
88ed3854be7aeb77541c5a5e0dcc624f26d3f6dcb2a003ad4192712d25852a28
BLAKE2b-256 checksum
How to use checksums
95fc27cfaedec60a79272bdc67c333e9116d3488f10931258b845794ac413fbc
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 Sep 29, 2026.

Transparency log

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

Download URL asterisk_ai_agent_gateway_sdk-0.3.1-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fcd40a6ebe6e250af3bbbd3d559e2354a3a4436e15133564f274c8e2fffe78c6
BLAKE2b-256 checksum
How to use checksums
9e15c8a6e0d14ed919c480372c04f53d28dd8ccc2ecfc2954652cc4f9b4b87f6
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 Sep 29, 2026.

Transparency log

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

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.1.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 Sep 29, 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