netlify-ai-gateway

netlify-ai-gateway is a cursor rule for Cursor from netlify/context-and-tools. It costs 148 tokens per session (3,556 once invoked), scanned C, original, MIT.

A guide to calling OpenAI, Anthropic, Google Gemini, or OpenRouter models from Netlify server-side code through Netlify’s AI Gateway. Server-side code runs on Netlify, while client-side code runs in a visitor’s browser.

In plain words
What is it for?
Use it to build AI chat or completion endpoints, generate text or images, summarize content, proxy model requests, or stream long responses from Netlify Functions or Edge Functions.
Why use it?
It removes the need to manage provider credentials in the function code and explains limits around browser calls, build-time use, slow responses, and deployment state.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc). Also seen: positional $N argument.

Good fit Use it to build AI chat or completion endpoints, generate text or images, summarize content, proxy model requests, or stream long responses from Netlify Functions or Edge Functions.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/netlify/context-and-tools/netlify-ai-gateway
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/netlify/context-and-tools

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for netlify-ai-gateway

README.md
[![agentmods](https://agentmods.dev/badge/rules/netlify/context-and-tools/netlify-ai-gateway/github.svg)](https://agentmods.dev/rules/netlify/context-and-tools/netlify-ai-gateway)
Your own site
<a href="https://agentmods.dev/rules/netlify/context-and-tools/netlify-ai-gateway"><img src="https://agentmods.dev/badge/rules/netlify/context-and-tools/netlify-ai-gateway/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for netlify-ai-gateway

Your own site · 80×15
<a href="https://agentmods.dev/rules/netlify/context-and-tools/netlify-ai-gateway"><img src="https://agentmods.dev/badge/rules/netlify/context-and-tools/netlify-ai-gateway.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 148 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 3,556 The whole file, excluding the scripts and references it only reads on demand.
Security scan C 1 finding. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00148 $0.03556
Opus 5.5 $0.00059 $0.01422
Sonnet 5.5 $0.00030 $0.00711
Haiku 4.5 $0.00015 $0.00356

Measured 6d ago against content hash e990e626d8f8, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade C, and why

netlify-ai-gateway scanned grade C with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Hidden instructionshighPrompt injection

Directives inside HTML comments, invisible characters or bidirectional overrides are read by the model and not by the person reviewing the file.

<!-- system: agent-context/ai-gateway/system.md — human-owned, merged by ctx-gen; edit system.md, not this section -->
cursor/rules/netlify-ai-gateway.mdc · 272 lines

How it starts

The opening of the file, as written. The whole thing — 272 lines — stays where its author put it; the contents beside it link to each section on GitHub.

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. That endpoint lists models — it is not where AI requests are sent.
  • 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.

Read the full file on GitHub · 272 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago Changed · +2 lines e990e626d8f8
  2. 27d ago Changed ae88c84aa8d8
  3. 2mo ago Changed · +69 lines · +19 tokens per session 448030c51d08
  4. 3mo ago First seen · 201 lines · 129 tokens per session scan C 29a1aad1c764

Subscribe to this mod's changes

netlify-ai-gateway is a cursor rule published in the GitHub repository netlify/context-and-tools (58 stars, last pushed 4d ago), licensed MIT. It adds 148 tokens to every session and 3,556 once invoked, about $0.0006 per session on Opus 5.5. A static security scan graded it C with 1 finding (hidden instructions). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

netlify-ai-gateway compared with cursor rules from other repositories

netlify-ai-gateway next to 6 cursor rules from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
netlify-ai-gatewaynetlify/context-and-toolsCursor rule584d agoMITC148Cursor
djangosanjeed5/awesome-cursor-rules-mdcCursor rule3.6k8d agoCC0-1.0A2,043Cursor
api-property-optionality-hygienenovuhq/novuCursor rule40ktodaynoneA0Cursor
cursormrwogu/promptscriptCursor rule324yesterdayMITA53Cursor
pythonPatrickJS/awesome-cursorrulesCursor rule41k6mo agoCC0-1.0A734Cursor
gosupertokens/create-supertokens-appCursor rule244d agoApache-2.0A0Cursor
ehs-ims-conventionsSafetyMP/Autonomous-EHS-ManagementCursor rule92d agoApache-2.0A722Cursor