AI EngineeringZero to ProductionHome·About·What’s new·Contact
Enterprise & Leadership · Part 2

Buy vs build & model selection

The most expensive AI decisions are made before any code is written: API vs fine-tune vs build, which vendor, and how do we get out if it goes wrong. This lesson gives you a repeatable framework — a decision flow, a vendor scorecard, a total-cost-of-ownership model, and an explicit lock-in and exit strategy — so these choices are defensible rather than fashionable. Frameworks and public pricing structures are attributed; costs are illustrative and must be verified against current vendor pricing.

⏱️ ~90 min🏢 Org / decision layer🎯 Lead / staff

Learning objectives

  • Choose deliberately between API, fine-tuning, and build-from-scratch using a decision flow tied to your actual constraints.
  • Score vendors and models with a weighted scorecard instead of a demo-driven gut call.
  • Build a total-cost-of-ownership (TCO) model that includes the costs teams forget.
  • Reason explicitly about vendor lock-in and design an exit strategy before you sign.
  • Present the recommendation as a decision a skeptical exec or board can approve.
Honesty note on numbersThe frameworks here are real and durable. Every dollar figure and rate is illustrative and drifts fast — verify against current vendor pricing pages before you commit. Vendor names are used generically to describe categories of offering; nothing here is an endorsement or a claim about a specific contract.

1 · The four options, honestly framed

Here's the meeting that goes wrong in a thousand companies. Someone demos a slick AI feature to leadership; everyone's excited; and then a senior engineer says the words that derail the next six months: "We should just build our own." Nobody in the room agrees on what "build" even means — one person pictures pre-training a model, another pictures fine-tuning, a third is thinking about self-hosting an open-weight model, and the exec is quietly wondering why they can't just call an API. They argue for weeks because they never named the actual choices. This section exists to make that never happen to you.

Think of it like housing, because you've already made this decision in your own life. You can rent an apartment (move in tomorrow, someone else fixes the plumbing, you pay monthly forever and can't knock down a wall), lease-and-renovate (customize the space but you don't own the building), or buy land and build a house from foundation up (total control, and a multi-year project with a construction crew you now employ). Nobody sane builds a house because they want a place to sleep next week — they rent. And nobody rents forever if they're running a hotel at massive scale. The right answer is entirely about your constraints, not about which option sounds most impressive in a meeting.

The AI version has the same shape, and the key word is ownership: the more of the stack you own, the more control and (eventually) the more cost-leverage you get — but the more you also own the burden of building, running, and maintaining it. The most expensive mistake in this whole topic is treating it as a binary — "buy" (call someone's API) versus "build" (do everything ourselves) — when in reality there's a continuous spectrum with at least five distinct stops, each winning under different conditions. The table below lays them out from least ownership to most. As you read it, resist the pull toward the right-hand columns: more ownership feels like maturity and independence, but for the overwhelming majority of teams the correct answer sits at the top of the table, and the whole rest of this chapter is machinery for proving that to yourself and to a skeptical board.

There is a spectrum, not a binary. From least to most ownership:

Hosted API a prompt + integration API + retrieval context + orchestration Fine-tune / adapter a model artifact Self-host weights weights + serving stack Build from scratch everything + pre-train ← most teams belong here more ownership + burden → A spectrum, not a binary. Five distinct stops, not two. Ownership and cost-leverage rise to the right — but so does the burden of building and running it, which is why the correct answer for most teams sits at the green left end.
🗺️ How to read this diagram

Read the five boxes left to right; the arrow underneath tracks how much of the stack you own as you move rightward.

  • The green box on the far left (Hosted API) is the least ownership — you own only a prompt and an integration. Each box to the right hands you more of the stack: context, then a model artifact, then the weights and serving, then everything.
  • The colors grade the burden: green is the low-effort default, plain boxes are moderate, the amber self-host box means a real infra team, and the red build-from-scratch box means a nine-figure research effort.
  • The arrow is the payoff to notice: more ownership brings more control and eventual cost-leverage, but the burden grows with it — so "further right" is not "more mature," it is "more expensive to own."

In short: Five stops on one axis; the right answer is whichever the constraints demand, and for most teams that is the green left end.

OptionWhat you ownWhen it winsThe real cost
Hosted APIA prompt and an integration.Fastest to value; frontier quality; variable load.Per-token spend; data leaves your boundary; provider dependency.
API + retrieval/promptingContext and orchestration.You need your data, not new model behavior.Same as API plus your retrieval infra.
Fine-tune / adapterA customized model artifact.Consistent format/style/domain; smaller model can hit quality.Data prep, training, eval, and re-tuning as base models move.
Self-host open weightsThe weights and the serving stack.Residency/air-gap; high steady volume; no egress allowed.GPUs, MLOps, on-call — a real infra team.
Build from scratchEverything, including pre-training.Almost never, for almost everyone.$millions and a research org — a moat only if the model is the business.
"Build" almost never means pre-trainWhen a team says "let's build our own," they usually mean fine-tune or self-host an open-weight model — not pre-train a foundation model. Pre-training a competitive base model is a nine-figure research effort. Naming the option precisely is half the decision: most "build vs buy" debates are really "API vs fine-tune vs self-host."

2 · A decision flow that ends the debate

You've seen a debate like this eat a whole quarter. Two smart people argue "API vs self-host" for weeks, each marshaling cost spreadsheets and quality anecdotes, and the argument never converges — because they're weighing everything at once, trading a cost point against a quality point against a latency point, with no agreed order. The fix is almost embarrassingly simple: stop optimizing and start eliminating. Most of these decisions aren't decided by the close call at the end; they're decided by a single hard constraint near the beginning that quietly removes most of the options before you ever compare prices.

The mental model is airport security versus a talent competition. A weighted scorecard (the next section) is a talent competition — everyone performs, you tally points, best average wins. But a decision flow is security screening: there are a few things that get you rejected at the door no matter how brilliant you are elsewhere. If your data legally cannot leave your network, it does not matter that the hosted API is cheaper, faster, and higher quality on every axis — it's disqualified at the first gate. A constraint like that isn't a factor to be weighed; it's a filter that decides the outcome by itself. Confusing the two — treating a hard legal or residency constraint as just another column with a weight — is exactly how teams talk themselves into an option they'll have to rip out during an audit.

So the discipline is: run your constraints in priority order, hardest and least-negotiable first, and let the first one that bites make the decision. This mirrors how the clinical case study resolved — the PHI (protected health information) constraint settled the deployment target before anyone got to argue about model quality. Only after the hard constraints have pruned the tree do you switch modes and optimize the survivors on the soft, tradeable things: cost, latency, quality. The flow below is that pruning made visible; read it left to right as a sequence of gates, not a menu.

Run the constraints in priority order — the first hard constraint that bites usually decides it, the same way the PHI constraint decided deployment in the clinical case study. Read the flow as: eliminate on hard constraints first, then optimize on cost and quality.

Data can leave? no→self-host Need new behavior? behavior→tune Volume steady + high? yes→self-host? Quality bar frontier? Choose decide
🗺️ How to read this diagram

Read it strictly left to right as a sequence of gates: each box asks one question, and the blue arrow only carries you onward once that constraint has been applied.

  • The first box asks "Data can leave?" — its sub-label no→self-host is the hardest gate: if the answer is no, you're pushed to self-host before cost or quality ever get a vote.
  • The middle boxes ask the next constraints in priority order — "Need new behavior?" (behavior→tune, distinguishing fine-tuning from retrieval), then "Volume steady + high?" (yes→self-host?, the amortization test), then "Quality bar" (frontier?) — each blue arrow passing the survivors to the next question.
  • The last box, "Choose" (decide), is the payoff: you only reach it after every hard constraint has pruned the options, so what's left is decided on the soft, tradeable things — cost, latency, quality.

In short: Eliminate on hard constraints first, left to right; the first gate that bites usually decides it, and only the survivors reach the final "Choose".

Worked reading of the flow: (1) If data legally cannot leave your boundary, you are pushed toward self-hosting regardless of cost. (2) If you need your own knowledge in answers, that's retrieval on top of an API — not fine-tuning; fine-tuning teaches behavior (format, tone, a narrow task), not facts. (3) Only steady, high volume amortizes the fixed cost of a serving team. (4) If your quality bar needs the current frontier, that usually means a hosted or managed-cloud frontier model, since your self-hosted open weights will trail it.

3 · The vendor / model scorecard

Every engineer has watched a decision get made by a demo. A vendor shows up, runs three cherry-picked prompts that dazzle the room, drops a benchmark chart where their model tops a public leaderboard, and suddenly the "decision" is made in the hallway afterward on vibes. Six months later you discover the model is mediocre on your actual workload, the pricing balloons at your real volume, and the impressive demo used a prompt nobody could reproduce. The demo was theater — and theater is designed to move you emotionally, not to inform a decision you'll have to defend to a board.

The antidote is the same tool a good hiring panel uses to avoid hiring the most charming candidate instead of the most capable one: a rubric you commit to before you meet anyone. A weighted scorecard forces two acts of honesty. First, it makes you write down what you actually value and how much — quality, cost, latency, security, portability — as explicit percentage weights that sum to 100. Second, it makes you score every candidate on the same axes, so a vendor who's brilliant at the one thing they demoed can't win on that alone. The number that falls out isn't magic, but it is legible: anyone can see why the winner won.

Here is the discipline that makes it work, and the one people skip: assign the weights first, before you've seen a single score. The reason is a well-documented human failing — motivated reasoning. If you set weights after you've fallen for a vendor, you'll unconsciously tune them to make your favorite win ("well, latency is actually the most important thing, and look, they're fastest"). Locking the weights in advance turns the scorecard from a rationalization engine into an honest one. The dimensions and starting weights below are a sensible default for a typical enterprise workload; treat them as a template, adjust the weights to your reality (a regulated industry pushes data-posture weight up; a latency-critical product pushes latency up), but adjust them before the demos start, not after.

Demos are theater; a weighted scorecard forces you to state what you actually value and score every candidate on the same axes. Assign weights first (before you see scores) so you can't rationalize your favorite afterward.

weights set FIRST, must sum to 100% Quality (your evals) 25% Cost at volume 20% Latency / throughput 15% Data & security 15% Reliability / SLA 10% Lock-in / portability 10% Roadmap / support 5% Σ = 100% · score every vendor on the SAME axes What you value, made explicit. Seven bars whose lengths are the weights you commit to before any demo. Quality-on-your-evals is longest by design; the bars must sum to 100%, and every vendor is scored on the identical axes.
🗺️ How to read this diagram

Read top to bottom; each bar's length is how much that dimension counts, and the percentages down the right add up to 100.

  • Each row is one scorecard dimension; the bar length is its weight — longer bar, more it matters to the final number.
  • The longest bars sit at the top: quality-on-your-evals (25%) and cost-at-volume (20%) dominate, while roadmap (5%) is a thin sliver — a vendor can't win on a minor axis alone.
  • The payoff is the Σ = 100% line: because the weights are fixed in advance and sum to a whole, you can't quietly re-weight to make a favorite win — the scorecard becomes an honest tally instead of a rationalization.

In short: Longer bar = more weight; lock the bars before the demos and score everyone identically.

DimensionWeightWhat you're really measuring
Quality on your evals25%Score on your task set, not a public leaderboard.
Cost at your volume20%Blended $/request at projected load — verify current pricing.
Latency / throughput15%p95 latency and tokens/sec under your concurrency.
Data & security posture15%Retention, training-on-your-data toggle, region, certifications.
Reliability / SLA10%Uptime history, rate limits, incident transparency.
Lock-in / portability10%How hard is it to leave? (see §5)
Roadmap / support5%Model cadence, deprecation policy, enterprise support.
Score on your own eval set or don't score at allThe single highest-leverage move is a held-out eval set of your real tasks. Public benchmarks tell you almost nothing about your workload; a 50-example eval you wrote in an afternoon tells you almost everything. Weight "quality on your evals" highest and make every vendor run the same set.

4 · Total cost of ownership — the costs teams forget

Picture the slide that wins the room and loses the year. An engineer puts up two numbers: the API costs $0.004 per request, and a GPU we could rent costs $3,000 a month. At our volume the API bill is $X, and — look — self-hosting is cheaper. Heads nod, the plan is approved, and eighteen months later the "cheaper" option is costing three times what the API ever did. Nothing on that slide was a lie. It was just radically incomplete — and incomplete cost models are the single most common way smart teams talk themselves into the wrong build decision.

The trap has a name from any car buyer: the difference between the sticker price and the total cost of ownership. The sticker on the windshield is the purchase price; TCO is what the car actually costs you over the years you own it — insurance, fuel, maintenance, the mechanic on speed-dial, depreciation, and the Saturday afternoons you spend dealing with it. A cheap car with expensive parts and terrible reliability can easily cost more to own than a pricier one that just works. Nobody who has owned a car twice confuses the two numbers again. Yet in AI infrastructure, the sticker price — per-token spend or GPU-hour — is exactly the number people quote, and the ownership costs are exactly the ones they forget.

So what's hiding below the sticker? For a self-host path it's the whole iceberg under the GPU line: the loaded salary of the MLOps engineers who build and babysit the serving stack (loaded means salary plus benefits, taxes, equipment — often 1.3–1.4× base), the on-call rotation that keeps a critical service alive at 3 a.m., the upgrade and re-tuning treadmill as base models improve and your adapters go stale, and the opportunity cost of months spent on infrastructure before the feature delivers a dollar of value. The API path has forgotten costs too — integration effort, eval-set upkeep, re-testing every time the provider ships a new model — but they're a fraction of the self-host burden. The table below sorts the buckets across both paths. Read it as a checklist: the honest cost of an option is the sum of every row, not the one row that fit on the exciting slide, and §4's warning box shows why this pushes the self-host break-even point much later than engineers hope.

The sticker price (per-token or GPU-hour) is the cost people quote. TCO is the cost they actually pay. A defensible model includes:

monthly request volume → total cost → API (per-token) self-host fixed cost crossover API cheaper self-host cheaper Where the lines actually cross. The API line starts at zero and climbs with every request; the self-host line starts high (fixed GPU + loaded MLOps salary + on-call) and climbs slowly. Only past the red crossover does self-host win — and adding the forgotten costs pushes that crossover far to the right.
🗺️ How to read this diagram

Read left to right along the volume axis, and compare which of the two lines is lower at any given volume — lower means cheaper.

  • The blue API line starts at the origin because it is pure per-request spend: zero volume costs nothing, and every request adds a little. It rises as a straight, steep line.
  • The amber self-host line starts high up the vertical axis — that offset is the fixed monthly cost (GPUs, a loaded MLOps salary, on-call) you pay before serving a single request — then climbs only gently.
  • The red dot is the payoff: the crossover volume where the lines meet. To its left the API line is lower (API is cheaper); only to its right is self-host cheaper. The costs teams forget all raise the amber line, sliding that crossover rightward.

In short: API wins below the crossover, self-host above it — and honest TCO puts the crossover much further right than a GPU-vs-token spreadsheet suggests.

Cost bucketAPI pathSelf-host path
Direct inferencePer-token spend at projected volumeGPU rental/purchase + power
EngineeringIntegration + prompt/eval upkeepServing stack, autoscaling, upgrades
On-call / opsMostly the vendor's problemYours — 24/7 for a critical service
Data & evalEval set upkeepSame, plus fine-tune data pipeline
Migration / re-tuneRe-test on model updatesRe-tune adapters as base models move
OpportunityTime-to-value is fastMonths of infra before first value
The crossover point is later than engineers hopeSelf-hosting looks cheaper on a spreadsheet that counts only GPU-hours vs per-token spend. Add a loaded MLOps salary, on-call, and re-tuning, and the break-even volume is far higher than the naive calculation. Compute the crossover volume honestly: below it, the API wins on TCO even when its per-request price looks high. (Plug in current prices — the crossover moves every time either side changes.)

5 · Lock-in and the exit strategy

The worst version of this story starts with good news. Your AI feature is a hit. Then, at renewal, your provider quietly raises prices 40% — or deprecates the exact model your prompts were tuned to with 90 days' notice — or a new compliance rule says that model's region won't do. You go to switch, and discover you can't: your prompts are hand-fitted to one model's quirks, your tool-calling uses a vendor-specific format, your fine-tuned adapter only runs on their stack, and your embeddings live in a store you can't easily export. You're not a customer anymore; you're a hostage. That's vendor lock-in, and the time to deal with it is the day you sign — never the day you want to leave.

The useful way to think about lock-in is that it's coupling, the same disease software engineers already know to fear. When two parts of a system know too much about each other's internals, you can't change one without breaking the other; when your application knows too much about one provider's specific API, you can't change providers without a rewrite. And just as in code, the cure is not to avoid depending on anything — you can't, you have to ship — but to route the dependency through a seam you control. Lock-in comes in four flavors worth naming so you can spot each: prompt/behavior coupling (prompts fitted to one model's personality), proprietary features (a vendor-only tool, format, or endpoint with no standard equivalent), fine-tune artifacts (an adapter married to one serving stack), and data gravity (embeddings and indexes so large or so awkward to export that moving them is its own project).

Here's the mindset shift that separates teams who stay free from teams who get trapped: you design the exit before you need it, and you rehearse it. An escape route you've drawn on a whiteboard but never actually driven is a hope, not a plan — the parking-brake analogy is a fire drill you never run. Concretely that means an abstraction layer so swapping providers is a config change, a provider-agnostic eval set so you can re-qualify a challenger in a day, avoiding one-way proprietary formats where an open standard exists, and keeping the data you'd need to re-tune elsewhere. And here's the part that surprises people: the point of all this usually isn't to actually leave. It's that a credible, tested ability to leave is your single strongest piece of negotiating leverage on price and terms at every renewal. A vendor who knows you can walk away in a week treats you very differently from one who knows you're stuck.

Every choice creates dependency; the question is whether you can leave when you need to. Sources of lock-in: prompt/behavior coupling (prompts tuned to one model's quirks), proprietary features (a vendor-specific tool or format), fine-tune artifacts (an adapter you can't move), and data gravity (your embeddings/indexes in one store). You reduce lock-in the same way you reduce coupling in code: an abstraction seam and a tested escape route.

Your app business code LLMClient the seam you own swap = config change Provider A adapter Provider B adapter Provider C adapter 4 lock-in sources the seam contains: prompt · proprietary · fine-tune · data gravity Route the dependency through a seam you own. Business code calls one internal LLMClient; each provider hides behind an interchangeable adapter. Swapping providers becomes a config change plus an eval re-run — which is exactly what turns the four lock-in sources into contained, escapable risks.
🗺️ How to read this diagram

Follow the arrows left to right: your app never talks to a vendor directly, only to the seam, which then fans out to interchangeable adapters.

  • The left box is your business code. It calls only the green middle box, LLMClient — the abstraction seam you control — never a vendor SDK.
  • The three stacked boxes on the right are provider adapters. Because they all implement the same LLMClient interface, they are interchangeable: switching providers is a config change, not a rewrite.
  • The payoff is the amber line at the bottom: the four sources of lock-in — prompt coupling, proprietary features, fine-tune artifacts, and data gravity — are all things the seam contains, so a credible, tested ability to leave stays intact (and becomes your renewal leverage).

In short: One seam in the middle turns "we're a hostage" into "swapping providers is a config change and an eval re-run."

Design the exit before you signPractical portability moves: put an abstraction layer between your app and the model API so swapping providers is a config change; keep your eval set provider-agnostic so you can re-qualify a challenger in a day; avoid one-way proprietary formats where a standard exists; and keep the data you'd need to re-tune elsewhere. You may never leave — but the credible ability to leave is also your negotiating leverage on price and terms.

✓ Checkpoint — you can move on when you can…

  • State the five points on the buy-vs-build spectrum and one situation where each wins.
  • Explain why fine-tuning is the wrong tool for adding your company's knowledge.
  • Assign weights to a vendor scorecard and justify why quality-on-your-evals is weighted highest.
  • List three TCO buckets an engineer typically forgets, and say why the self-host crossover is later than it looks.
  • Name two sources of lock-in and the abstraction that mitigates each.
✓ Knowledge check

A stakeholder says: "Our support answers are wrong because the model doesn't know our products. Let's fine-tune it on our docs." Why is fine-tuning likely the wrong first move, and what would you propose instead?

Show answer
Fine-tuning teaches behavior — style, format, a narrow task — not facts, and facts learned by fine-tuning go stale the moment your docs change and are hard to cite. The symptom ("doesn't know our products") is a knowledge problem, which is what retrieval (RAG) solves: keep the docs in a store, retrieve the relevant chunks, and have the model answer from them with citations. It's cheaper, updates instantly when docs change, and is auditable. Reserve fine-tuning for when you've proven RAG works but need consistent formatting or a smaller/cheaper model to hit the same quality.
✓ Knowledge check

Two vendors are within 3% on your eval set. Vendor A is 20% cheaper today; Vendor B has a documented deprecation policy, region controls, and a clean abstraction path. Which do you lean toward, and how do you defend it to a cost-focused exec?

Show answer
Lean toward Vendor B, and defend it on TCO and risk, not sticker price. A 20% per-token saving is real but small next to the cost of an unplanned migration when a model is deprecated with no notice, or a compliance failure because you couldn't control region/retention. The scorecard weights lock-in, data posture, and reliability precisely so a cheap-but-fragile option can't win on price alone. Frame it to the exec as: "The 3% quality gap is noise, the 20% price gap is ~$X/year, and the switching/compliance risk we'd take on with A is a low-probability, high-severity cost that dwarfs $X." If A closes the governance gap, revisit — verify both prices against current pages.

🪜 Practice ladder beginner → industry

Six graded exercises, easy to real-world. Try each before opening its solution.

Exercise 1 · Name the right option for five scenariosBeginner

Context: The first skill is refusing the false binary and naming the precise option.

Your task: For five representative scenarios, name the best option on the buy-vs-build spectrum and one sentence of justification.

Requirements:

  • A) A startup wants a support bot live in two weeks
  • B) A bank cannot let any customer data leave its network
  • C) A team needs outputs always in a strict JSON schema in a niche style
  • D) A hobby project answers ~50 questions a day
  • E) A company's entire product IS a novel foundation model

💡 Hint: Match the option to the dominant constraint: speed, residency, behavior, volume, or moat.

Show solution

A) Hosted API + prompting. Speed-to-value dominates; frontier quality out of the box, no infra.

B) Self-host open weights. A hard residency/egress constraint vetoes external APIs regardless of cost — accept the ops burden.

C) Fine-tune / adapter. The need is consistent behavior (schema + style), which is exactly what fine-tuning is for; likely on top of a smaller model to save cost.

D) Hosted API. 50 requests/day will never amortize a serving team; per-token spend is trivial.

E) Build from scratch (pre-train). The one case that justifies it — the model itself is the differentiated product and the moat. Almost no one else.

Exercise 2 · Fill and total a vendor scorecardIntermediate

Context: A weighted scorecard turns a demo-driven argument into a defensible number.

Your task: Score two candidate models on the seven scorecard dimensions and compute a weighted total, then state the decision.

Requirements:

  • Use the weights from §3 (they must sum to 100%)
  • Invent plausible per-dimension scores (0–10) for two candidates
  • Compute each weighted total and pick a winner
  • Note what single dimension, if it changed, would flip the decision

💡 Hint: Set weights before scores; compute weighted sum = Σ(weight × score).

Show solution

Representative fill (scores 0–10):

Dimension (weight)Model AModel B
Quality on our evals (25%)98
Cost at volume (20%)69
Latency (15%)78
Data/security (15%)87
Reliability (10%)87
Lock-in (10%)68
Roadmap (5%)87

Weighted totals: A = .25·9+.20·6+.15·7+.15·8+.10·8+.10·6+.05·8 = 7.50. B = .25·8+.20·9+.15·8+.15·7+.10·7+.10·8+.05·7 = 7.90. Winner: Model B, driven by cost and portability despite A's edge on raw quality.

Flip point: the quality gap is small — if our evals showed A leading by ~2 points instead of 1, or if cost weight dropped below ~12%, A would win. That sensitivity is the honest output of the scorecard.

Exercise 3 · Build a TCO model and find the crossover volumeAdvanced

Context: The self-host-is-cheaper argument usually dies when you add the forgotten costs.

Your task: Build a TCO comparison of an API path vs a self-host path and solve for the monthly request volume at which self-host becomes cheaper.

Requirements:

  • API path: a per-request blended cost (verify against current pricing)
  • Self-host path: fixed monthly infra + a loaded fraction of an MLOps engineer + on-call
  • Write the crossover equation and solve for volume
  • State the honest caveat about how the crossover moves

💡 Hint: Crossover: API_per_req × N = fixed_self_host_monthly ⇒ N = fixed / per_req.

Show solution

Illustrative model (verify all numbers). API: assume $0.004 blended per request. Self-host fixed monthly: GPU $3,000 + ~40% of a $200k-loaded MLOps eng ≈ $6,700 + on-call/upgrades $1,300 = $11,000/month fixed, roughly volume-independent until you saturate the box.

Crossover. Self-host wins when fixed < API·N ⇒ N > $11,000 / $0.004 = 2.75 million requests/month (~92k/day). Below that, the API is cheaper on TCO even though its marginal price looks high.

Caveats: the crossover collapses if you already run an MLOps team (fixed cost is sunk), and it rises if throughput per GPU is lower than assumed or if re-tuning is frequent. Every input drifts — recompute with current GPU and token prices, and don't quote a crossover you computed six months ago.

Exercise 4 · Design a provider-abstraction seam + exit planExpert

Context: Lock-in is a coupling problem; the fix is an abstraction seam and a tested escape route.

Your task: Design the abstraction layer and exit plan that keeps you portable across model providers.

Requirements:

  • Define the interface your app calls instead of a vendor SDK directly
  • List what the adapter normalizes (auth, message format, tool-calling, streaming, errors)
  • State how your eval set stays provider-agnostic
  • Describe the drill that proves you can actually switch

💡 Hint: The seam should make 'swap provider' a config change plus a re-run of your eval set.

Show solution

Interface. The app calls a single internal LLMClient.complete(messages, tools, opts); provider SDKs live only behind adapters implementing it. No vendor type leaks into business code.

Adapter normalizes: auth/config, message/role format, tool-calling schema (the biggest source of divergence), streaming events, token-usage reporting, and error/retry semantics (rate limits, refusals). Prompts live as versioned templates, not inlined per model.

Provider-agnostic evals. The eval harness targets LLMClient, so any provider runs the identical task set; you re-qualify a challenger in an afternoon, not a quarter.

The switch drill. Quarterly, run the full eval set against a second provider through its adapter and record quality/latency/cost. This proves the seam still works, keeps a warm fallback for an outage or deprecation, and gives you real leverage at renewal. An escape route you've never tested is a hope, not a plan.

Exercise 5 · Write the buy-vs-build recommendation memoProfessional

Context: The deliverable of this whole decision is a one-page memo an exec can approve.

Your task: Write the recommendation memo for a representative 'add an AI assistant to our product' decision.

Requirements:

  • State the recommendation up front (BLUF)
  • Summarize the decision flow result and the scorecard winner
  • Show the TCO at projected volume and the crossover
  • Name the lock-in risk and the exit plan in one paragraph
  • State what would change the recommendation

💡 Hint: Lead with the decision; put the analysis underneath for those who want it.

Show solution

Recommendation (BLUF): Build the assistant on a hosted frontier API + retrieval, behind our provider-abstraction layer, with a fine-tune deferred until RAG quality is proven. Do not self-host at current volume.

Why. Decision flow: data can leave under our enterprise agreement; the need is our knowledge (→ retrieval, not fine-tune); volume (~200k req/month) is well below the ~2.75M self-host crossover. Scorecard winner: Model B (7.9 vs 7.5), driven by cost and portability.

TCO. ~$800/month inference at projected volume + existing eng time, vs ~$11k/month fixed to self-host — API wins decisively until we ~14× our volume.

Lock-in / exit. Risk is prompt+tool coupling to one provider; mitigated by the abstraction seam and a quarterly switch drill against a second provider, keeping a warm fallback and renewal leverage.

What would change this: a hard residency mandate (→ self-host), a 10×+ volume jump past the crossover (→ revisit self-host), or a proven need for behavior RAG can't give (→ fine-tune). All numbers verified against current pricing as of the memo date.

Exercise 6 · Adjudicate a contested build-your-own proposalIndustry scenario

Context: Representative scenario: an ambitious staff engineer proposes the company self-host and fine-tune an open-weight model to 'own our AI stack and cut costs.' Leadership asks you to adjudicate.

Your task: Evaluate the proposal rigorously and issue a decision with conditions, respecting that the engineer may be right.

Requirements:

  • Steelman the proposal — when would it actually be correct?
  • Run it through the decision flow and TCO honestly
  • Identify the hidden costs and the key assumption the case rests on
  • Issue a decision: proceed / pilot / decline, with measurable conditions
  • Say how you'd de-risk if you proceed

💡 Hint: The right answer might be 'not yet' with a concrete trigger, not a flat no.

Show solution

Steelman. Self-hosting is genuinely correct if volume is high and steady, if there's a residency/egress constraint, or if the company already runs an MLOps team so the fixed cost is sunk. "Own our stack" also has real strategic value if AI is core to the product.

Decision-flow + TCO reality. Absent a residency mandate, the case rests entirely on volume clearing the crossover (~2.75M req/month in our illustrative model). Current volume is ~200k/month — 14× short. The "cut costs" claim compares GPU-hours to token spend and omits a loaded MLOps salary, on-call, upgrades, and re-tuning as base models move. Corrected, self-host is more expensive today, not less.

Hidden costs / key assumption. The proposal assumes a fine-tuned open model matches frontier quality on our tasks — unverified. It also assumes throughput per GPU we haven't measured. Both are testable.

Decision: decline as a full migration, approve a bounded pilot. Fund a 3-week pilot to (1) fine-tune the candidate and measure it on our held-out eval set vs the incumbent API, and (2) measure real throughput/GPU. Trigger to revisit self-host at scale: sustained volume past ~60–70% of the crossover or a residency mandate.

De-risking if we later proceed: keep the abstraction seam so the API stays a fallback, roll out behind a traffic split, and don't retire the API contract until the self-host path holds quality and reliability for a full quarter.

© 2026 studybydoing.in · AI Engineering: Zero to Production · All rights reserved. · About · Privacy Policy · Terms · Contact
Educational content, provided as-is and without warranty. Code samples are examples — review, test, and adapt them before using in production. See the Terms of Use & Disclaimer. Use at your own risk.
© studybydoing.in