Leanpub Header

Skip to main content

The AI Gateway Playbook

Building a Production LLM Gateway with Auth, Quotas, Cost Control, and MCP

The AI Gateway Playbook
This book is 100% completeLast updated on 2026-10-04

A practitioner's playbook for building an in-house LLM gateway: keyless auth, six-tier RBAC, quotas and budgets, per-token cost control, MCP at enterprise scale, and the operations to run it all. About 32,000 words with diagrams, configs, and checklists.

Minimum price

$19.00

$19.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
75
Pages
About

About

About the Book

Every organization that gets serious about LLMs eventually hits the same wall. API keys get hardcoded on laptops, extra keys appear because the first one got rate-limited, and months later the platform team discovers that the model bill has outgrown the team that owns it and that nobody can answer "who is spending what, on which model, for what feature?"

The AI Gateway Playbook is a practitioner's guide to the system that fixes that: an in-house LLM gateway. It is a thin, boring, auditable layer of infrastructure that sits between your codebase and every model provider, and treats model access the way any mature platform treats secrets, budget, and access control.

You will learn how to build:

  • A model registry that syncs models, availability, and pricing across multiple providers, so your code talks to stable aliases instead of vendor model IDs
  • A unified API surface with one wire protocol for chat, streaming, embeddings, and tool-calling
  • A keyless auth layer where no static LLM API key is ever issued to a human, using managed identities, on-behalf-of flows, and a six-tier RBAC model with per-role rate limits and daily token quotas
  • A metering and cost pipeline: token accounting per model, tenant, and user; budgets with soft and hard limits; dashboards and alerting; quota-increase approvals; and monthly reconciliation against provider invoices
  • An MCP server that exposes internal SaaS and office tools as Model Context Protocol tools at 90+ tool scale, secured with OAuth 2.1 + PKCE, envelope-encrypted secrets, PII masking, and a self-service portal
  • A RAG-based team assistant with a worked CI/CD failure-analysis example and an evaluation harness that keeps it honest
  • The operations layer: audit retention, key rotation without static keys, observability, incident runbooks, and deployment and migration checklists

Who this book is for: senior infrastructure and platform engineers, AI/ML platform engineers, DevOps engineers and SREs who will run the system, and tech leads or engineering managers who need to make and defend the build-vs-buy decision. The book is deliberately cloud-generic: components are described by role, so you can map the patterns onto your own stack.

What you get: about 32,000 words across eight chapters, plus front matter and an index. It is practitioner-oriented throughout, with architecture and sequence diagrams, YAML/JSON configs and code sketches, decision tables, a pitfalls section at the end of every chapter, and a full production-readiness checklist.

How this book was made: drafted with AI assistance from the author's hands-on experience designing and running an in-house LLM gateway; all examples are generic and anonymized.

Author

About the Author

Sanghyeok Y

DevOps engineer with 9+ years in infrastructure, Kubernetes, GitOps and AI infrastructure. Designed and ran an in-house LLM gateway in production. Writes practical guides for platform teams.

Translations

Translations

Languages

Contents

Table of Contents

  • Front matter: the pitch, who this book is for, how the book is organized
  • Chapter 1: Why Companies Outgrow Managed API Gateways for LLM Traffic
  • Chapter 2: Reference Architecture
  • Chapter 3: Keyless Auth and the Six-Tier RBAC Model
  • Chapter 4: Quotas, Budgets, and Cost Control
  • Chapter 5: MCP at Enterprise Scale
  • Chapter 6: RAG-Based Team Assistant
  • Chapter 7: Operations
  • Chapter 8: Production Readiness: The Full Checklist and the Pitfalls
  • Index

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub