Explore an AI Gateway example
Learn how AI Gateway works in this TanStack Start chat app example, which automatically proxies your requests to a supported AI provider with built-in security, usage analytics, and rate limiting.
For the complete Netlify documentation index, see llms.txt. Markdown versions of any documentation page are available by appending .md to its URL. Use popular AI models in your code, without needing to manage API keys or external accounts.
The AI Gateway service simplifies technical and operational concerns when using AI inference in your code, by removing the need to:
Explore an AI Gateway example
Learn how AI Gateway works in this TanStack Start chat app example, which automatically proxies your requests to a supported AI provider with built-in security, usage analytics, and rate limiting.
For a video overview of how the AI Gateway works with a fun demo project, check out our AI Gateway gameshow demo.
Check out more examples of working projects that are powered with AI models in our AI Gateway examples docs.
By default, Netlify automatically sets the appropriate environment variables that AI client libraries typically use for configuration, in all Netlify compute contexts (e.g., Netlify Functions, Edge Functions, Preview Server, etc.).
These variables include:
These variables are picked up by the official client libraries of these providers, so no extra configuration is necessary - with the exception of the OpenRouter SDK, which needs the base URL passed explicitly. Alternatively, if you make AI calls via a provider's REST API, these values are easy to incorporate in your code.
When receiving a request from a client, the AI Gateway makes the call to the AI provider on your behalf. Then, it bills your Netlify account by converting the actual token usage in the request into credits, using your existing credit quota.
The AI Gateway does not store your prompts or model outputs. Learn more about Security and Privacy for AI features. To opt out, check your opt-out options.
When you develop server-side code with any web framework supported by Netlify (e.g., Astro; Tanstack Start; Next.js, Gatsby, Nuxt, etc.), your code is packaged in Netlify Functions and Edge Functions under the hood, as part of the build process.
Therefore, the above environment variables are available as when explicitly using Netlify compute primitives, without any further settings required.
For a quickstart, check out our Quickstart for AI Gateway.
The AI Gateway is available by default in all credit-based plans, unless:
For full information on which environment variables are automatically set, and how to control this behavior, see here.
If you're using any of the following libraries, little to no configuration is required. The AI Gateway automatically provides the necessary environment variables that these libraries use:
import Anthropic from '@anthropic-ai/sdk';
const anthropic = new Anthropic();// No API key or base URL configuration needed - automatically uses:// process.env.ANTHROPIC_API_KEY and process.env.ANTHROPIC_BASE_URL
async function callAnthropic() { const message = await anthropic.messages.create({ model: 'claude-sonnet-4-5-20250929', max_tokens: 1024, messages: [{ role: 'user', content: 'Hello!' }] }); return message;}Library: Anthropic TypeScript API Library
import OpenAI from 'openai';
const openai = new OpenAI();// No API key or base URL configuration needed - automatically uses:// process.env.OPENAI_API_KEY and process.env.OPENAI_BASE_URL
async function callOpenAI() { const completion = await openai.chat.completions.create({ // Models available through OpenRouter can also be used here, with no extra // configuration - just pass a model name in the OpenRouter notation, // e.g. 'deepseek/deepseek-v4-flash-0731' model: 'gpt-5', messages: [{ role: 'user', content: 'Hello!' }] }); return completion;}import { GoogleGenAI } from '@google/genai';
const genAI = new GoogleGenAI({});// No API key or base URL configuration needed - automatically uses:// process.env.GEMINI_API_KEY and process.env.GOOGLE_GEMINI_BASE_URL
async function callGemini() { const result = await genAI.models.generateContent({ model: 'gemini-2.5-pro', contents: 'Hello!' }); return result;}import { OpenRouter } from '@openrouter/sdk';
const openRouter = new OpenRouter();// No API key or base URL configuration needed - automatically uses:// process.env.OPENROUTER_API_KEY and process.env.OPENROUTER_BASE_URL// Requires @openrouter/sdk 1.2.43 or later. Earlier versions ignore// OPENROUTER_BASE_URL and call openrouter.ai directly, which rejects the// Netlify-issued key with "401 Missing Authentication header".
async function callOpenRouter() { const result = await openRouter.chat.send({ chatRequest: { model: 'x-ai/grok-4.5', messages: [{ role: 'user', content: 'Hello!' }] } }); return result;}Library: OpenRouter TypeScript SDK
Note that models available through OpenRouter can be used with either the OpenRouter SDK or the OpenAI SDK.
async function callAnthropic() { const ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY; const ANTHROPIC_BASE_URL = process.env.ANTHROPIC_BASE_URL;
const response = await fetch(`${ANTHROPIC_BASE_URL}/v1/messages`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': ANTHROPIC_API_KEY, 'anthropic-version': '2023-06-01' }, body: JSON.stringify({ model: 'claude-sonnet-4-5-20250929', max_tokens: 1024, messages: [{ role: 'user', content: 'Hello!' }] }) }); return await response.json();}async function callOpenAI() { const OPENAI_API_KEY = process.env.OPENAI_API_KEY; const OPENAI_BASE_URL = process.env.OPENAI_BASE_URL;
const response = await fetch(`${OPENAI_BASE_URL}/v1/chat/completions`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${OPENAI_API_KEY}` }, body: JSON.stringify({ model: 'gpt-5', messages: [{ role: 'user', content: 'Hello!' }] }) }); return await response.json();}async function callGemini() { const GEMINI_API_KEY = process.env.GEMINI_API_KEY; const GEMINI_BASE_URL = process.env.GOOGLE_GEMINI_BASE_URL;
const response = await fetch( `${GEMINI_BASE_URL}/v1beta/models/gemini-2.5-pro:generateContent`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-goog-api-key': GEMINI_API_KEY }, body: JSON.stringify({ contents: [{ parts: [{ text: 'Hello!' }] }] }) } ); return await response.json();}async function callOpenRouter() { const OPENROUTER_API_KEY = process.env.OPENROUTER_API_KEY; const OPENROUTER_BASE_URL = process.env.OPENROUTER_BASE_URL;
const response = await fetch(`${OPENROUTER_BASE_URL}/chat/completions`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${OPENROUTER_API_KEY}` }, body: JSON.stringify({ model: 'x-ai/grok-4.5', messages: [{ role: 'user', content: 'Hello!' }] }) }); return await response.json();}If you are using a client library that does not work out-of-the-box with the environment variables set for the AI Gateway, you need to manually pass the API key and base URL as arguments to the library.
This is similar to manually reading & passing variable values when using a provider's REST API. See Using official REST APIs above for the relevant variable names.
If you have already set an API key or base URL at the project or team level, Netlify will never override it.
When a Netlify Function or Edge Function is initialized, the following environment variables are set to the appropriate values for the AI Gateway:
OPENAI_API_KEY and OPENAI_BASE_URL - unless any of these is already set by you at the project or team level.ANTHROPIC_API_KEY and ANTHROPIC_BASE_URL - unless any of these is already set by you.GEMINI_API_KEY and GOOGLE_GEMINI_BASE_URL- unless any of these is already set by you, or if either GOOGLE_API_KEY or GOOGLE_VERTEX_BASE_URL are set.OPENROUTER_API_KEY and OPENROUTER_BASE_URL - unless any of these is already set by you.NETLIFY_AI_GATEWAY_KEY and NETLIFY_AI_GATEWAY_BASE_URL environment variables are always injected into the AI Gateway-supported runtimes. If you want to mix different setups with your own keys and Netlify's or you want to be explicit about using AI Gateway keys in your calls, use these env variables as they will never collide with other environment variables values.
To prevent any variables from being automatically set, you can disable AI Features.
Models are available through the AI Gateway in two ways.
Models from Anthropic, OpenAI, and Google Gemini are served directly by the AI Gateway, using each provider's own API. These are the models listed below, and they are not routed through OpenRouter.
| AI Provider | Model |
|---|---|
| Anthropic | claude-fable-5 |
| Anthropic | claude-haiku-4-5 |
| Anthropic | claude-haiku-4-5-20251001 |
| Anthropic | claude-opus-4-5 |
| Anthropic | claude-opus-4-5-20251101 |
| Anthropic | claude-opus-4-6 |
| Anthropic | claude-opus-4-7 |
| Anthropic | claude-opus-4-8 |
| Anthropic | claude-opus-5 |
| Anthropic | claude-sonnet-4-5 |
| Anthropic | claude-sonnet-4-5-20250929 |
| Anthropic | claude-sonnet-4-6 |
| Anthropic | claude-sonnet-5 |
| Gemini | gemini-2.5-flash |
| Gemini | gemini-2.5-flash-image |
| Gemini | gemini-2.5-flash-lite |
| Gemini | gemini-2.5-pro |
| Gemini | gemini-3-flash-preview |
| Gemini | gemini-3-pro-image |
| Gemini | gemini-3.1-flash-image |
| Gemini | gemini-3.1-flash-lite |
| Gemini | gemini-3.1-flash-lite-image |
| Gemini | gemini-3.1-pro-preview |
| Gemini | gemini-3.1-pro-preview-customtools |
| Gemini | gemini-3.5-flash |
| Gemini | gemini-3.5-flash-lite |
| Gemini | gemini-3.6-flash |
| Gemini | gemini-3.7-flash |
| Gemini | gemini-flash-latest |
| Gemini | gemini-flash-lite-latest |
| OpenAI | chat-latest |
| OpenAI | gpt-4.1 |
| OpenAI | gpt-4.1-mini |
| OpenAI | gpt-4.1-nano |
| OpenAI | gpt-4o |
| OpenAI | gpt-4o-mini |
| OpenAI | gpt-5 |
| OpenAI | gpt-5-2025-08-07 |
| OpenAI | gpt-5-mini |
| OpenAI | gpt-5-mini-2025-08-07 |
| OpenAI | gpt-5-nano |
| OpenAI | gpt-5-pro |
| OpenAI | gpt-5.1 |
| OpenAI | gpt-5.1-2025-11-13 |
| OpenAI | gpt-5.2 |
| OpenAI | gpt-5.2-2025-12-11 |
| OpenAI | gpt-5.2-pro |
| OpenAI | gpt-5.2-pro-2025-12-11 |
| OpenAI | gpt-5.3-codex |
| OpenAI | gpt-5.4 |
| OpenAI | gpt-5.4-2026-03-05 |
| OpenAI | gpt-5.4-mini |
| OpenAI | gpt-5.4-mini-2026-03-17 |
| OpenAI | gpt-5.4-nano |
| OpenAI | gpt-5.4-nano-2026-03-17 |
| OpenAI | gpt-5.4-pro |
| OpenAI | gpt-5.4-pro-2026-03-05 |
| OpenAI | gpt-5.5 |
| OpenAI | gpt-5.5-2026-04-23 |
| OpenAI | gpt-5.5-pro |
| OpenAI | gpt-5.5-pro-2026-04-23 |
| OpenAI | gpt-5.6-luna |
| OpenAI | gpt-5.6-sol |
| OpenAI | gpt-5.6-terra |
| OpenAI | o3 |
| OpenAI | o3-mini |
| OpenAI | o4-mini |
| Openrouter | allenai/olmo-3-32b-think |
| Openrouter | anthracite-org/magnum-v4-72b |
| Openrouter | arcee-ai/trinity-large-thinking |
| Openrouter | arcee-ai/virtuoso-large |
| Openrouter | baidu/ernie-4.5-vl-424b-a47b |
| Openrouter | bytedance-seed/seed-1.6 |
| Openrouter | bytedance-seed/seed-1.6-flash |
| Openrouter | bytedance-seed/seed-2-1-turbo |
| Openrouter | bytedance-seed/seed-2.0-code |
| Openrouter | bytedance-seed/seed-2.0-lite |
| Openrouter | bytedance-seed/seed-2.0-mini |
| Openrouter | bytedance/ui-tars-1.5-7b |
| Openrouter | cognitivecomputations/dolphin-mistral-24b-venice-edition |
| Openrouter | deepcogito/cogito-v2.1-671b |
| Openrouter | deepseek/deepseek-chat |
| Openrouter | deepseek/deepseek-chat-v3-0324 |
| Openrouter | deepseek/deepseek-chat-v3.1 |
| Openrouter | deepseek/deepseek-r1 |
| Openrouter | deepseek/deepseek-r1-0528 |
| Openrouter | deepseek/deepseek-r1-distill-llama-70b |
| Openrouter | deepseek/deepseek-v3.1-terminus |
| Openrouter | deepseek/deepseek-v3.2 |
| Openrouter | deepseek/deepseek-v3.2-exp |
| Openrouter | deepseek/deepseek-v4-flash |
| Openrouter | deepseek/deepseek-v4-flash-0731 |
| Openrouter | deepseek/deepseek-v4-pro |
| Openrouter | deepseek/deepseek-v4-pro-0813 |
| Openrouter | google/gemma-2-27b-it |
| Openrouter | google/gemma-3-12b-it |
| Openrouter | google/gemma-3-27b-it |
| Openrouter | google/gemma-3-4b-it |
| Openrouter | google/gemma-3n-e4b-it |
| Openrouter | google/gemma-4-26b-a4b-it |
| Openrouter | google/gemma-4-31b-it |
| Openrouter | gryphe/mythomax-l2-13b |
| Openrouter | ibm-granite/granite-4.1-8b |
| Openrouter | inception/mercury-2 |
| Openrouter | inclusionai/ling-2.6-1t |
| Openrouter | inclusionai/ling-2.6-flash |
| Openrouter | inclusionai/ling-3.0-flash |
| Openrouter | inclusionai/ring-2.6-1t |
| Openrouter | mancer/weaver |
| Openrouter | meta-llama/llama-3.1-70b-instruct |
| Openrouter | meta-llama/llama-3.1-8b-instruct |
| Openrouter | meta-llama/llama-3.2-3b-instruct |
| Openrouter | meta-llama/llama-3.3-70b-instruct |
| Openrouter | meta-llama/llama-4-maverick |
| Openrouter | meta-llama/llama-4-scout |
| Openrouter | meta-llama/llama-guard-4-12b |
| Openrouter | meta/muse-glimmer-30b |
| Openrouter | microsoft/phi-4 |
| Openrouter | microsoft/wizardlm-2-8x22b |
| Openrouter | minimax/minimax-m1 |
| Openrouter | minimax/minimax-m2 |
| Openrouter | minimax/minimax-m2.1 |
| Openrouter | minimax/minimax-m2.5 |
| Openrouter | minimax/minimax-m2.7 |
| Openrouter | minimax/minimax-m3 |
| Openrouter | mistralai/ministral-8b |
| Openrouter | mistralai/mistral-nemo |
| Openrouter | mistralai/mistral-small-24b-instruct-2501 |
| Openrouter | mistralai/mistral-small-2603 |
| Openrouter | mistralai/mistral-small-3.2-24b-instruct |
| Openrouter | moonshotai/kimi-k2 |
| Openrouter | moonshotai/kimi-k2-0905 |
| Openrouter | moonshotai/kimi-k2-thinking |
| Openrouter | moonshotai/kimi-k2.5 |
| Openrouter | moonshotai/kimi-k2.6 |
| Openrouter | moonshotai/kimi-k2.7-code |
| Openrouter | moonshotai/kimi-k3 |
| Openrouter | morph/morph-v3-fast |
| Openrouter | morph/morph-v3-large |
| Openrouter | nousresearch/hermes-3-llama-3.1-405b |
| Openrouter | nousresearch/hermes-3-llama-3.1-70b |
| Openrouter | nousresearch/hermes-4-405b |
| Openrouter | nousresearch/hermes-4-70b |
| Openrouter | nvidia/nemotron-3-nano-30b-a3b |
| Openrouter | nvidia/nemotron-3-super-120b-a12b |
| Openrouter | nvidia/nemotron-3-ultra-550b-a55b |
| Openrouter | nvidia/nemotron-3.5-lightning |
| Openrouter | openai/gpt-oss-120b |
| Openrouter | openai/gpt-oss-20b |
| Openrouter | openai/gpt-oss-safeguard-20b |
| Openrouter | openrouter/auto |
| Openrouter | openrouter/auto-beta |
| Openrouter | openrouter/bodybuilder |
| Openrouter | openrouter/free |
| Openrouter | openrouter/fusion |
| Openrouter | openrouter/pareto-code |
| Openrouter | perceptron/perceptron-mk1 |
| Openrouter | perplexity/sonar |
| Openrouter | perplexity/sonar-deep-research |
| Openrouter | perplexity/sonar-pro |
| Openrouter | perplexity/sonar-pro-search |
| Openrouter | perplexity/sonar-reasoning-pro |
| Openrouter | qwen/qwen-2.5-72b-instruct |
| Openrouter | qwen/qwen-2.5-7b-instruct |
| Openrouter | qwen/qwen2.5-vl-72b-instruct |
| Openrouter | qwen/qwen3-14b |
| Openrouter | qwen/qwen3-235b-a22b-2507 |
| Openrouter | qwen/qwen3-235b-a22b-thinking-2507 |
| Openrouter | qwen/qwen3-30b-a3b |
| Openrouter | qwen/qwen3-30b-a3b-instruct-2507 |
| Openrouter | qwen/qwen3-32b |
| Openrouter | qwen/qwen3-coder |
| Openrouter | qwen/qwen3-coder-30b-a3b-instruct |
| Openrouter | qwen/qwen3-coder-next |
| Openrouter | qwen/qwen3-next-80b-a3b-instruct |
| Openrouter | qwen/qwen3-next-80b-a3b-thinking |
| Openrouter | qwen/qwen3-vl-235b-a22b-instruct |
| Openrouter | qwen/qwen3-vl-235b-a22b-thinking |
| Openrouter | qwen/qwen3-vl-30b-a3b-instruct |
| Openrouter | qwen/qwen3-vl-8b-instruct |
| Openrouter | qwen/qwen3.5-122b-a10b |
| Openrouter | qwen/qwen3.5-27b |
| Openrouter | qwen/qwen3.5-35b-a3b |
| Openrouter | qwen/qwen3.5-397b-a17b |
| Openrouter | qwen/qwen3.5-9b |
| Openrouter | qwen/qwen3.6-27b |
| Openrouter | qwen/qwen3.6-35b-a3b |
| Openrouter | qwen/qwen3.8-2.4t-a95b |
| Openrouter | qwen/qwen3.8-27b |
| Openrouter | rekaai/reka-edge |
| Openrouter | rekaai/reka-flash-3 |
| Openrouter | relace/relace-apply-3 |
| Openrouter | relace/relace-search |
| Openrouter | sao10k/l3-lunaris-8b |
| Openrouter | sao10k/l3.1-euryale-70b |
| Openrouter | sao10k/l3.3-euryale-70b |
| Openrouter | stepfun/step-3.7-flash |
| Openrouter | tencent/hy-mt2-1.8b |
| Openrouter | tencent/hy-mt2-30b-a3b |
| Openrouter | tencent/hy3 |
| Openrouter | thedrummer/cydonia-24b-v4.1 |
| Openrouter | thedrummer/rocinante-12b |
| Openrouter | thedrummer/skyfall-36b-v2 |
| Openrouter | thedrummer/unslopnemo-12b |
| Openrouter | thinkingmachines/inkling |
| Openrouter | thinkingmachines/inkling-small |
| Openrouter | undi95/remm-slerp-l2-13b |
| Openrouter | x-ai/grok-4.20 |
| Openrouter | x-ai/grok-4.20-multi-agent |
| Openrouter | x-ai/grok-4.3 |
| Openrouter | x-ai/grok-4.5 |
| Openrouter | x-ai/grok-4.6 |
| Openrouter | x-ai/grok-build-0.1 |
| Openrouter | xiaomi/mimo-v2.5 |
| Openrouter | xiaomi/mimo-v2.5-pro |
| Openrouter | z-ai/glm-4.5-air |
| Openrouter | z-ai/glm-4.5v |
| Openrouter | z-ai/glm-4.6 |
| Openrouter | z-ai/glm-4.6v |
| Openrouter | z-ai/glm-4.7 |
| Openrouter | z-ai/glm-4.7-flash |
| Openrouter | z-ai/glm-5 |
| Openrouter | z-ai/glm-5.1 |
| Openrouter | z-ai/glm-5.2 |
| Openrouter | z-ai/glm-5.2:free |
| Openrouter | ~deepseek/deepseek-v4-flash-latest |
| Openrouter | ~moonshotai/kimi-latest |
| Openrouter | ~x-ai/grok-latest |
Models from other model creators, such as xAI, DeepSeek, Meta, Mistral, and Qwen, are available in partnership with OpenRouter, which routes many AI models. To browse the full catalog and find the model IDs to use, see the OpenRouter models directory.
To call these models, pass a model ID in the OpenRouter notation - for example, deepseek/deepseek-v4-flash-0731 - to either the OpenRouter SDK or the OpenAI SDK, as shown in Using official client libraries above. You can also call them via REST, as shown in Using official REST APIs.
To understand pricing for AI Gateway, check out our Pricing for AI features docs.
Netlify applies rate limits for your team's usage of the AI Gateway, across all of your team's projects. The rate limit is per minute and differs by plan, with higher plans having a higher limit.
Tokens consumed by each request to the AI Gateway are converted to USD (U.S. dollars) based on the costs published by the providers we support, and then to Netlify credits. $1 USD of AI model usage equates to 180 credits. Learn more in our Pricing for AI features.
The limit depends on your plan:
| Plan | Limit per minute (credits) |
|---|---|
| Free | 90 |
| Personal | 450 |
| Pro | 1,800 |
| Enterprise | 9,000 |
Thus, when adding AI Gateway-based features to your site, it's always advised to track your credit usage - and ensure you have either enabled auto recharge or purchased credit packs to meet the demand you expect without exhausting your credits.
The AI Gateway has the following limitations at this time:
To help you monitor AI Gateway usage, check out our docs on monitoring AI feature usage.
Your feedback helps us improve our docs.