Courses

AI Gateway

Put a single control plane in front of the AI models your app calls to observe traffic, control spend, route across models, and enforce security policies without rewriting your code. For students who've deployed a Worker.

AI Gateway

Why put a gateway in front of your model calls: visibility first, then control, by Thomas Desmond. Direct video link

When an application calls an AI model directly, you’re flying blind: you can’t easily see who is driving up token spend, avoid paying twice for repeat questions, swap or fall back between models without redeploying your app, or stop sensitive data and prompt injections before they reach a provider.

Cloudflare AI Gateway sits between your code and the models it calls, whether those models run on Workers AI, OpenAI, Anthropic, or another provider. In this course, you’ll put one Worker behind AI Gateway and learn how to observe and govern its model traffic from a single place.

Exercises

  1. 00.Interview: Tell your agent what you already know about AI gateways, which model providers you use, and what you care most about controlling.
  2. 01.See every request: Create an AI Gateway, route a Worker's model calls through it with custom metadata, and inspect the live request logs.
  3. 02.Cache responses: Turn on exact-match response caching so repeat questions return in milliseconds for $0, and opt out per request with skipCache.
  4. 03.Cap requests and spend: See how Unified Billing and stored keys pay for inference, cap request volume with a rate limit, and enforce a dollar spend limit per team.
  5. 04.Route and fall back: Move model selection out of your Worker and into a versioned gateway route that branches on metadata, falls back on failure, and updates without redeploying your app.
  6. 05.Block bad prompts: Stop prompt injections and sensitive data at the gateway with Guardrails and DLP before they ever reach a model.