数据与研究

netlify-ai-gateway

netlify/context…nd-tools

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.

  • 3099 次安装
  • 47 星标
  • 收录于

安装命令

npx skills add https://github.com/netlify/context-and-tools --skill netlify-ai-gateway

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 --prod once 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 with 401 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.