integrations/sdk/OpenAI SDK
OA

OpenAI SDK + AIgateway

Drop-in. Change one line, gain 100+ models.

AIgateway speaks the OpenAI API verbatim — chat, embeddings, images, audio, moderations. Point the official OpenAI SDK at our base URL and every endpoint, every parameter, every streaming SSE shape works exactly the same.

OpenAI SDK homepage →
Setup

Three steps or fewer.

STEP 01

Install both SDKs

aigateway-py/js for our aggregator primitives (sub-accounts, evals, replays, jobs, webhook verify). openai for chat — drop-in compat per our own SDK's guidance.

pip install aigateway-py openai
# or
pnpm add aigateway-js openai
STEP 02

Set the base URL

Use the AIgateway endpoint and your AIgateway key. Nothing else changes for chat.

# pip install aigateway-py openai
from openai import OpenAI

client = OpenAI(
    base_url="https://api.aigateway.sh/v1",
    api_key="sk-aig-...",
)

resp = client.chat.completions.create(
    model="anthropic/claude-opus-4.7",   # or any of 100+ models
    messages=[{"role": "user", "content": "hello"}],
    stream=True,
)
STEP 03

TypeScript

Same swap on the JS side.

// pnpm add aigateway-js openai
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.aigateway.sh/v1",
  apiKey: process.env.AIGATEWAY_API_KEY,
});

const stream = await client.chat.completions.create({
  model: "moonshot/kimi-k2.6",
  messages: [{ role: "user", content: "hello" }],
  stream: true,
});
STEP 04

Use aigateway-py / aigateway-js for primitives

Sub-accounts, evals, replays, async video/music jobs, webhook signature verification.

from aigateway import AIgateway
client = AIgateway(api_key="sk-aig-...")

# Scoped key per customer
sub = client.sub_accounts.create(name="acme", spend_cap_cents=50_000)

# Async video job
job = client.jobs.create_video(model="runwayml/gen-4", prompt="...", duration=5)
done = client.jobs.wait(job.id)
Notes
  • Model IDs use the provider/model slug — anthropic/claude-opus-4.7, openai/gpt-5.4, moonshot/kimi-k2.6.
  • Vision, tool calling, JSON mode, streaming, and prompt caching all pass through unchanged.
  • aigateway-js declares `openai` as a peer dependency — the two packages are designed to pair.
More integrations

Same key. Every other tool.