Coders In Hoods
  • Courses
  • Roles
  • Blog
  • Setup

Coders In Hoods AI Academy

Every course is free. Sign in to start, and your progress, quiz scores and bookmarks follow you.

AI Academy

  • Courses
  • Paths
  • Setup guides
  • How we teach

Role roadmaps

  • AI Engineer
  • Forward Deployed Engineer
  • Machine Learning Engineer
  • All roles

Coders In Hoods

  • The agency
  • Coaching for teams
  • Blog
  • LinkedIn
  • X (Twitter)

Contact

codersinhoods@gmail.com

© Coders In Hoods · since 2019

Course overview

Infrastructure for Agents

Free · sign in to start and track progress

1 · Compute and execution

  • 1Where agents run
  • 2Sandboxes for agent code
  • 3Durable execution engines
  • 4Queues, schedules and background jobs

2 · State, access and delivery

  • 5State, sessions and checkpoints
  • 6Secrets, identity and tenant isolation
  • 7AI gateways

    Exercise answers

    • Answer: Simulate fallbacks, correlation and budgets
    • Answer: A self-hosted gateway with per-firm keys
  • 8Environments and delivery for agents
CapstoneA production platform slice for one agentReference implementation

Module 2 · State, access and delivery · Lesson 7

AI gateways

One control point between your agents and every model provider. What Vercel AI Gateway, OpenRouter, LiteLLM and Portkey do (routing, fallbacks, keys, budgets, logging, data controls), the arithmetic of fallbacks, and the ways a gateway can mislead you.

70 min 1 video 3 exercises 7-question quiz Answers
Setup for the exercises:Install Claude CodePython with uvDocker and Docker ComposePostgres with pgvector

By the end of this lesson you can

  • Describe the functions of an AI gateway and decide which ones your fleet needs
  • Compare Vercel AI Gateway, OpenRouter, LiteLLM and Portkey on hosting, pricing, routing, keys and budgets
  • Compute the availability gain from fallbacks, and explain why correlated failures and changed behaviour reduce it
  • Configure per-tenant keys, budgets and model fallbacks from Python, and handle budget rejections in an agent
  • Explain the data-handling implications of adding a gateway to the request path

On this page

  • Intuition: the firm's outgoing post room
  • What a gateway does
  • The four products
  • Fallbacks, and their arithmetic
  • Keys and budgets per tenant
  • Code: per-firm key, fallbacks and budget handling
  • Routing for cost
  • Data handling
  • Misconceptions and limits
  • Connections
  • Summary
  • Sources & further reading
  • Quiz

In this lesson

  1. 01Intuition: the firm's outgoing post room
  2. 02What a gateway does
  3. 03Fallbacks, and their arithmetic
  4. 04Keys and budgets per tenant
  5. 05Code: per-firm key, fallbacks and budget handling
  6. 06Routing for cost
  7. 07Data handling
  8. 08Misconceptions and limits
  9. 09Connections
  10. 10Summary

Sources & further reading

  • FrugalGPT: How to Use Large Language Models While Reducing Cost and Improving PerformancePaper · Chen, Zaharia, Zou · 2023The paper that framed model cascades and routing across providers with very different prices. Read the description of its three strategies (prompt adaptation, LLM approximation and the LLM cascade); routing logic like this often lives in a gateway.
  • RouteLLM: Learning to Route LLMs with Preference DataPaper · Ong, Almahairi, Wu, Chiang, Wu et al. · 2024Learned routers that send each query to a strong or a cheap model. Useful context for gateway routing features; the evaluation shows how much quality you trade for cost.
  • Vercel AI Gateway: Models, Routing, and ObservabilityDocs · VercelOpenAI-, Anthropic- and AI SDK-compatible endpoints, zero markup on provider token prices including BYOK, OIDC authentication on Vercel, provider ordering and request logs. Read the model fallbacks and budgets pages next.
  • AI Gateway budgets and spend limitsDocs · VercelTeam, project, API key and user budgets that stack, soft-cap semantics, HTTP 402 rejections, refresh periods and default budgets. The clearest write-up of gateway budget behaviour.
  • OpenRouter provider routingDocs · OpenRouterDefault routing by effective cost and reliability, and the provider object (order, allow_fallbacks, only, ignore, data_collection, zdr, sort) plus model fallbacks.
  • LiteLLM virtual keysDocs · LiteLLMThe self-hosted option. Virtual keys with model allowlists and spend tracking, owned by users or teams, backed by your own Postgres.
Free · sign in to start

Sign in to keep reading.

Free, no card. We use your account to save progress, quiz scores, bookmarks and occasionally send updates from our team.

  • 10 more sections
  • 3 hands-on exercises
  • A 7-question quiz
  • Progress, quiz scores and bookmarks