Skip to content
Netlify Docs
For the complete Netlify documentation index, see llms.txt. Markdown versions of any documentation page are available by appending .md to its URL.

The new Netlify experience is here. Learn more or join the waitlist.

AI Gateway Overview

Use popular AI models in your code, without needing to manage API keys or external accounts.

This feature is available on Credit-based plans only, including the Free, Personal, and Pro plans. If you are on an Enterprise plan and you’re interested, reach out to your Account Manager.

The AI Gateway service simplifies technical and operational concerns when using AI inference in your code, by removing the need to:

  • Open an account with each provider you want to use.
  • Maintain a separate credit balance with each provider.
  • Copy the API key from each provider to your projects on Netlify.

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:

  • API keys for OpenAI, Anthropic, Google Gemini, OpenRouter, and TypeSafe AI.
  • A custom base URL for each provider, to route requests via the AI Gateway service.

These variables are picked up by the official client libraries of these providers, so no extra configuration is necessary (the OpenRouter SDK requires version 1.2.43 or later). 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:

  1. You have disabled Netlify AI Features for your team, or:
  2. You have set your own API keys for AI providers via environment variables. Netlify does not override these keys. You can add or remove your own keys at any point.

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-5-5',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello!' }]
});
return message;
}

Library: Anthropic TypeScript API Library

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-5-5',
max_tokens: 1024,
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:

  1. OPENAI_API_KEY and OPENAI_BASE_URL - unless any of these is already set by you at the project or team level.
  2. ANTHROPIC_API_KEY and ANTHROPIC_BASE_URL - unless any of these is already set by you.
  3. 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.
  4. OPENROUTER_API_KEY and OPENROUTER_BASE_URL - unless any of these is already set by you.
  5. TYPESAFE_API_KEY and TYPESAFE_BASE_URL - unless any of these is already set by you.

NETLIFY_AI_GATEWAY_KEY and NETLIFY_AI_GATEWAY_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, Google Gemini, Meta, and TypeSafe 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-fable-5-1
Anthropic claude-fable-5-2
Anthropic claude-haiku-4-5
Anthropic claude-haiku-4-5-20251001
Anthropic claude-haiku-5-5
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-opus-5-5
Anthropic claude-sonnet-4-6
Anthropic claude-sonnet-5
Anthropic claude-sonnet-5-5
Gemini gemini-2.5-flash-image
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.7-flash
Gemini gemini-3.8-flash
Gemini gemini-4-argon
Gemini gemini-4-carbon
Gemini gemini-4-hydrogen
Gemini gemini-4-neon
Gemini gemini-flash-latest
Gemini gemini-flash-lite-latest
Gemini gemini-nano-banana-2.1
Meta muse-ember-1.0
Meta muse-spark-1.1
Meta muse-spark-1.2
Meta muse-spark-1.3
Meta muse-wonder-1.0
OpenAI chat-latest
OpenAI gpt-4.1
OpenAI gpt-4.1-mini
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 gpt-6-astra
OpenAI gpt-6-luna
OpenAI gpt-6-sol
OpenAI gpt-6.1-sol
OpenAI gpt-6.1-terra
OpenAI gpt-6.2-astra
OpenAI gpt-6.2-sol
OpenAI gpt-image-1.5
OpenAI gpt-image-2
OpenAI gpt-image-2-2026-04-21
OpenAI gpt-image-2.5-flare
OpenAI gpt-image-2.5-flare-2026-09-08
OpenAI gpt-image-2.5-sunburst
OpenAI gpt-image-2.5-sunburst-2026-09-08
OpenAI gpt-image-2.6-flare
OpenAI gpt-image-2.6-sunburst
OpenAI o3
TypeSafe jev-1.13.0
TypeSafe jev-1.14.0
TypeSafe jev-latest
TypeSafe jev-preview

Models from other model creators, such as xAI, DeepSeek, Mistral, and Qwen, are available in partnership with OpenRouter, which routes to many AI models. The full list is below.

To call these models, pass any of the model IDs in the table below (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.

Additional information about these models is available in the OpenRouter models directory.

Model
amazon/ergo-1.0
anthracite-org/magnum-v4-72b
bytedance/ui-tars-1.5-7b
cognitivecomputations/dolphin-mistral-24b-venice-edition
cohere/command-a-plus
deepseek/deepseek-chat
deepseek/deepseek-chat-v3.1
deepseek/deepseek-r1-0528
deepseek/deepseek-v3.2
deepseek/deepseek-v4-flash
deepseek/deepseek-v4-flash-0731
deepseek/deepseek-v4-flash-vision-exp
deepseek/deepseek-v4-pro
deepseek/deepseek-v4-pro-0813
deepseek/deepseek-v4.1-flash
deepseek/deepseek-v4.1-flash-1017
deepseek/deepseek-v4.1-flash-1017:tee
elorian/glimpse
fireworks/ember-1
google/gemma-2-27b-it
google/gemma-3-12b-it
google/gemma-3-27b-it
google/gemma-3-4b-it
google/gemma-4-26b-a4b-it
google/gemma-4-31b-it
gryphe/mythomax-l2-13b
ibm-granite/granite-4.2-8b
inclusionai/ling-3.0-flash
inclusionai/ling-3.0-flash-vl
inclusionai/ling-3.2-air
inclusionai/lingsante-3.1-air-vl
inference-net/schematron-v2-small
inference-net/schematron-v2-turbo
liquid/lfm-2.5-24b-a2b
liquid/lfm-3-1.7b
mancer/weaver
meta-llama/llama-3.1-8b-instruct
meta-llama/llama-3.2-3b-instruct
meta-llama/llama-3.3-70b-instruct
meta-llama/llama-4-maverick
meta-llama/llama-4-scout
meta-llama/llama-guard-4-12b
meta/muse-glimmer-30b
meta/muse-spark-open
microsoft/phi-4
minimax/minimax-m2.5
minimax/minimax-m2.7
minimax/minimax-m3
minimax/minimax-m3.1-flash
mistralai/codestral-2508
mistralai/devstral-2512
mistralai/ministral-14b-2512
mistralai/ministral-3b-2512
mistralai/ministral-8b-2512
mistralai/mistral-large-2407
mistralai/mistral-large-2512
mistralai/mistral-large-4-0
mistralai/mistral-medium-3-5
mistralai/mistral-nemo
mistralai/mistral-saba
mistralai/mistral-small-24b-instruct-2501
mistralai/mistral-small-2603
mistralai/mistral-small-3.1-24b-instruct
mistralai/mistral-small-3.2-24b-instruct
mistralai/mixtral-8x22b-instruct
mistralai/voxtral-small-24b-2507
moonshotai/kimi-k2.6
moonshotai/kimi-k2.7-code
moonshotai/kimi-k3
moonshotai/kimi-k3.1-pro
morph/morph-v3-fast
morph/morph-v3-large
nousresearch/hermes-4-405b
nvidia/nemotron-3-nano-30b-a3b
nvidia/nemotron-3-super-120b-a12b
nvidia/nemotron-3-ultra-550b-a55b
nvidia/nemotron-3.5-lightning
nvidia/nemotron-3.5-super-vl
nvidia/switchyard
openai/gpt-oss-120b
openai/gpt-oss-20b
openai/gpt-oss-safeguard-20b
openrouter/auto
openrouter/auto-beta
openrouter/auto-code
openrouter/free
openrouter/pareto-code
particle-ai/particle-1
perceptron/perceptron-mk1
perceptron/perceptron-mk1.5
perplexity/sonar
perplexity/sonar-deep-research
perplexity/sonar-pro
perplexity/sonar-pro-search
perplexity/sonar-reasoning-pro
qwen/qwen-2.5-72b-instruct
qwen/qwen-2.5-coder-32b-instruct
qwen/qwen2.5-vl-72b-instruct
qwen/qwen3-14b
qwen/qwen3-235b-a22b-2507
qwen/qwen3-30b-a3b
qwen/qwen3-30b-a3b-instruct-2507
qwen/qwen3-32b
qwen/qwen3-coder
qwen/qwen3-coder-next
qwen/qwen3-next-80b-a3b-instruct
qwen/qwen3-vl-235b-a22b-instruct
qwen/qwen3-vl-30b-a3b-instruct
qwen/qwen3-vl-8b-instruct
qwen/qwen3.5-27b
qwen/qwen3.5-35b-a3b
qwen/qwen3.5-397b-a17b
qwen/qwen3.5-9b
qwen/qwen3.6-27b
qwen/qwen3.6-35b-a3b
qwen/qwen3.8-2.4t-a95b
qwen/qwen3.8-27b
qwen/qwen3.8-flash
radixark/daisyrose-27b
reflection/beam-1.0-501b-a23b
rekaai/reka-edge
rekaai/reka-flash-3
relace/relace-apply-3
relace/relace-search
ricursiveai/ripple-65b-preview
sao10k/l3-lunaris-8b
scaledown/extract
scaledown/summarize
scaledown/toolcall:free
stepfun/step-5
tencent/hy4
tencent/hy4-flash
thedrummer/cydonia-24b-v4.1
thedrummer/skyfall-36b-v2
thedrummer/unslopnemo-12b
thinkingmachines/inkling
thinkingmachines/inkling-2-mini
thinkingmachines/inkling-2-small
thinkingmachines/inkling-small
typesafe/jev-router
undi95/remm-slerp-l2-13b
upstage/solar-mini-4-5
upstage/solar-pro4
x-ai/grok-4.20
x-ai/grok-4.20-multi-agent
x-ai/grok-4.3
x-ai/grok-4.5
x-ai/grok-4.6
x-ai/grok-4.7
xiaomi/mimo-v2.6-flash
xiaomi/mimo-v2.6-flash-mopd
xiaomi/mimo-v2.6-pro
z-ai/glm-4.6
z-ai/glm-4.7
z-ai/glm-4.7-flash
z-ai/glm-5.2
z-ai/glm-5.3
z-ai/glm-5.3-flash
z-ai/glm-5.3-flash:tee
z-ai/glm-5.4
~deepseek/deepseek-flash-latest
~deepseek/deepseek-flash-latest:tee
~deepseek/deepseek-pro-latest
~deepseek/deepseek-v4-flash-latest
~moonshotai/kimi-latest
~moonshotai/kimi-pro-latest
~x-ai/grok-latest
~z-ai/glm-flash-latest
~z-ai/glm-flash-latest:tee
~z-ai/glm-latest

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:

  1. Using the AI Gateway requires that the site has had at least one production deployment in the past.
  2. The context window (input prompt) is limited to 200k tokens.
  3. Prompt caching:
    • Anthropic Claude: only the default 5-minute ephemeral cache duration is supported for Claude.
    • OpenAI: the AI Gateway sets a per-account prompt_cache_key.
    • Google Gemini: explicit context caching is not supported.
  4. The AI Gateway does not pass through any request headers (and thus you cannot enable proprietary experimental features via headers).
  5. Batch inference is not supported.
  6. Priority processing (an OpenAI feature) is not supported.

To help you monitor AI Gateway usage, check out our docs on monitoring AI feature usage.