netlify-access-control
Picks the right Netlify protection layer for a deployed site and disambiguates the three unrelated things people call "auth". Use when a developer wants to…
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
$ npx -y skills add netlify/context-and-tools --skill netlify-ai-gateway --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/netlify-ai-gatewayContext preview
The summary Claude sees to decide when to auto-load this skill.
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
name: netlify-ai-gateway description: 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.
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):
File: `netlify/functions/joke.js` (`mkdir -p netlify/functions`). Install: `npm install openai`.
import process from "process";
import OpenAI from "openai";
export default async () => {
const client = new OpenAI(); // reads OPENAI_API_KEY + OPENAI_BASE_URL
try {
const res = await client.responses.create({
model: "gpt-5-mini",
input: [{ role: "user", content: "Give me a random short dad joke" }],
reasoning: { effort: "minimal" },
});
return Response.json({
joke: res.output_text?.trim() || "Out of jokes",
model: res.model,
tokens: { input: res.usage.input_tokens, output: res.usage.output_tokens },
});
} catch (e) {
return Response.json({ error: `${e}` }, { status: 500 });
}
};
export const config = { path: "/api/joke" }; // route, local + deployedClient-side fetch just hits the route:
const res = await fetch("/api/joke");
const data = await res.json();Each SDK auto-reads the injected env vars. **OpenRouter is the exception:** its base URL must be passed explicitly.
// Anthropic — npm i @anthropic-ai/sdk
import Anthropic from '@anthropic-ai/sdk';
const anthropic = new Anthropic(); // ANTHROPIC_API_KEY + ANTHROPIC_BASE_URL
await anthropic.messages.create({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello!' }],
});// OpenAI — npm i openai
import OpenAI from 'openai';
const openai = new OpenAI(); // OPENAI_API_KEY + OPENAI_BASE_URL
await openai.chat.completions.create({
model: 'gpt-5',
messages: [{ role: 'user', content: 'Hello!' }],
});// Google Gemini — npm i @google/genai
import { GoogleGenAI } from '@google/genai';
const genAI = new GoogleGenAI({}); // GEMINI_API_KEY + GOOGLE_GEMINI_BASE_URL
await genAI.models.generateContent({
model: 'gemini-2.5-pro',
contents: 'Hello!',
});// OpenRouter — npm i @openrouter/sdk — base URL REQUIRED
import { OpenRouter } from '@openrouter/sdk';
const openRouter = new OpenRouter({
serverURL: process.env.OPENROUTER_BASE_URL, // API key auto-read from OPENROUTER_API_KEY
});
await openRouter.chat.send({
chatRequest: {
model: 'x-ai/grok-4.5',
messages: [{ role: 'user', content: 'Hello!' }],
},
});**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:
await openai.chat.completions.create({
model: 'deepseek/deepseek-v4-flash-0731',
messages: [{ role: 'user', content: 'Hello!' }],
});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:**
Use 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:
Public Netlify skills for AI coding agents. Each skill is a focused, factual reference for a Netlify platform primitive — designed to help agents build correctly on Netlify without needing to search docs.
Repo: netlify/context-and-tools
Picks the right Netlify protection layer for a deployed site and disambiguates the three unrelated things people call "auth". Use when a developer wants to…
Run AI agent tasks remotely on Netlify using Claude, Codex, or Gemini. Use when the user wants to run an AI agent on their site, get a second opinion from…
Store and retrieve unstructured objects, file uploads, and cache-like state on Netlify using the @netlify/blobs key/value API from Functions, Edge Functions,…
Cache dynamic and static responses on Netlify's CDN from Functions, Edge Functions, and proxies. Use when you add caching or cache-control headers to a…
Configure Netlify projects via netlify.toml and the _headers/_redirects files — covering build settings and deploy contexts alongside environment…
Zero-config Postgres for Netlify apps via @netlify/database — querying data from Functions/Edge Functions, writing schema migrations, setting up Drizzle ORM,…