Skip to content
AZRouter.dev

Guides

Vercel AI SDK

Use AZRouter as an OpenAI-compatible provider in the AI SDK.

Tested: ai 7.0.142, @ai-sdk/openai-compatible 3.0.70 (Node 24), 2026-10-16

AZRouter plugs into the AI SDK through its OpenAI-compatible provider.

Shell
npm install ai @ai-sdk/openai-compatible
TypeScript
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateText } from "ai";

const azrouter = createOpenAICompatible({
  name: "azrouter",
  baseURL: "https://api.azrouter.dev/v1",
  apiKey: process.env.AZROUTER_API_KEY,
  includeUsage: true,
});

const { text, usage } = await generateText({
  model: azrouter("qwen/qwen3.8-flash"),
  prompt: "Reply with exactly: Hello from AZRouter",
  maxOutputTokens: 200,
});
console.log(text);
console.log(usage);

Save it as hello.mts and run npx tsx hello.mts: top-level await needs an ES module.

Streaming

TypeScript
import { streamText } from "ai";

const result = streamText({
  model: azrouter("qwen/qwen3.8-flash"),
  prompt: "Reply with exactly: Hello from AZRouter",
  maxOutputTokens: 200,
});
for await (const delta of result.textStream) {
  process.stdout.write(delta);
}
console.log();

includeUsage: true asks the gateway for the usage chunk at the end of a stream, so await result.usage has token counts.