llm.guideChapter 1The AI Engineering Landscape

The AI Engineering Landscape

The four-layer stack, model tiers, API-versus-training math, and where durable advantage comes from.

Part 1: Orientation. 9 sections, about 10 minutes.

UXStreaming interfaces, human-in-the-loop designProduct layerRAG, agents, evals, guardrails, cost controlInference infrastructurevLLM, TensorRT-LLM, GPU clusters, hosted APIsResearchPretraining runs, post-training, papersmost of this guide lives here
UXStreaming interfaces, human-in-the-loop designProduct layerRAG, agents, evals, guardrails, cost controlInference infrastructurevLLM, TensorRT-LLM, GPU clusters, hosted APIsResearchPretraining runs, post-training, papersmost of this guide
The four layers of the AI stack. Most of this guide works in the second one, the product layer, where model capability becomes a dependable feature.

Before any mechanism, a map. Most confusion about AI products comes from mixing up layers, treating model names as a strategy, or underestimating how hard reliability is. This chapter fixes the vocabulary the rest of the guide relies on.

It covers the layer map, the model tiers, the cost arithmetic, the build-or-rent decision, the reliability gap, and where durable advantage comes from. There is no math beyond multiplication, and every number here is one you should be able to produce on the spot.

1.1Layer map

Know exactly which floor of the building you work on.

The stack has four layers, drawn at the top of this chapter. Research trains new models: pretraining runs, post-training, papers, done at frontier labs. Inference infrastructure makes trained models serve tokens fast and cheaply: vLLM, TensorRT-LLM, GPU clusters, and the hosted APIs themselves. The product layer is you: you take model capability through an API and turn it into a working feature, with retrieval, agents, evals, guardrails and cost control. UX sits on top: streaming interfaces and human-in-the-loop design.

Why it matters: it is easy to blur these layers and reach for research answers to product questions. “How do we improve answer quality?” almost never means retraining the model. At the product layer, the answers are retrieval quality, prompt structure and evals. The boundary with inference infrastructure is worth knowing well too: an API server in front of a vLLM instance sits exactly on it.

Common take“I’d fine-tune the model to make the answers better.”

Sharper take“I work at the product layer. My job is turning a stochastic API into a reliable feature, so I start with retrieval, prompts and evals.”

1.2Model landscape

Learn the shape, not the leaderboard.

Model names churn every few months; the structure is stable. Three frontier families dominate closed APIs (OpenAI’s GPT line, Anthropic’s Claude line, Google’s Gemini line), each shipped in tiers. In parallel, open-weight families such as Meta’s Llama, Mistral, Qwen, DeepSeek and Google’s Gemma let you download the weights and run them yourself. Most providers now also offer a reasoning or “thinking” mode that spends extra tokens before answering, covered in Chapter 10.

TierWhat it’s forTrade-off
FlagshipThe hardest requests: complex reasoning, long multi-step work, the cases your evals say smaller tiers failHighest capability, highest price, slowest
Mid-tier workhorseThe default for most product trafficThe best capability per dollar for general work
Small and fastClassification, routing, extraction, autocomplete, anything latency-critical at high volumeCheap and quick, but brittle on hard inputs
Open-weight, self-hostedData that can’t leave, steady huge volume, pinned behavior (section 1.4)You own the ops and the idle GPUs

The tier structure matters more than any model name because real products route: a cheap model for easy requests, a flagship for hard ones (Chapter 28). The shape of the market also tells you what to build defensively: if you hardcode one model, the provider will eventually deprecate it or change its behavior under the same name, and your prompts will silently regress in production. That failure mode is why Chapter 23 exists, and why model-agnostic design matters.

price per million tokens, log scale: roughly 5 to 10× per tiercapabilitySmall and fastrouting and extractionOpen weights, self-hostedpinned; you run the GPUsMid-tier workhorsethe default for most trafficFlagshipthe hardest requests
Figure 1.1 The shape of the market, with illustrative positions. GPT, Claude and Gemini each sell a model in all three closed tiers; the names change every few months, the shape does not. Products route between tiers by difficulty (chapter 28), so the tiers matter more than any model name.

Common take“I’d use the best model.”

Sharper take“The tier depends on the task’s difficulty, the latency budget and the volume. I’d start mid-tier, measure with evals, then route.”

1.3Capacity math

Why almost everyone rents a model instead of training one: do the capacity math.

Pretraining a frontier-class model costs on the order of $10M–$100M+ in compute, plus a research team, plus data pipelines. Calling an API costs a fraction of a cent to a few cents per request. The arithmetic to have at your fingertips: tokens per request × price per token × requests per month. With 2,500 tokens per request (say 2,000 in, 500 out) and a blended price of $10 per million tokens, each request costs 2.5 cents and a million requests cost $25,000 a month.

$10$1K$100K$10M10K100K1M10M100MAPI spend per monthrequests per monthone engineer’s salary
$100$10K$1M10K1M100MAPI spend per monthrequests per monthone salary
  • $1 per million tokens
  • $10 per million
  • $50 per million
  • one ML engineer’s salary, about $15K a month
Figure 1.2 Monthly API spend at 2,500 tokens per request for three illustrative blended prices spanning the tiers; plug in today’s list prices, the shape won’t change. Dots mark where the bill equals one ML engineer’s salary (about $15K a month): 6 million requests at $1, 600,000 at $10, and 120,000 at $50 per million tokens.

Two habits make this math credible. First, split input and output: output tokens are typically priced several times higher than input, and long prompts move the bill more than people expect (Chapter 11). Second, compare against people, not just against GPUs: below the salary line, engineering time is the expensive resource and you should spend tokens freely; above it, cost engineering pays for headcount (Chapter 28).

The conclusion, said the senior way: training from scratch is never on the table for a product team, and even fine-tuning has to justify itself against prompting plus retrieval first (Chapter 17). This is also the honest answer to the sneer “you’re just a GPT wrapper”: yes, the model is rented. The moat is everything wrapped around it (section 1.8).

Common take“Training our own model would give us an edge.”

Sharper take“At 2,500 tokens a request and $10 per million, a million requests is $25K a month. Training is never the first lever; routing and caching usually are.”

1.4Closed versus open-weight

Closed API versus open-weight self-hosting: a decision rule, not a religion.

Closed means you send tokens to someone else’s servers, pay per token, and get the frontier capability ceiling with zero ops. Open-weight means you run inference yourself, on a vLLM server for example, pay for GPUs whether they’re busy or idle, and control everything. Self-hosting pays its way when at least one of three things is true: data can’t leave (healthcare, banking, defense: compliance, not preference); volume is huge and steady, so per-token API cost exceeds GPU rental; or you need control, such as pinning a model version forever or meeting a strict latency budget. Otherwise the closed API wins on capability per engineering-hour.

$0.10$1$10$1002%10%30%100%cost per million tokensGPU utilization (log scale)closed mid-tier API: $10 per Msame open model on a hosted API: $0.20 per Mbreak-even near 5%self-hosting on one GPU
$0.10$1$10$1002%10%30%100%cost per million tokensGPU utilization (log scale)closed API $10/Mhosted open model $0.20/Mbreak-even near 5%self-hosting one GPU
Figure 1.3 Utilization decides. Assumes one rented GPU at $2.50 an hour sustaining 1,500 generated tokens per second at full load; your numbers will differ, but the shape won’t. Self-hosting beats a $10-per-million closed API above roughly 5% utilization, but it never beats the same open model served by a hosted provider at $0.20 per million, because that provider runs its GPUs far busier than you will.

Read the chart twice. The first lesson: idle GPUs burn money while idle APIs cost nothing, so self-hosting only wins at sustained volume. The second is subtler: self-hosting a small open model looks cheap next to a frontier API, but that’s not a like-for-like comparison. Your real cost competitor is often a hosted provider serving the same open weights, and your real quality question is whether the smaller model passes your evals at all.

Read the license before the architecture review, not after. Say “open-weight,” not “open source”: the weights are open, but the training data and recipe usually aren’t. Licenses vary widely. Some models ship under permissive licenses such as Apache 2.0; others use custom licenses that can carry acceptable-use policies, attribution or naming requirements, restrictions on using outputs to train other models, or thresholds on how many users you can serve before you need a separate agreement.

Common take“Open source is cheaper.”

Sharper take“Open-weight is cheaper above a utilization threshold and below a capability bar. Below that threshold I’m paying for idle silicon, and I compare against hosted providers of the same weights, not just against frontier APIs.”

1.5Reliability gap

The capability–reliability gap is the whole job.

LLM output is sampled from a probability distribution (Chapter 2 makes this mechanical), so the same input can produce different outputs, and impressive behavior on demo day is not dependable behavior at the 99th percentile. A demo needs the model to work once. Production needs it to work on the ten-thousandth strange input, at 2 a.m., while the provider has elevated latency. And the gap widens with every step a task takes:

0%50%100%15101520chance every step succeedssteps in the task99% per step: 82%95% per step: 36%90% per step: 12%0.95⁸ ≈ 66%
0%50%100%11020chance every step succeedssteps in the task99% per step: 82%95% per step: 36%90% per step: 12%0.95⁸ ≈ 66%
Figure 1.4 If each step succeeds independently with probability p, a task of n steps succeeds with probability pn. A step that works 95% of the time sounds production-ready; chain eight of them and the task works two times in three. This one curve is why agents need harnesses (Chapters 18 and 19).

That explains the industry’s open secret: the gap between “we built a prototype in a weekend” (true) and “we shipped it reliably” (months of evals, guardrails, fallbacks and observability, in Chapters 19, 23, 24 and 26). The war-story pattern: a support-bot demo wows the executive team; in production it confidently invents a refund policy, one screenshot goes viral, and the feature gets pulled. The failure wasn’t the model. It was shipping without grounding (Chapter 15) or evals (Chapter 23).

Common take“It worked every time we tested it.”

Sharper take“Demos prove capability; production requires reliability. The product layer’s entire job is closing that gap, and per-step reliability compounds.”

1.6Provider risk

You are renting a dependency that changes underneath you.

A hosted model is a third-party dependency with unusual failure modes. Models are deprecated on a schedule. Behavior can shift under the same name when an alias moves to a new snapshot. Rate limits and quota tiers cap your growth. Regional outages and elevated latency happen. Prices, refusal behavior and data-retention terms change. None of this is hypothetical, and none of it shows up in a demo.

The mitigations are ordinary engineering, applied deliberately:

  • Pin a dated model snapshot wherever the provider offers one, and upgrade on purpose.
  • Abstract provider calls behind one internal interface or gateway, so swapping models is a configuration change (Chapter 21).
  • Gate every model change on your eval suite, which turns a migration into an afternoon (Chapter 23).
  • Fall back to a second provider or a smaller model when the primary errors or slows down, and test the fallback before you need it (Chapter 19).
  • Watch per-provider error rates, latency and output-format failures, and alert on them (Chapter 24).
snapshot 2026-03snapshot 2026-07snapshot 2026-11alias “model-latest”silently points at the newestuntil this monthPina dated snapshotGatewayone internal interfaceEval gatebefore any changeFallbacka tested second providerMonitorerrors, latency, formatordinary engineering around a dependency that changes underneath you
Figure 1.5 An alias is a moving target: the same name can mean a different model next month. The mitigations below it turn that change into a decision you make.

Common take“The provider is reliable.”

Sharper take“I treat the model like any critical dependency: pinned, abstracted, monitored, and with a fallback I’ve actually tested.”

1.7Build for future models

Build for where models will be in six to twelve months.

Rich Sutton’s essay “The Bitter Lesson” argues that, over decades of AI research, general methods that ride on more compute have beaten hand-engineered cleverness. Applied to products, it becomes a design test: if the next model release were twice as capable, would this component become more valuable or unnecessary? Scaffolding that compensates for today’s weaknesses gets deleted by the next release; scaffolding that captures what only you have keeps compounding.

Compounds as models improveGets deleted by the next release
Eval suites and golden sets built from real failuresPrompt tricks tuned to one model’s quirks
Proprietary data and feedback loopsElaborate chains that work around weak reasoning
Integrations, permissions and workflow embeddingHand-written parsers for formats that structured outputs now guarantee
UX for verifying and correcting model outputRetrieval hacks that compensate for a small context window
Routing, caching and cost infrastructureFine-tunes that only teach what the next base model already knows

The same logic applies to economics. The price of a given level of capability has kept falling, so plan unit economics that improve as costs drop, but don’t bet the company on a specific future price (Chapter 31).

Price for GPT-3-level MMLU, $ per million tokens$100$10$1$0.10$0.012021: $602024: $0.06a thousand times cheaper in three yearsContext window, tokensGPT-3, 20202,048GPT-4 32K, 202332,768Claude 2.1, 2023200,000Gemini 1.5 Pro, 20242,000,000log scale
Figure 1.6 Published figures: the price drop for a fixed capability reported by Andreessen Horowitz (“LLMflation”, 2024), and context windows from the providers’ launch announcements. Both scales are logarithmic.

Common take“We built a twelve-step pipeline to get the model to reason properly.”

Sharper take“I build the parts that get more valuable as models improve and keep the workarounds thin, because the next release deletes them.”

1.8Where the moat is

Where the moat actually is: the honest answer to “anyone can call an API”

Everyone rents the same models, so differentiation lives in what only you have. Your evals: a golden set of real user queries with graded answers is proprietary and compounds, which is why Chapter 23 is called the differentiator. Your data flywheel: logged real interactions and feedback become better retrieval corpora, better examples and fine-tuning data (Chapter 25). Domain integration: the model wired into your database, your tools and your workflow permissions can’t be reproduced by a competitor with the same API key.

Users and real trafficTraces andfeedbackLabels andgolden setsBetter retrieval,prompts, fine-tunesA betterproductowned andcompounding
Figure 1.7 The flywheel. The two highlighted stages, traces and labels, are the ones a competitor can’t rent; they turn usage into an asset that improves with every turn.

Common take“Our moat is that we use the best model.”

Sharper take“Models are rented and commoditizing. Evals, the data flywheel and integration depth are owned, and they compound.”

1.9The AI engineering role

What the AI engineering role actually is.

Honest sizing of the title: an AI engineer is a backend or product engineer whose core dependency is a nondeterministic API. Not a researcher (no pretraining runs) and not a classic ML engineer (no feature pipelines), though the boundaries blur at fine-tuning (Chapter 17), and the role reaches into product and business decisions (Part 7). The skill set is this guide: model mechanics, APIs, retrieval, agents, evals, security, cost and observability, glued onto backend craft you already have.

Three habits from this chapter separate durable AI engineering from hype: knowing which layer a problem lives in (section 1.1), reasoning in tiers and trade-offs rather than brand names (sections 1.2 and 1.4), and respecting why production is hard (section 1.5). The rest of the guide turns each of them into working practice.

Softwareengineeringbackend, APIs,tests, operationsML engineeringtraining, features,pretraining runsProductdesign, costAI engineeringevals, fine-tuning,a nondeterministic API
Figure 1.8 Where the role sits. Most of the daily work is software engineering; it meets machine learning at fine-tuning and evaluation, and product work at design and cost.

Key takeaways

  • I work at the product layer: my job is turning a stochastic API into a reliable feature.
  • Demos prove capability; production requires reliability. Closing that gap is the job.
  • Models are rented; evals and the data flywheel are owned. That’s the moat.
  • Open-weight wins above a utilization threshold and below a capability bar. Otherwise, APIs win on capability per engineering-hour.
  • Model names churn quarterly. I design model-agnostic and let evals pick the model.
  • I treat the model provider like any critical dependency: pinned, abstracted, monitored, with a tested fallback.
  • I build the parts that get more valuable as models improve, and keep the workarounds thin.

Check your understanding

  1. Your startup’s support bot runs on a closed flagship API. Finance flags the bill: $40K a month and growing. The CEO says “self-host Llama, it’s free.” Walk through the actual decision: what you measure, the break-even logic, and the capability risk you flag.

    Answer outline

    Measure tokens per month by route, the traffic shape (peaks versus average), and quality: run the candidate open model on the golden set, slice by slice. Do the math: at a $10-per-million blended price, $40K is about 4 billion tokens a month, roughly 1,500 tokens per second on average; peaks need several times that, so plan three or four GPUs plus the engineers who run them. Before any of that, try the cheaper levers: routing easy traffic to a small tier and prompt caching often cut the bill substantially (Chapter 28). Compare against hosted providers of the same open model too. Flag the capability risk (smaller models fail hard slices), the ops cost (on-call, GPU supply), and the one factor that can override the math: data that can’t leave.

  2. A provider ships a silent model update. The same prompt now formats answers slightly differently, and a downstream JSON parser starts failing 5% of requests at 3 a.m. Which layer did the failure originate in, which layer has to fix it, and what two things from later chapters would have caught it before users did?

    Answer outline

    It originated in the provider’s layer (a behavior change under an unchanged name), but the product layer has to fix it, because that’s the layer that owns reliability. Fixes: structured outputs with schema validation and retry-with-feedback (Chapters 11 and 19), and a pinned snapshot. It would have been caught by a scheduled eval run against the provider that tests output format (Chapter 23), and by monitoring parse-failure rate with an alert (Chapter 24).

  3. A skeptical investor says: “You’re just a thin wrapper around someone else’s model. Why shouldn’t that worry us?” Give a strong answer, including what compounds and what doesn’t.

    Answer outline

    Concede the true part: the model is rented, and its price per unit of capability keeps falling, so model access is not a moat. Then name what compounds: a golden set built from real user failures, proprietary interaction and feedback data, deep integration into customer systems and permissions, and workflow ownership. Name what doesn’t: prompts, the choice of model, and a thin UI. Close with section 1.7: you invest in the components that become more valuable when the next model ships.

Further reading

  • Chip Huyen, AI Engineering: chapter 1, which frames the AI stack in three layers (application development, model development, infrastructure). The product layer here corresponds to her application layer.
  • Rich Sutton, “The Bitter Lesson”, a one-page essay behind section 1.7.

↑↓ to move↵ to openesc to close