netlify-ai-gateway
Installation
SKILL.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.