Skip to main content

Vercel AI Gateway Plugin

The Vercel AI Gateway plugin provides AI capabilities through the Vercel AI Gateway, a unified API endpoint that gives access to models from multiple providers (OpenAI, Anthropic, Google, and others) through a single OpenAI-compatible interface.

Source: packages/plugins/vercel-ai-gateway/src/vercel-ai-gateway.plugin.ts

Overview

PropertyValue
Plugin IDvercel-ai-gateway
Categoryai-provider
Capabilitiesai-provider
Version1.0.0
Configuration Modehybrid
Auto-enableNo
System pluginNo
Visibilitypublic
Dependencies@langchain/openai, @langchain/core

The plugin extends BaseAiProvider from @ever-works/plugin/abstract and uses AiOperations from @ever-works/plugin/ai for all AI operations. It communicates through the OpenAI-compatible protocol, which means it works with any model accessible through the Vercel AI Gateway.

Architecture

OpenAI-Compatible Protocol

The Vercel AI Gateway exposes an OpenAI-compatible API at https://ai-gateway.vercel.sh/v1. This means:

  • All requests use the same format as OpenAI API calls.
  • Model names use the provider/model format (e.g., openai/gpt-4o, anthropic/claude-sonnet-4-20250514).
  • The plugin delegates to AiOperations with providerType: 'openai'.

Configuration

Settings Schema

SettingTypeRequiredDefaultScopeDescription
apiKeystringYes--userVercel AI Gateway API key (secret)
defaultModelstringYesopenai/gpt-5.1globalModel for all AI tasks (unless tier-specific)
simpleModelstringNoopenai/gpt-5-nanoglobalModel for tags, short descriptions
mediumModelstringNoopenai/gpt-4oglobalModel for listings, summaries
complexModelstringNoopenai/gpt-5.1globalModel for full page generation
baseUrlstringNohttps://ai-gateway.vercel.sh/v1--Custom endpoint (hidden)
temperaturenumberNo0.7--Generation temperature 0--2 (hidden)
maxTokensnumberNo4096--Max response tokens (hidden)

Environment Variables

VariableDescription
PLUGIN_VERCEL_AI_GATEWAY_API_KEYAPI key fallback
PLUGIN_VERCEL_AI_GATEWAY_DEFAULT_MODELDefault model fallback
PLUGIN_VERCEL_AI_GATEWAY_SIMPLE_MODELSimple model fallback
PLUGIN_VERCEL_AI_GATEWAY_MEDIUM_MODELMedium model fallback
PLUGIN_VERCEL_AI_GATEWAY_COMPLEX_MODELComplex model fallback
PLUGIN_VERCEL_AI_GATEWAY_BASE_URLBase URL fallback

Three-Tier Model System

The plugin supports assigning different models to different task complexities, optimizing cost and quality:

TierSettingHandlesRecommended Model
SimplesimpleModelTags, short descriptions, classificationsFast, inexpensive model
StandardmediumModelListings, summaries, content reformattingBalanced model
ComplexcomplexModelFull page generation, multi-step analysisMost capable model

If a tier-specific model is not set, the defaultModel is used as a fallback for all tasks.

AI Capabilities

Supported Features

CapabilitySupported
Chat completionYes
StreamingYes
Structured outputYes
Tool callingYes
VisionNo
EmbeddingsYes
Max context length128,000 tokens

Chat Completion

async createChatCompletion(options: ChatCompletionOptions): Promise<ChatCompletionResponse>

Sends a chat completion request through the AI Gateway. Settings are resolved from the plugin configuration and merged with per-call options.

Streaming Chat Completion

async *createStreamingChatCompletion(options: ChatCompletionOptions): AsyncIterable<ChatCompletionChunk>

Provides streaming responses for real-time output. The AI facade can use this for progressive content generation in the pipeline.

Embeddings

async createEmbedding(options: EmbeddingOptions): Promise<EmbeddingResponse>

Generates text embeddings using the configured model. Embeddings are used for semantic similarity and search operations.

Model Listing

async listModels(settings?: PluginSettings): Promise<readonly AiModel[]>

Lists available models from the AI Gateway. This powers the model selection UI in the admin panel.

Connection Testing

async isAvailable(settings?: PluginSettings): Promise<boolean>

Tests whether the AI Gateway is reachable and the API key is valid by making a test connection.

Comparison with Other AI Providers

FeatureVercel AI GatewayOpenAIAnthropicGoogle AI
Multi-provider accessYes (unified)OpenAI onlyAnthropic onlyGoogle only
API compatibilityOpenAI-compatibleNativeNativeNative
Model switchingChange model nameChange providerChange providerChange provider
Account managementSingle API keyPer-providerPer-providerPer-provider
Vercel integrationNativeManualManualManual
Vision supportDepends on modelYesYesYes
Custom endpointsYes (baseUrl)YesNoNo

The Vercel AI Gateway is ideal when you want to experiment with models from different providers without managing separate accounts. Dedicated provider plugins (OpenAI, Anthropic, Google) offer deeper integration with provider-specific features like vision and advanced tool calling.

Settings Resolution

The plugin overrides the resolveConfig() method from BaseAiProvider to merge settings:

protected override resolveConfig(settings?: PluginSettings): Partial<AiOperationsConfig> {
const config: Partial<AiOperationsConfig> = {};
if (s.apiKey && typeof s.apiKey === 'string') config.apiKey = s.apiKey;
if (s.baseUrl && typeof s.baseUrl === 'string') config.baseURL = s.baseUrl;
if (typeof s.temperature === 'number') config.temperature = s.temperature;
if (typeof s.maxTokens === 'number') config.maxTokens = s.maxTokens;
return config;
}

This ensures that only valid, typed values are forwarded to the underlying LangChain operations.

Getting Started

  1. Set up Vercel AI Gateway in your Vercel dashboard.
  2. Generate an API key from the AI Gateway settings.
  3. Enable the Vercel AI Gateway plugin.
  4. Enter the API key in the plugin settings.
  5. Select models for each complexity tier using the provider/model format.
  6. Set this plugin as the active AI provider for your work.

Troubleshooting

IssueCauseSolution
"Plugin not loaded"onLoad not calledRestart the plugin or server
Connection test failsInvalid API key or network issueVerify the key and check connectivity to ai-gateway.vercel.sh
Model not foundInvalid model name formatUse provider/model format (e.g., openai/gpt-4o)
Slow responsesLarge maxTokens or complex modelReduce maxTokens or use a faster model for simple tasks
Unexpected model behaviorTemperature too highLower temperature toward 0 for more consistent output