Vercel Logo

Using AI Gateway in Production

Learn how AI Gateway handles model access, routing, spend, privacy, developer tools, and production authentication.

An AI feature can work perfectly in a demo and still leave a pile of production questions. What happens when a provider slows down? Which model is driving the bill? Where did a prompt go? Can the coding agents on your laptop use the same Gateway?

This course answers those questions one at a time. Every lesson stands alone, so you can follow the full course or jump directly to the problem in front of you. Each answer is followed by working code, request metadata, or a dashboard check.

The examples use Taco Tuesday, an ordering assistant for a taco truck. It gives us one application to test model changes, outages, caching, budgets, privacy controls, and coding agents without inventing a new project in every lesson.

Get the student project

The Taco Tuesday student project is a Next.js ordering assistant with a streaming AI Gateway route, a shared menu, and runnable scripts for the routing, reliability, caching, cost, privacy, and usage exercises throughout the course.

Deploy with Vercel

The button forks the repository to your GitHub account and deploys the ordering assistant to Vercel. The deployed app authenticates to AI Gateway with Vercel OIDC, so it does not need an AI Gateway API key in the project settings.

To run the app and lesson scripts locally, clone your new repository and set up the project:

pnpm install
cp .env.example .env.local
pnpm dev

Add an AI Gateway API key to .env.local. Keep that file local; it is already excluded from Git.

What you'll be able to do

  • Trace a request to its cost and control spend with routing, caching, budgets, and provider keys
  • Keep an application responding when a provider fails or becomes slow
  • Apply privacy requirements and inspect usage by model, project, API key, and request
  • Connect existing SDKs and coding agents through the same Gateway

Prerequisites

  • A Vercel account (Hobby works for most lessons)
  • Node.js 22+ and pnpm installed
  • Comfortable with TypeScript basics
  • An AI feature you're building, or willingness to run small scripts

The sections

Reliability and Migration: Connect an existing stack, compare models, migrate from the OpenAI SDK, and define routing behavior for outages and slow providers.

Control Spend: Read request costs, route by price, cache repeated prompts, manage credits and budgets, and bring your own provider keys.

Stay Aware: Inspect usage, keep prompts private, and connect Claude Code, OpenCode, and Codex.