netlify-ai-gateway
Installation
SKILL.md
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):
- Not browser-callable. The gateway lives in Functions/Edge Functions only. Never call it from client-side React/browser code.
- 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.
- 60s sync timeout. A slow generation in a synchronous function is killed at 60s. Stream it (SDK streaming +
ReadableStream), or use a background function that persists output for the client to fetch. - Requires a production deploy. The gateway does not activate until the project has at least one production deploy — even in local dev.
- Don't hardcode model lists. Model availability changes; check the live providers endpoint rather than baking in IDs.
Function example
File: netlify/functions/joke.js (mkdir -p netlify/functions). Install: npm install openai.
import process from "process";
import OpenAI from "openai";