Migrate from Vercel AI Gateway
Keep your Vercel AI SDK code, add response caching, detailed analytics, and smart routing. One provider for all models.
Let your AI agent do the migration
Copy this prompt into Claude Code, Cursor, or any coding agent — it reads our docs and handles the migration from Vercel AI Gateway for you.
Quick Migration
Swap your provider imports—your AI SDK code stays the same:
- import { openai } from "@ai-sdk/openai";
- import { anthropic } from "@ai-sdk/anthropic";
+ import { generateText } from "ai";
+ import { createLLMGateway } from "@llmgateway/ai-sdk-provider";
+ const llmgateway = createLLMGateway({
+ apiKey: process.env.LLM_GATEWAY_API_KEY
+ });
const { text } = await generateText({
- model: openai("gpt-6-astra"),
+ model: llmgateway("gpt-6-astra"),
prompt: "Hello!"
});The key difference: one provider, one API key, all models—with caching and analytics built in.
Zero-diff alternative: repoint the base URL
If your app passes bare model strings (model: "anthropic/claude-sonnet-5"), it resolves them through @ai-sdk/gateway — the AI SDK's default provider. PassingRight implements that protocol, so you can keep every line of application code and repoint the provider instead:
import { createGateway } from "@ai-sdk/gateway";
globalThis.AI_SDK_DEFAULT_PROVIDER = createGateway({
baseURL: "https://api.passingright.io/v4/ai",
apiKey: process.env.LLM_GATEWAY_API_KEY,
});No import changes, no model-string changes, and provider-native web search keeps returning source-url parts. See AI SDK Gateway protocol.
Prefer the explicit @llmgateway/ai-sdk-provider migration below when you want the gateway's own model IDs and options surfaced as first-class provider settings.
Migration Steps
Get Your PassingRight API Key
Sign up at passingright.io/signup and create an API key from your dashboard.
Install the PassingRight AI SDK Provider
Install the native PassingRight provider for the Vercel AI SDK:
pnpm add @llmgateway/ai-sdk-providerThis package provides full compatibility with the Vercel AI SDK and supports all PassingRight features.
Update Your Code
Basic Text Generation
// Before (Vercel AI Gateway with native providers)
import { openai } from "@ai-sdk/openai";
import { anthropic } from "@ai-sdk/anthropic";
import { generateText } from "ai";
const { text: openaiText } = await generateText({
model: openai("gpt-6-astra"),
prompt: "Hello!",
});
const { text: claudeText } = await generateText({
model: anthropic("claude-sonnet-5"),
prompt: "Hello!",
});
// After (PassingRight - single provider for all models)
import { createLLMGateway } from "@llmgateway/ai-sdk-provider";
import { generateText } from "ai";
const llmgateway = createLLMGateway({
apiKey: process.env.LLM_GATEWAY_API_KEY,
});
const { text: openaiText } = await generateText({
model: llmgateway("openai/gpt-6-astra"),
prompt: "Hello!",
});
const { text: claudeText } = await generateText({
model: llmgateway("anthropic/claude-sonnet-5"),
prompt: "Hello!",
});Streaming Responses
import { createLLMGateway } from "@llmgateway/ai-sdk-provider";
import { streamText } from "ai";
const llmgateway = createLLMGateway({
apiKey: process.env.LLM_GATEWAY_API_KEY,
});
const { textStream } = await streamText({
model: llmgateway("anthropic/claude-sonnet-5"),
prompt: "Write a poem about coding",
});
for await (const text of textStream) {
process.stdout.write(text);
}Using in Next.js API Routes
// app/api/chat/route.ts
import { createLLMGateway } from "@llmgateway/ai-sdk-provider";
import { streamText } from "ai";
const llmgateway = createLLMGateway({
apiKey: process.env.LLM_GATEWAY_API_KEY,
});
export async function POST(req: Request) {
const { messages } = await req.json();
const result = await streamText({
model: llmgateway("openai/gpt-6-astra"),
messages,
});
return result.toUIMessageStreamResponse();
}Alternative: Using OpenAI SDK Adapter
If you prefer not to install a new package, you can use @ai-sdk/openai with a custom base URL:
import { createOpenAI } from "@ai-sdk/openai";
import { generateText } from "ai";
const llmgateway = createOpenAI({
baseURL: "https://api.passingright.io/v1",
apiKey: process.env.LLM_GATEWAY_API_KEY,
});
const { text } = await generateText({
model: llmgateway("openai/gpt-6-astra"),
prompt: "Hello!",
});Update Environment Variables
# Remove individual provider keys (optional - can keep as backup)
# OPENAI_API_KEY=sk-...
# ANTHROPIC_API_KEY=sk-ant-...
# Add PassingRight key
export LLM_GATEWAY_API_KEY=llmgtwy_your_key_hereModel Name Format
PassingRight supports two model ID formats:
Canonical Model IDs (without provider prefix) - Uses smart routing to automatically select the best provider based on uptime, throughput, price, and latency:
gpt-6-astra
claude-sonnet-5
gemini-3.1-pro-previewProvider-Prefixed Model IDs - Routes to a specific provider with automatic failover if uptime drops below 90%:
openai/gpt-6-astra
anthropic/claude-sonnet-5
google-ai-studio/gemini-3.1-pro-previewFor more details on routing behavior, see the routing documentation.
Model Mapping Examples
| Vercel AI SDK | PassingRight |
|---|---|
openai("gpt-6-astra") | llmgateway("gpt-6-astra") or llmgateway("openai/gpt-6-astra") |
anthropic("claude-sonnet-5") | llmgateway("claude-sonnet-5") or llmgateway("anthropic/claude-sonnet-5") |
google("gemini-3.1-pro-preview") | llmgateway("gemini-3.1-pro-preview") or llmgateway("google-ai-studio/gemini-3.1-pro-preview") |
Check the models page for the full list of available models.
Tool Calling
PassingRight supports tool calling through the AI SDK:
import { createLLMGateway } from "@llmgateway/ai-sdk-provider";
import { generateText, tool } from "ai";
import { z } from "zod";
const llmgateway = createLLMGateway({
apiKey: process.env.LLM_GATEWAY_API_KEY,
});
const { text, toolResults } = await generateText({
model: llmgateway("openai/gpt-6-astra"),
tools: {
weather: tool({
description: "Get the weather for a location",
inputSchema: z.object({
location: z.string(),
}),
execute: async ({ location }) => {
return { temperature: 72, condition: "sunny" };
},
}),
},
prompt: "What's the weather in San Francisco?",
});Self-Hosting PassingRight
If you prefer self-hosting, PassingRight is available under AGPLv3:
git clone https://github.com/theopenco/llmgateway
cd llmgateway
pnpm install
pnpm run setup
pnpm devThis gives you the same managed experience with full control over your infrastructure.
How is this guide?
Last updated on