Skip to main content

aigateway-py (Python)

Official Python SDK for AIgateway — one OpenAI-compatible API for every frontier and open-weight model, every modality.

Distribution name on PyPI is aigateway-py (the bare aigateway name was unavailable). The import path is still aigateway.

For chat, embeddings, images, STT, TTS, moderation — just use the openai package with base_url='https://api.aigateway.sh/v1'. AIgateway is drop-in.

This SDK covers the aggregator-native surface OpenAI doesn't model:

  • Async jobs — text-to-video, music, 3D with a typed jobs.wait(id) helper
  • Sub-accounts — one scoped key per end customer with spend caps
  • Evals — pick the winning model from a candidate set; alias as eval:<run_id>
  • Replays — re-run any past request on a new model and diff the output
  • Signed file URLs — share job results without handing out the gateway key
  • Webhook signature verification — HMAC-SHA256 with verify_webhook()

Install

pip install aigateway-py

You still import aigateway in code — the PyPI distribution name and the import name are intentionally different.

Requires Python 3.9+.

Quickstart

import os
from aigateway import AIgateway

client = AIgateway(api_key=os.environ["AIGATEWAY_API_KEY"])

# 1. Submit a video job with a webhook.
job = client.jobs.create_video(
    prompt="a sunset over mountains, cinematic",
    model="runwayml/gen-4",
    duration=5,
    webhook_url="https://yourapp.com/hooks/aigateway",
)

# 2. Or poll until it's done:
done = client.jobs.wait(job.id, timeout_seconds=600)
print(done.result_url)

# 3. Mint a shareable signed URL:
signed = client.files.signed_url(job.id, "video.mp4", expires_in=3600)
print(signed["url"])

Async

import asyncio
from aigateway import AsyncAIgateway

async def main():
    async with AsyncAIgateway(api_key="sk-aig-...") as client:
        job = await client.jobs.create_video(prompt="a cat")
        result = await client.jobs.wait(job.id)
        print(result.result_url)

asyncio.run(main())

Webhook verification

from aigateway import verify_webhook
from fastapi import FastAPI, Request, HTTPException

app = FastAPI()
SECRET = os.environ["AIGATEWAY_WEBHOOK_SECRET"]

@app.post("/hooks/aigateway")
async def hook(request: Request):
    raw = await request.body()
    sig = request.headers.get("x-gateway-signature", "")
    if not verify_webhook(SECRET, raw, sig):
        raise HTTPException(status_code=401)
    # ... handle the payload

Fetch your webhook secret with client.webhook_secret.get() or rotate it with client.webhook_secret.rotate().

Source, issues, examples

License

MIT © AIgateway

Metadata

Release files for aigateway-py 0.1.3

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

Source distribution (sdist)

Source distribution for aigateway-py 0.1.3
File Size Uploaded Provenance
aigateway_py-0.1.3.tar.gz 8.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aigateway-py 0.1.3
File Interpreter ABI Platform
aigateway_py-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 16.3 kB

Release files / aigateway_py-0.1.3.tar.gz

Download URL aigateway_py-0.1.3.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6b12c9f6f0d854043a5ad2e61e69a6aa9b44a04c76338a5cea37e9c381ad9366
BLAKE2b-256 checksum
How to use checksums
97e225e91443f1eed1b2d92c119f749780eeb2ac8634cf7363ad1e6509a99498
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / aigateway_py-0.1.3-py3-none-any.whl

Download URL aigateway_py-0.1.3-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ece7bea6668ffe7c5b13e09de2f2fa1b59406b196be7abe3c09ec3b522165193
BLAKE2b-256 checksum
How to use checksums
236ebe2829f3afff5cbd0b9b979f16caed6c6dc4c47de3dd61ab588cc71dae21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Security for aigateway-py 0.1.3

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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