Netlify AI Gateway

Guide for using Netlify AI Gateway to access AI models. Use when adding AI capabilities or selecting/changing AI models. Must be read before

What Is This?

Overview

Netlify AI Gateway is a managed proxy layer that sits between your application and third-party AI model providers. It provides a unified interface for accessing models from OpenAI, Anthropic, and Google, routing requests through Netlify's infrastructure rather than calling provider APIs directly. This approach centralizes authentication, simplifies SDK configuration, and gives developers a consistent way to integrate AI capabilities into Netlify-hosted projects.

The gateway enforces an important constraint: only a specific subset of models from each provider is supported. Not every model a provider offers is available through the gateway. This means developers must consult the approved model list before writing any integration code. Attempting to use an unsupported model will result in failed requests, so selecting a model from the verified list is a required first step, not an optional one.

Environment variables and SDK initialization are handled in a standardized way across all supported providers. Once configured correctly, switching between providers or models requires minimal code changes, making the gateway a practical foundation for projects that may need to evolve their AI model choices over time.

Who Should Use This

  • Frontend and full-stack developers building AI-powered features on Netlify-hosted applications
  • Teams that want centralized API key management without exposing provider credentials in client-side code
  • Developers evaluating multiple AI providers and needing a consistent integration pattern across all of them
  • Engineers responsible for maintaining AI integrations who want to reduce the overhead of managing separate provider SDKs
  • Technical leads setting up project scaffolding and establishing standards for how AI models are accessed across a codebase

Why Use It?

Problems It Solves

  • Direct provider API calls require each developer or deployment environment to manage separate credentials, increasing the risk of key exposure and configuration drift.
  • Switching between AI providers typically involves rewriting SDK initialization code and updating multiple environment variables across environments.
  • Without a proxy layer, usage tracking and request logging must be implemented separately for each provider integration.
  • Teams working across multiple Netlify projects have no shared mechanism for enforcing which models are approved for use, leading to inconsistent dependencies.

Core Highlights

  • Unified proxy for OpenAI, Anthropic, and Google model providers
  • Standardized SDK setup pattern that works across all supported providers
  • Centralized environment variable configuration managed through Netlify's platform
  • Enforced model allowlist that prevents use of unsupported or deprecated models
  • Reduced credential surface area by routing authentication through Netlify infrastructure
  • Consistent request and response handling regardless of the underlying provider
  • Simplified provider switching with minimal code changes required

How to Use It?

Basic Usage

To initialize the Netlify AI Gateway with the Anthropic SDK, configure the base URL and authorization header to route through the gateway endpoint.

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

const client = new Anthropic({
  baseURL: process.env.ANTHROPIC_BASE_URL,
  apiKey: process.env.ANTHROPIC_API_KEY,
});

For OpenAI, the pattern follows the same structure using the gateway-provided base URL.

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: process.env.OPENAI_BASE_URL,
  apiKey: process.env.OPENAI_API_KEY,
});

Specific Scenarios

Scenario 1: Adding a chat completion feature. After confirming your chosen model appears in the approved model list, initialize the appropriate SDK using gateway environment variables. Pass the exact model identifier string as specified in the list, then call the completions endpoint as you normally would with that SDK.

Scenario 2: Switching providers mid-project. Update the SDK import and client initialization to reference the new provider. Replace the model identifier with an approved model from the new provider. Update the relevant environment variables in the Netlify dashboard. No changes to your request logic are required if the API shape is compatible.

Real-World Examples

A content platform uses the gateway to power a writing assistant, routing requests through Anthropic while keeping API keys out of the client bundle entirely. A developer tools product uses the gateway to offer model selection to end users, swapping between approved OpenAI and Google models based on user preference without restructuring the backend.

Important Notes

Requirements

  • The project must be hosted on or deployed through Netlify
  • Environment variables must be configured through the Netlify dashboard or CLI before deployment
  • Only models listed in the official Netlify AI Gateway approved model list may be used