Skip to main content

Official Python SDK for AIgateway — async jobs, sub-accounts, evals, replays, webhook verification. Install as aigateway-py; import as aigateway.

Project description

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().

Examples + bug reports

Working examples: github.com/Rakesh1002/ai-gateway-examples. Bug reports + feature requests: support@aigateway.sh · X: @buildwithrakesh · LinkedIn: in/rakeshroushan1002.

License

MIT © AIgateway

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

aigateway_py-0.1.2.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aigateway_py-0.1.2-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file aigateway_py-0.1.2.tar.gz.

File metadata

  • Download URL: aigateway_py-0.1.2.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for aigateway_py-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d7f932f745bf44f465649a583c468cf3ecac2bb1a7cb4a4be268a6a747fe4d8a
MD5 27bcc522d7db8d02743af20cbb04c74f
BLAKE2b-256 13a4e8432403a1a2b0612a1084fa90ff824984a1badd9191181248af116d8bbb

See more details on using hashes here.

File details

Details for the file aigateway_py-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: aigateway_py-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for aigateway_py-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e6bdfc8895f4738c43653cbdacddb974ec50a16147c13f4b7fc44f23d47fc9d6
MD5 f0d3302f389889337239ffa33e06ffee
BLAKE2b-256 dfdcd1a9c6ae302e85d7db0db1c5e8bdc997ad464bdd527fdb17a741ed75cc4d

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