netlify-ai-gateway

Guide for using Netlify AI Gateway to access AI models. Use when adding AI capabilities (text generation, image generation, embeddings) to a Netlify project. Covers supported providers (OpenAI, Anthropic, Google), SDK configuration via base URL override, environment variables, and usage from Netlify Functions.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "netlify-ai-gateway" with this command: npx skills add netlify/context-and-tools/netlify-context-and-tools-netlify-ai-gateway

Netlify AI Gateway

Netlify AI Gateway provides access to AI models from multiple providers without managing API keys directly. It is available on all Netlify sites.

How It Works

The AI Gateway acts as a proxy — you use standard provider SDKs (OpenAI, Anthropic, Google) but point them at Netlify's gateway URL instead of the provider's API. Netlify handles authentication, rate limiting, and monitoring.

Setup

  1. Enable AI on your site in the Netlify UI
  2. The environment variable OPENAI_BASE_URL is set automatically by Netlify
  3. Install the provider SDK you want to use

No provider API keys are needed — Netlify's gateway handles authentication.

Using OpenAI SDK

npm install openai
import OpenAI from "openai";

const openai = new OpenAI();
// OPENAI_BASE_URL is auto-configured — no API key or base URL needed

const completion = await openai.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: "Hello!" }],
});

Using Anthropic SDK

npm install @anthropic-ai/sdk
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  baseURL: Netlify.env.get("ANTHROPIC_BASE_URL"),
});

const message = await client.messages.create({
  model: "claude-sonnet-4-5-20250929",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello!" }],
});

Using Google AI SDK

npm install @google/generative-ai
import { GoogleGenerativeAI } from "@google/generative-ai";

const genAI = new GoogleGenerativeAI("placeholder");
// Configure base URL via environment variable

const model = genAI.getGenerativeModel({ model: "gemini-2.5-flash" });
const result = await model.generateContent("Hello!");

In a Netlify Function

import type { Config, Context } from "@netlify/functions";
import OpenAI from "openai";

export default async (req: Request, context: Context) => {
  const { prompt } = await req.json();
  const openai = new OpenAI();

  const completion = await openai.chat.completions.create({
    model: "gpt-4o-mini",
    messages: [{ role: "user", content: prompt }],
  });

  return Response.json({
    response: completion.choices[0].message.content,
  });
};

export const config: Config = {
  path: "/api/ai",
  method: "POST",
};

Environment Variables

VariableProviderSet by
OPENAI_BASE_URLOpenAINetlify (automatic)
ANTHROPIC_BASE_URLAnthropicNetlify (automatic)

These are configured automatically when AI is enabled on the site. No manual setup required.

Local Development

With @netlify/vite-plugin or netlify dev, gateway environment variables are injected automatically. The AI Gateway is accessible during local development after the site has been deployed at least once.

Available Models

The gateway supports models from OpenAI, Anthropic, and Google. Use standard model identifiers (e.g., gpt-4o-mini, claude-sonnet-4-5-20250929, gemini-2.5-flash). Available models may change — refer to Netlify's AI Gateway documentation for the current list.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

netlify-config

No summary provided by upstream source.

Repository SourceNeeds Review
General

netlify-image-cdn

No summary provided by upstream source.

Repository SourceNeeds Review
General

netlify-frameworks

No summary provided by upstream source.

Repository SourceNeeds Review
General

netlify-blobs

No summary provided by upstream source.

Repository SourceNeeds Review