netlify/context-and-tools/netlify-ai-gateway
Claude Code and agent skill by netlify/context-and-tools
- community
Checking that the SKILL.md file is still in the repository.
Use Netlify AI Gateway to call OpenAI, Anthropic Claude, Google Gemini, TypeSafe (Jev), or OpenRouter-hosted models (xAI/DeepSeek/Meta/Mistral/Qwen) from Netlify Functions or Edge Functions without managing provider accounts or API keys. Reach for this when adding an AI feature to a Netlify app — a chatbot, text summarizer, image generator, joke/content generator, form-submission routing or analysis, or any LLM call — or when wiring the OpenAI/Anthropic/Gemini/TypeSafe/OpenRouter SDK into a Netlify Function, choosing which env vars to use, streaming long generations, or debugging why gateway calls fail at build time or return 401.
Install
npx vskill@latest install netlify/context-and-tools/netlify-ai-gatewaySKILL.md
Netlify AI Gateway
Call AI models from Netlify compute using the provider's official SDK. The gateway injects provider credentials automatically — instantiate the SDK with no args and it works.
Use the provider SDK with injected env credentials. Do not hand-roll a raw fetch() against the gateway URL, and do not wire calls to NETLIFY_AI_GATEWAY_KEY / NETLIFY_AI_GATEWAY_URL as your default path — those are for third-party/unsupported libraries only (see below).
Footguns (read first)
- Not browser-callable. Gateway calls belong in Functions or Edge Functions — never in client-side code. The browser has no injected credentials.
- Runtime-only credentials. Never call the gateway from build scripts, prerender/SSG, or build plugins — those get no credentials and fail. Do AI work at request time; cache to Netlify Blobs if output must look precomputed.
- 60-second sync timeout. A gateway call in a synchronous function is bound by the 60s function timeout. Stream long generations (SDK streaming +
ReadableStream), or use a background function that persists output for the client to fetch. Never leave a slow generation unstreamed. - Requires one production deploy. The gateway does not activate until a project has at least one production deploy. Even for local dev, run
netlify deploy --prodonce first. - Don't hardcode model lists. Available models change. Check the live providers endpoint (
https://api.netlify.com/api/v1/ai-gateway/providers/detailed) rather than baking in a static list. - OpenRouter SDK needs 1.2.43+. Earlier versions ignore
OPENROUTER_BASE_URL, call openrouter.ai directly, and fail with401 Missing Authentication header.
Where code goes
Write normal Function/handler code — there is no AI-specific file type. A function at netlify/functions/joke.js exporting config = { path: "/api/joke" } is served at /api/joke under both netlify dev and production.
Provider SDKs (instantiate with no args)
The gateway injects each provider's own env vars, so the official SDK works with zero config.
Anthropic Claude:
OpenAI:
Google Gemini:
TypeSafe (Jev) — structured decisions (e.g. routing/classifying form submissions):
systemOne defaults to the jev-latest model. Each question is a choice(prompt, options) mapping named options to null; the result is at answers.<question>.choice. POST a JSON body (e.g. {"message":"Can someone help us upgrade to 200 seats?"}) with Content-Type: application/json.
OpenRouter (SDK 1.2.43+ required — see footguns):
Models available through OpenRouter can be called with either the OpenRouter SDK or the OpenAI SDK using OpenRouter model-ID notation (e.g. deepseek/deepseek-v4-flash-0731) — just pass the ID as the model.
Model IDs above (gpt-6.1-sol, claude-sonnet-5-5, gemini-3.8-flash, x-ai/grok-4.5, etc.) are examples that change — check the live providers endpoint.
Env vars — which to use
Default: supported provider SDKs consume their injected provider-specific vars automatically. Instantiate the SDK with no args as shown above (new OpenAI(), new Anthropic(), new GoogleGenAI({}), new TypeSafeClient(), new OpenRouter()) and the corresponding pair is read for you:
- OpenAI:
OPENAI_API_KEY,OPENAI_BASE_URL - Anthropic:
ANTHROPIC_API_KEY,ANTHROPIC_BASE_URL - Google Gemini:
GEMINI_API_KEY,GOOGLE_GEMINI_BASE_URL - OpenRouter:
OPENROUTER_API_KEY,OPENROUTER_BASE_URL - TypeSafe:
TYPESAFE_API_KEY,TYPESAFE_BASE_URL
Explicit-config path: NETLIFY_AI_GATEWAY_KEY and NETLIFY_AI_GATEWAY_URL are always injected and never collide with user-set provider vars. Use this pair only when a third-party or unsupported library needs explicit key/base-URL configuration — pass them as constructor arguments. It is not the default; supported SDKs should use their provider-specific vars above.
Precedence: Netlify never overrides a key or base URL you set at project or team level. If you set your own provider key, the gateway defers to it. For Gemini specifically, injection is skipped if GOOGLE_API_KEY or GOOGLE_VERTEX_BASE_URL is set (Vertex/Google-API-key setups win).
To stop all injection, disable AI Features: https://docs.netlify.com/build/build-with-ai/manage-ai-for-your-team/manage-ai-features/#disable-ai-features
Full example (Vite + React + Function)
Detect gateway availability by checking for an injected var, then call the SDK.
Install the client first: npm install openai. Then create netlify/functions/joke.js:
src/App.jsx fetches /api/joke:
Local development
Two options — both need at least one prior production deploy:
- Netlify CLI:
netlify devgives full gateway support. - Vite plugin: access the gateway locally without
netlify dev. Add@netlify/vite-pluginand run your native dev command (npm run dev):
Setup flow:
Billing, limits, constraints
- Plans: Credit-based plans only (Free, Personal, Pro). Enterprise: contact your Account Manager. Legacy plans must switch first. Enabled by default unless you disabled AI Features or set your own provider keys.
- Cost: tokens → USD (provider-published rates) → credits. $1 USD = 180 credits.
- Rate limits (per minute, per team, across all projects): Free 90, Personal 450, Pro 1,800, Enterprise 9,000 credits.
- Context window: input limited to 200k tokens.
- Prompt caching: Anthropic — only the default 5-min ephemeral cache; OpenAI — per-account
prompt_cache_keyset for you; Gemini — explicit context caching unsupported. - No pass-through headers (can't enable header-gated experimental features), no batch inference, no OpenAI priority processing.
- OpenRouter ZDR only: Netlify routes only to providers with a Zero Data Retention policy. A model listed in the OpenRouter directory but with no ZDR-guaranteeing host is not served. Browse ZDR-eligible models: https://openrouter.ai/models?zdr=true
- Privacy: The gateway does not store prompts or model outputs.
Cost controls: Set up rate-limiting rules on AI-calling Functions/Edge Functions to prevent visitor abuse and runaway cost: https://docs.netlify.com/manage/security/secure-access-to-sites/rate-limiting/ — and configure auto-recharge or credit packs: https://docs.netlify.com/manage/accounts-and-billing/billing/billing-for-credit-based-plans/configure-auto-recharge/ · https://docs.netlify.com/manage/accounts-and-billing/billing/billing-for-credit-based-plans/buy-credit-packs/
Monitor usage: https://docs.netlify.com/manage/accounts-and-billing/billing/billing-for-credit-based-plans/monitor-usage-for-credit-based-plans
References
- Overview: https://docs.netlify.com/build/ai-gateway/overview.md
- Quickstart: https://docs.netlify.com/build/ai-gateway/quickstart-for-ai-gateway.md
- Examples: https://docs.netlify.com/build/ai-gateway/examples.md — including the AI SEO Image Generator (Gemini image generation): https://github.com/netlify/examples/tree/main/examples/ai-seo-image-generator and a TanStack Start chat app: https://github.com/netlify-templates/tanstack-template
<!-- Gap: exact directly-served model names (Anthropic/OpenAI/Gemini/TypeSafe) are not statically enumerable — rendered at build time from the live providers endpoint. -->
<!-- system: agent-context/ai-gateway/system.md — human-owned, merged by ctx-gen; edit system.md, not this section -->
Netlify house rules (ai-gateway)
These are org conventions, not docs facts — merged into the rendered skill by ctx-gen and never generated. Owned by the skills maintainer.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/netlify-ai-gateway/SKILL.md
Popularity
- Repository stars
- 16
- Repository forks
- 4
- 7-day trend score
- 14
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 1 May 2026, 6 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/netlify/context-and-tools/netlify-ai-gateway)