gateway in chat.config.ts to choose which backend your app talks to.
Available Gateways
| Gateway | Models | Auth | Image Generation | Best For |
|---|---|---|---|---|
| Vercel AI Gateway (default) | 120+ | AI_GATEWAY_API_KEY or auto OIDC | Dedicated image models | Vercel deployments |
| OpenRouter | Hundreds | OPENROUTER_API_KEY | Via multimodal models | Broadest model access |
| OpenAI | OpenAI only | OPENAI_API_KEY | gpt-image-1 and others | Direct OpenAI access |
| OpenAI Compatible | Varies | OPENAI_COMPATIBLE_API_KEY (optional) | Provider-dependent | Ollama, LM Studio, vLLM, Azure |
Choosing a Gateway
- Vercel AI Gateway is the default. It aggregates 120+ models from multiple providers behind a single key. Zero-config on Vercel deployments.
- OpenRouter gives access to hundreds of models with per-token pricing. Good when you want the widest selection or models not on Vercel’s gateway.
- OpenAI connects directly to the OpenAI API. Use this when you only need OpenAI models and want type-safe model IDs.
- OpenAI Compatible works with any endpoint that follows the OpenAI API format (local servers, self-hosted inference, or cloud services).
Configuration
Set the gateway inchat.config.ts:
chat.config.ts
The
gateway field lives inside the ai key and defaults to "vercel" when omitted.How Model Fetching Works
Every gateway implementsfetchModels() which returns the list of available models. The app calls this at runtime and caches the result for 1 hour.
When no API key is available, the app falls back to a static snapshot in models.generated.ts. Refresh this snapshot periodically:
Snapshot Gateway Validation
The snapshot file records which gateway generated it via ageneratedForGateway export. When you run bun check-env, it compares this value against config.ai.gateway and warns if they don’t match:
- Build time:
bun check-envprints the warning shown above. - Runtime: each gateway checks
generatedForGatewaybefore using the fallback. If it doesn’t match, the fallback is skipped and an empty model list is returned instead of stale model IDs.
Related
- Multi-Model Support for model configuration and visibility
- Custom Gateway for implementing your own gateway
- Auto-Updating Models for the fetching and caching pattern