Migrate from Vercel AI Gateway
Keep your Vercel AI SDK code, add response caching, detailed analytics, and smart routing. One provider for all models.
Published · Updated
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.
Vercel AI Gateway and PassingRight both pass provider token prices through with zero markup. The differences are portability and what sits on separate meters: Vercel's bring-your-own-keys needs the paid tier, purchased credits expire after a year, and custom reporting, team-wide allowlists, zero data retention, and trace drains each bill on their own. PassingRight is open source, self-hostable, charges a flat 5% on credits or 0% with your own keys, and needs no Vercel team account. See the full comparison.
Zero-Diff Migration: 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:
1import { createGateway } from "@ai-sdk/gateway";2
3globalThis.AI_SDK_DEFAULT_PROVIDER = createGateway({4 baseURL: "https://api.passingright.io/v4/ai",5 apiKey: process.env.LLM_GATEWAY_API_KEY,6});1import { createGateway } from "@ai-sdk/gateway";2
3globalThis.AI_SDK_DEFAULT_PROVIDER = createGateway({4 baseURL: "https://api.passingright.io/v4/ai",5 apiKey: process.env.LLM_GATEWAY_API_KEY,6});No import changes, no model-string changes. See the AI SDK gateway protocol docs. Prefer the explicit provider migration below when you want the gateway's own model IDs and options surfaced as first-class provider settings.
Quick Migration
Swap your provider imports—your AI SDK code stays the same:
1- import { openai } from "@ai-sdk/openai";2- import { anthropic } from "@ai-sdk/anthropic";3+ import { generateText } from "ai";4+ import { createLLMGateway } from "@llmgateway/ai-sdk-provider";5
6+ const llmgateway = createLLMGateway({7+ apiKey: process.env.LLM_GATEWAY_API_KEY8+ });9
10const { text } = await generateText({11- model: openai("gpt-6-astra"),12+ model: llmgateway("gpt-6-astra"),13 prompt: "Hello!"14});1- import { openai } from "@ai-sdk/openai";2- import { anthropic } from "@ai-sdk/anthropic";3+ import { generateText } from "ai";4+ import { createLLMGateway } from "@llmgateway/ai-sdk-provider";5
6+ const llmgateway = createLLMGateway({7+ apiKey: process.env.LLM_GATEWAY_API_KEY8+ });9
10const { text } = await generateText({11- model: openai("gpt-6-astra"),12+ model: llmgateway("gpt-6-astra"),13 prompt: "Hello!"14});The key difference: one provider, one API key, all models—with caching and analytics built in.
Migration Steps
1. Get Your PassingRight API Key
Sign up at passingright.io/signup and create an API key from your dashboard.
2. Install the PassingRight AI SDK Provider
Install the native PassingRight provider for the Vercel AI SDK:
1pnpm add @llmgateway/ai-sdk-provider1pnpm add @llmgateway/ai-sdk-providerThis package provides full compatibility with the Vercel AI SDK and supports all PassingRight features.
3. Update Your Code
Basic Text Generation
1// Before (Vercel AI Gateway with native providers)2import { openai } from "@ai-sdk/openai";3import { anthropic } from "@ai-sdk/anthropic";4import { generateText } from "ai";5
6const { text: openaiText } = await generateText({7 model: openai("gpt-6-astra"),8 prompt: "Hello!",9});10
11const { text: claudeText } = await generateText({12 model: anthropic("claude-sonnet-5"),13 prompt: "Hello!",14});15
16// After (PassingRight - single provider for all models)17import { createLLMGateway } from "@llmgateway/ai-sdk-provider";18import { generateText } from "ai";19
20const llmgateway = createLLMGateway({21 apiKey: process.env.LLM_GATEWAY_API_KEY,22});23
24const { text: openaiText } = await generateText({25 model: llmgateway("gpt-6-astra"),26 prompt: "Hello!",27});28
29const { text: claudeText } = await generateText({30 model: llmgateway("anthropic/claude-sonnet-5"),31 prompt: "Hello!",32});1// Before (Vercel AI Gateway with native providers)2import { openai } from "@ai-sdk/openai";3import { anthropic } from "@ai-sdk/anthropic";4import { generateText } from "ai";5
6const { text: openaiText } = await generateText({7 model: openai("gpt-6-astra"),8 prompt: "Hello!",9});10
11const { text: claudeText } = await generateText({12 model: anthropic("claude-sonnet-5"),13 prompt: "Hello!",14});15
16// After (PassingRight - single provider for all models)17import { createLLMGateway } from "@llmgateway/ai-sdk-provider";18import { generateText } from "ai";19
20const llmgateway = createLLMGateway({21 apiKey: process.env.LLM_GATEWAY_API_KEY,22});23
24const { text: openaiText } = await generateText({25 model: llmgateway("gpt-6-astra"),26 prompt: "Hello!",27});28
29const { text: claudeText } = await generateText({30 model: llmgateway("anthropic/claude-sonnet-5"),31 prompt: "Hello!",32});Streaming Responses
1import { createLLMGateway } from "@llmgateway/ai-sdk-provider";2import { streamText } from "ai";3
4const llmgateway = createLLMGateway({5 apiKey: process.env.LLM_GATEWAY_API_KEY,6});7
8const { textStream } = await streamText({9 model: llmgateway("anthropic/claude-sonnet-5"),10 prompt: "Write a poem about coding",11});12
13for await (const text of textStream) {14 process.stdout.write(text);15}1import { createLLMGateway } from "@llmgateway/ai-sdk-provider";2import { streamText } from "ai";3
4const llmgateway = createLLMGateway({5 apiKey: process.env.LLM_GATEWAY_API_KEY,6});7
8const { textStream } = await streamText({9 model: llmgateway("anthropic/claude-sonnet-5"),10 prompt: "Write a poem about coding",11});12
13for await (const text of textStream) {14 process.stdout.write(text);15}Using in Next.js API Routes
1// app/api/chat/route.ts2import { createLLMGateway } from "@llmgateway/ai-sdk-provider";3import { streamText } from "ai";4
5const llmgateway = createLLMGateway({6 apiKey: process.env.LLM_GATEWAY_API_KEY,7});8
9export async function POST(req: Request) {10 const { messages } = await req.json();11
12 const result = await streamText({13 model: llmgateway("gpt-6-astra"),14 messages,15 });16
17 return result.toUIMessageStreamResponse();18}1// app/api/chat/route.ts2import { createLLMGateway } from "@llmgateway/ai-sdk-provider";3import { streamText } from "ai";4
5const llmgateway = createLLMGateway({6 apiKey: process.env.LLM_GATEWAY_API_KEY,7});8
9export async function POST(req: Request) {10 const { messages } = await req.json();11
12 const result = await streamText({13 model: llmgateway("gpt-6-astra"),14 messages,15 });16
17 return result.toUIMessageStreamResponse();18}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:
1import { createOpenAI } from "@ai-sdk/openai";2import { generateText } from "ai";3
4const llmgateway = createOpenAI({5 baseURL: "https://api.passingright.io/v1",6 apiKey: process.env.LLM_GATEWAY_API_KEY,7});8
9const { text } = await generateText({10 model: llmgateway("gpt-6-astra"),11 prompt: "Hello!",12});1import { createOpenAI } from "@ai-sdk/openai";2import { generateText } from "ai";3
4const llmgateway = createOpenAI({5 baseURL: "https://api.passingright.io/v1",6 apiKey: process.env.LLM_GATEWAY_API_KEY,7});8
9const { text } = await generateText({10 model: llmgateway("gpt-6-astra"),11 prompt: "Hello!",12});4. Update Environment Variables
1# Remove individual provider keys (optional - can keep as backup)2# OPENAI_API_KEY=sk-...3# ANTHROPIC_API_KEY=sk-ant-...4
5# Add PassingRight key6export LLM_GATEWAY_API_KEY=llmgtwy_your_key_here1# Remove individual provider keys (optional - can keep as backup)2# OPENAI_API_KEY=sk-...3# ANTHROPIC_API_KEY=sk-ant-...4
5# Add PassingRight key6export 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:
1gpt-6-astra2claude-sonnet-53gemini-3.1-pro-preview1gpt-6-astra2claude-sonnet-53gemini-3.1-pro-previewProvider-Prefixed Model IDs - Routes to a specific provider with automatic failover if uptime drops below 90%:
1openai/gpt-6-astra2anthropic/claude-sonnet-53google-ai-studio/gemini-3.1-pro-preview1openai/gpt-6-astra2anthropic/claude-sonnet-53google-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") |
anthropic("claude-sonnet-5") | llmgateway("claude-sonnet-5") |
google("gemini-3.1-pro-preview") | llmgateway("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:
1import { createLLMGateway } from "@llmgateway/ai-sdk-provider";2import { generateText, tool } from "ai";3import { z } from "zod";4
5const llmgateway = createLLMGateway({6 apiKey: process.env.LLM_GATEWAY_API_KEY,7});8
9const { text, toolResults } = await generateText({10 model: llmgateway("gpt-6-astra"),11 tools: {12 weather: tool({13 description: "Get the weather for a location",14 inputSchema: z.object({15 location: z.string(),16 }),17 execute: async ({ location }) => {18 return { temperature: 72, condition: "sunny" };19 },20 }),21 },22 prompt: "What's the weather in San Francisco?",23});1import { createLLMGateway } from "@llmgateway/ai-sdk-provider";2import { generateText, tool } from "ai";3import { z } from "zod";4
5const llmgateway = createLLMGateway({6 apiKey: process.env.LLM_GATEWAY_API_KEY,7});8
9const { text, toolResults } = await generateText({10 model: llmgateway("gpt-6-astra"),11 tools: {12 weather: tool({13 description: "Get the weather for a location",14 inputSchema: z.object({15 location: z.string(),16 }),17 execute: async ({ location }) => {18 return { temperature: 72, condition: "sunny" };19 },20 }),21 },22 prompt: "What's the weather in San Francisco?",23});Self-Hosting PassingRight
If you prefer self-hosting, PassingRight is available under AGPLv3:
1git clone https://github.com/theopenco/llmgateway2cd llmgateway3pnpm install4pnpm run setup5pnpm dev1git clone https://github.com/theopenco/llmgateway2cd llmgateway3pnpm install4pnpm run setup5pnpm devThis gives you the same managed experience with full control over your infrastructure.
Need Help?
- Browse available models at passingright.io/models
- Read the API documentation
- Contact support at support@passingright.io