-
Notifications
You must be signed in to change notification settings - Fork 52
[BOUNTY #573] Add Vercel AI Gateway as a Provider #746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zhaog100
wants to merge
2
commits into
Merit-Systems:master
Choose a base branch
from
zhaog100:feat/vercel-ai-gateway-provider
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/sdk/ts/scripts/update-vercel-ai-gateway-models.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Script to update Vercel AI Gateway models | ||
| // Usage: pnpm run update-models:vercel-ai-gateway | ||
|
|
||
| import { writeFileSync } from 'fs'; | ||
| import { SupportedModel } from '../src/supported-models/types'; | ||
|
|
||
| // TODO: Fetch models from Vercel AI Gateway API when available | ||
| // For now, models are manually maintained based on: | ||
| // https://vercel.com/ai-gateway/models | ||
| // https://vercel.com/docs/ai-gateway/pricing | ||
|
|
||
| const models: SupportedModel[] = [ | ||
| // OpenAI models via Vercel AI Gateway | ||
| { | ||
| model_id: 'gpt-4o', | ||
| input_cost_per_token: 0.0000025, | ||
| output_cost_per_token: 0.00001, | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
| // ... add more models as needed | ||
| ]; | ||
|
|
||
| console.log(`Found ${models.length} Vercel AI Gateway models`); | ||
| // writeFileSync(...) // Uncomment to auto-update the model file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { | ||
| createOpenAICompatible, | ||
| OpenAICompatibleProvider, | ||
| } from '@ai-sdk/openai-compatible'; | ||
|
|
||
| import { ROUTER_BASE_URL } from 'config'; | ||
| import { EchoConfig } from '../types'; | ||
| import { validateAppId } from '../utils/validation'; | ||
| import { echoFetch } from './index'; | ||
|
|
||
| /** | ||
| * Creates a Vercel AI Gateway provider for the AI SDK. | ||
| * | ||
| * Vercel AI Gateway provides a unified API that proxies requests to | ||
| * underlying AI providers (OpenAI, Anthropic, Google, etc.) with | ||
| * built-in observability, rate limiting, and caching. | ||
| * | ||
| * @see https://vercel.com/docs/ai-gateway | ||
| * @see https://sdk.vercel.ai/providers/ai-sdk-providers/vercel | ||
| */ | ||
| export function createEchoVercelAIGateway( | ||
| { appId, baseRouterUrl = ROUTER_BASE_URL }: EchoConfig, | ||
| getTokenFn: (appId: string) => Promise<string | null>, | ||
| onInsufficientFunds?: () => void, | ||
| options?: { | ||
| /** Custom gateway base URL. Defaults to the Echo router. */ | ||
| gatewayBaseURL?: string; | ||
| } | ||
| ): OpenAICompatibleProvider { | ||
| validateAppId(appId, 'createEchoVercelAIGateway'); | ||
|
|
||
| return createOpenAICompatible({ | ||
| name: 'vercel-ai-gateway', | ||
| baseURL: options?.gatewayBaseURL ?? baseRouterUrl, | ||
| headers: { | ||
| 'x-echo-app-id': appId, | ||
| }, | ||
| fetch: echoFetch( | ||
| fetch, | ||
| async () => await getTokenFn(appId), | ||
| onInsufficientFunds | ||
| ), | ||
| }); | ||
| } | ||
166 changes: 166 additions & 0 deletions
166
packages/sdk/ts/src/supported-models/chat/vercel-ai-gateway.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| import { SupportedModel } from '../types'; | ||
|
|
||
| // Vercel AI Gateway model IDs | ||
| // Vercel AI Gateway acts as a proxy - it routes requests to underlying providers | ||
| // (OpenAI, Anthropic, Google, Groq, etc.) so pricing matches the upstream provider. | ||
| // Pricing sourced from: https://vercel.com/docs/ai-gateway/pricing | ||
| // Model list sourced from: https://vercel.com/ai-gateway/models | ||
| // Last updated: 2026-03-20 | ||
|
|
||
| export type VercelAIGatewayModel = | ||
| | 'gpt-4o' | ||
| | 'gpt-4o-mini' | ||
| | 'gpt-4.1' | ||
| | 'gpt-4.1-mini' | ||
| | 'gpt-4.1-nano' | ||
| | 'gpt-5' | ||
| | 'gpt-5-mini' | ||
| | 'gpt-5-nano' | ||
| | 'o3-mini' | ||
| | 'o4-mini' | ||
| | 'claude-sonnet-4-20250514' | ||
| | 'claude-haiku-4-20250414' | ||
| | 'gemini-2.5-pro' | ||
| | 'gemini-2.5-flash' | ||
| | 'deepseek-r1' | ||
| | 'deepseek-chat' | ||
| | 'llama-3.1-8b-instant' | ||
| | 'llama-3.3-70b-versatile' | ||
| | 'mistral-large-latest' | ||
| | 'qwen/qwen3-32b'; | ||
|
|
||
| export const VercelAIGatewayModels: SupportedModel[] = [ | ||
| // === OpenAI models via Vercel AI Gateway === | ||
| { | ||
| model_id: 'gpt-4o', | ||
| input_cost_per_token: 0.0000025, // $2.50 per 1M tokens | ||
| output_cost_per_token: 0.00001, // $10.00 per 1M tokens | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
| { | ||
| model_id: 'gpt-4o-mini', | ||
| input_cost_per_token: 0.00000015, // $0.15 per 1M tokens | ||
| output_cost_per_token: 0.0000006, // $0.60 per 1M tokens | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
| { | ||
| model_id: 'gpt-4.1', | ||
| input_cost_per_token: 0.000002, // $2.00 per 1M tokens | ||
| output_cost_per_token: 0.000008, // $8.00 per 1M tokens | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
| { | ||
| model_id: 'gpt-4.1-mini', | ||
| input_cost_per_token: 0.0000004, // $0.40 per 1M tokens | ||
| output_cost_per_token: 0.0000016, // $1.60 per 1M tokens | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
| { | ||
| model_id: 'gpt-4.1-nano', | ||
| input_cost_per_token: 0.0000001, // $0.10 per 1M tokens | ||
| output_cost_per_token: 0.0000004, // $0.40 per 1M tokens | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
| { | ||
| model_id: 'gpt-5', | ||
| input_cost_per_token: 0.0000025, // $2.50 per 1M tokens | ||
| output_cost_per_token: 0.000015, // $15.00 per 1M tokens | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
| { | ||
| model_id: 'gpt-5-mini', | ||
| input_cost_per_token: 0.0000005, // $0.50 per 1M tokens | ||
| output_cost_per_token: 0.000003, // $3.00 per 1M tokens | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
| { | ||
| model_id: 'gpt-5-nano', | ||
| input_cost_per_token: 0.00000005, // $0.05 per 1M tokens | ||
| output_cost_per_token: 0.00000025, // $0.25 per 1M tokens | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
| { | ||
| model_id: 'o3-mini', | ||
| input_cost_per_token: 0.0000011, // $1.10 per 1M tokens | ||
| output_cost_per_token: 0.0000044, // $4.40 per 1M tokens | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
| { | ||
| model_id: 'o4-mini', | ||
| input_cost_per_token: 0.0000011, // $1.10 per 1M tokens | ||
| output_cost_per_token: 0.0000044, // $4.40 per 1M tokens | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
|
|
||
| // === Anthropic models via Vercel AI Gateway === | ||
| { | ||
| model_id: 'claude-sonnet-4-20250514', | ||
| input_cost_per_token: 0.000003, // $3.00 per 1M tokens | ||
| output_cost_per_token: 0.000015, // $15.00 per 1M tokens | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
| { | ||
| model_id: 'claude-haiku-4-20250414', | ||
| input_cost_per_token: 0.0000008, // $0.80 per 1M tokens | ||
| output_cost_per_token: 0.000004, // $4.00 per 1M tokens | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
|
|
||
| // === Google models via Vercel AI Gateway === | ||
| { | ||
| model_id: 'gemini-2.5-pro', | ||
| input_cost_per_token: 0.00000125, // $1.25 per 1M tokens | ||
| output_cost_per_token: 0.00001, // $10.00 per 1M tokens | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
| { | ||
| model_id: 'gemini-2.5-flash', | ||
| input_cost_per_token: 0.00000015, // $0.15 per 1M tokens | ||
| output_cost_per_token: 0.0000006, // $0.60 per 1M tokens | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
|
|
||
| // === DeepSeek models via Vercel AI Gateway === | ||
| { | ||
| model_id: 'deepseek-r1', | ||
| input_cost_per_token: 0.00000055, // $0.55 per 1M tokens | ||
| output_cost_per_token: 0.00000219, // $2.19 per 1M tokens | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
| { | ||
| model_id: 'deepseek-chat', | ||
| input_cost_per_token: 0.00000014, // $0.14 per 1M tokens | ||
| output_cost_per_token: 0.00000028, // $0.28 per 1M tokens | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
|
|
||
| // === Groq models via Vercel AI Gateway === | ||
| { | ||
| model_id: 'llama-3.1-8b-instant', | ||
| input_cost_per_token: 0.00000005, // $0.05 per 1M tokens | ||
| output_cost_per_token: 0.00000008, // $0.08 per 1M tokens | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
| { | ||
| model_id: 'llama-3.3-70b-versatile', | ||
| input_cost_per_token: 0.00000059, // $0.59 per 1M tokens | ||
| output_cost_per_token: 0.00000079, // $0.79 per 1M tokens | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
|
|
||
| // === Mistral models via Vercel AI Gateway === | ||
| { | ||
| model_id: 'mistral-large-latest', | ||
| input_cost_per_token: 0.000002, // $2.00 per 1M tokens | ||
| output_cost_per_token: 0.000006, // $6.00 per 1M tokens | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
|
|
||
| // === Qwen models via Vercel AI Gateway === | ||
| { | ||
| model_id: 'qwen/qwen3-32b', | ||
| input_cost_per_token: 0.00000029, // $0.29 per 1M tokens | ||
| output_cost_per_token: 0.00000059, // $0.59 per 1M tokens | ||
| provider: 'Vercel AI Gateway', | ||
| }, | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.