For chat / embeddings / images / STT / TTS, use the official `openai` npm package with `baseURL: 'https://api.aigateway.sh/v1'`. The `aigateway` package wraps the aggregator-native surface OpenAI doesn't model — long-running jobs, sub-account billing, evals, replays, signed file URLs, and webhook signature verification.
Node 18+. Zero runtime dependencies. ESM + CJS exports. Distribution name on npm is aigateway-js (the bare 'aigateway' name was unavailable).
pnpm add aigateway-js # or npm i aigateway-js
import { AIgateway } from "aigateway-js";
const client = new AIgateway({ apiKey: process.env.AIGATEWAY_API_KEY! });
const job = await client.jobs.createVideo({
prompt: "a sunset over mountains, cinematic",
model: "runwayml/gen-4",
duration: 5,
});
const done = await client.jobs.wait(job.id, { timeoutSeconds: 600 });
console.log(done.resultUrl);const acct = await client.subAccounts.create({
name: "acme-corp",
spendCapCents: 50_000,
rateLimitRpm: 300,
defaultTag: "acme",
});
console.log(acct.key);import { verifyWebhook } from "aigateway-js";
const ok = verifyWebhook({
secret: process.env.AIGATEWAY_WEBHOOK_SECRET!,
body: rawBody,
header: req.headers["x-gateway-signature"] as string,
});