npx skills add ...
npx skills add netlify/context-and-tools --skill netlify-ai-gateway
Use OpenAI, Anthropic, Google Gemini, or OpenRouter models from Netlify Functions or Edge Functions without managing provider API keys or accounts — the gateway injects credentials automatically. Reach for this when you add an AI chatbot or completion endpoint, generate images or text with Gemini/GPT/Claude, summarize form submissions with AI, build an LLM-backed API route, stream a long AI generation, or wire up any server-side AI provider call on Netlify. Covers provider SDK setup, injected env vars, model availability, rate limits, credit costs, streaming for long generations, and local dev with netlify dev or the Vite plugin.
npx skills add netlify/context-and-tools --skill netlify-ai-gateway
Call AI providers from Netlify server-side compute using each provider's official SDK with zero credential config — the gateway injects the API keys and base URLs the SDKs already read. Instantiate the client with no args (except OpenRouter, which needs an explicit base URL).
Never do these (they silently fail or cost money):
ReadableStream), or use a background function that persists output for the client to fetch.File: netlify/functions/joke.js (mkdir -p netlify/functions). Install: npm install openai.
Client-side fetch just hits the route:
Each SDK auto-reads the injected env vars. OpenRouter is the exception: its base URL must be passed explicitly.
OpenRouter models via the OpenAI SDK: you can reach any OpenRouter-served model (xAI, DeepSeek, Meta, Mistral, Qwen) through the plain OpenAI SDK — just pass the model ID in OpenRouter notation, no extra config:
Set in all Netlify compute contexts at function init only if you have not already set them at project/team level (Netlify never overrides your keys):
| Provider | Vars |
|---|---|
| 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 |
Gemini special case: Netlify will not inject GEMINI_API_KEY / GOOGLE_GEMINI_BASE_URL if either GOOGLE_API_KEY or GOOGLE_VERTEX_BASE_URL is set (use those to point at Vertex or your own Google credentials).
Always injected, never collide with your provider vars:
NETLIFY_AI_GATEWAY_KEYNETLIFY_AI_GATEWAY_BASE_URLUse the SDK path with the per-provider injected vars above as your default. Reach for NETLIFY_AI_GATEWAY_KEY / NETLIFY_AI_GATEWAY_BASE_URL only when a third-party or unsupported library needs the credentials passed explicitly — that's the correct time to configure them by hand.
Two supported paths — both still require an existing production deploy:
netlify dev (full support). Needs npm install -g netlify-cli@latest and netlify login.@netlify/vite-plugin, add netlify() to vite.config.js plugins, run your normal npm run dev — gateway access without netlify dev.netlify init.netlify deploy --prod --open.prompt_cache_key is set; Gemini — explicit context caching not supported.These are org conventions, not docs facts — merged into the rendered skill by ctx-gen and never generated. Owned by the skills maintainer.
fetch() against the gateway, even though raw REST is a supported
surface. The body must not present raw REST or the
NETLIFY_AI_GATEWAY_KEY / NETLIFY_AI_GATEWAY_BASE_URL pair as a
recommended path — but it MUST still document the pair as facts: always
injected, never collide with user-set provider vars, and the right choice
when a third-party or unsupported library needs explicit configuration.
Demote the recommendation; keep the knowledge.ReadableStream), or
use a background function that persists output for the client to fetch —
never leave a slow generation unstreamed and assume it finishes.