P1526 min

LLM Serving & Inference

Most agents start by calling an API. Self-hosting is a different muscle — you become the SRE for inference. This lesson is the decision-and-assembly path: when self-hosting pays, then the engine, precision, parallelism, and benchmarking choices that turn a model checkpoint into a production endpoint.

SDK FocusOpenAI-compatible endpointsmodel routingfallback strategiescost tracking

The Serving Stack

Self-hosting is not one decision; it is a small stack of decisions that compound:

Serving stack: workload, engine, precision, parallelism, deployment, benchmark loopServing Decision Stackiterate1. Workload Profile2. Inference Engine3. Model Precision4. Parallelism5. Deployment Pattern6. Benchmark

The lesson walks through each layer in order. The benchmark step is what closes the loop — if you skip it, the rest are guesses.

Workload Profile: API vs Self-Hosted

The first question is whether to self-host at all. API providers (Anthropic, OpenAI, Google) handle every layer below for you. Self-host only when one of these is true:

text
Use API providers when:
  ✓ Low or bursty volume (often < 500K req/month unless prompts are very long)
  ✓ Need frontier model quality (GPT-5.x, Claude Opus/Sonnet, Gemini)
  ✓ Variable / unpredictable traffic
  ✓ No data residency requirements
  ✓ Team has no ML infra experience

Self-host when:
  ✓ High steady volume with a fixed model and high GPU utilization
  ✓ Strict data privacy / air-gapped environments
  ✓ Custom fine-tuned models that no API exposes
  ✓ Latency-critical (< 100ms first token)
  ✓ Predictable, steady traffic patterns

Cost crossover. Approximate June 2026 estimates, assuming ~1K input + 1K output tokens per request; re-derive these for your workload because both API and GPU prices move fast.

Premium lesson preview

Continue with full access

This lesson stays here for preview. Full access unlocks the complete lesson, flashcards, and related practice.

Sign In to Unlock

One purchase unlocks advanced lessons, practice, and future updates.