For chat / embeddings / images / STT / TTS, use the `openai` package with `base_url='https://api.aigateway.sh/v1'` — AIgateway is drop-in. The `aigateway` package is the typed wrapper for the parts OpenAI doesn't model: long-running jobs, sub-account billing, evals, replays, signed file URLs, and webhook verification.
Python 3.9+. Pure-Python, single dependency on httpx. PyPI distribution name is aigateway-py; the import path is aigateway.
pip install aigateway-py
Long-running modalities (video, music, 3D) return a Job. Wait inline or attach a webhook_url and forget about it.
import os
from aigateway import AIgateway
client = AIgateway(api_key=os.environ["AIGATEWAY_API_KEY"])
job = client.jobs.create_video(
prompt="a sunset over mountains, cinematic",
model="runwayml/gen-4",
duration=5,
)
done = client.jobs.wait(job.id, timeout_seconds=600)
print(done.result_url)One call returns a scoped key with its own spend cap and analytics.
acct = client.sub_accounts.create(
name="acme-corp",
spend_cap_cents=50_000,
rate_limit_rpm=300,
default_tag="acme",
)
print(acct["key"]) # hand to the customerHMAC-SHA256 over `t.body`. Helper raises if the signature is bad or stale.
from aigateway import verify_webhook
ok = verify_webhook(
secret=os.environ["AIGATEWAY_WEBHOOK_SECRET"],
body=raw_request_body,
header=request.headers["x-gateway-signature"],
)Same surface, async/await flavored.
import asyncio
from aigateway import AsyncAIgateway
async def main():
async with AsyncAIgateway(api_key=os.environ["AIGATEWAY_API_KEY"]) as c:
job = await c.jobs.create_video(prompt="a cat")
done = await c.jobs.wait(job.id)
print(done.result_url)
asyncio.run(main())