Interview's MateAI Engineering
Interview's Mate

AI Engineering

LLMs, RAG, agents & evals

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
AI Engineering topics
Lesson 20/ 160
01. LLM Fundamentals

Open vs Closed Models

API providers vs self-hosted open weights: control, cost, compliance, and quality trade-offs.

BeginnerAPI vs Self-host · Compliance3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidHands-onQuiz (3)Practice

In plain words

Closed models are like using a service over the internet. Open models are ones you can download and run yourself.

Think of it like…

Renting a car with a driver versus buying your own car. The driver service gets you moving today with no maintenance and the latest model, but you pay per trip, accept their rules and can't see under the bonnet. Owning gives control and lower cost per kilometre at high use, but you buy the garage, the mechanic and the fuel.

Where you’ve seen it

A healthcare analytics company can't send patient notes outside its cloud account. They evaluate API models with a business associate agreement, and also a 70B open-weight model quantised on four GPUs in their own VPC. The open model hits 91 percent of the best API model's score on their note-summarisation set, passes the privacy review without negotiation, and costs less than the API at their volume of roughly 300 million tokens a day. They keep an API model for the hardest 5 percent of requests where permitted.

Words you’ll hear

Open-weight
Model weights are downloadable; licence and data transparency vary.
Self-hosting
Running a model on your own GPUs or cloud instances.
Data residency / compliance
Rules on where data may be processed and who may see it.
Vendor lock-in
Cost of switching providers or models because of proprietary APIs and prompts.

Visual diagram

Loading interactive diagram

Theory & deep dive

Comparing closed and open-weight models

Quality: frontier closed models usually lead on the hardest general tasks, while strong open-weight models are close behind and often sufficient, especially after fine-tuning on a narrow task. Cost: APIs are pay-per-token with no fixed cost, which is hard to beat at low or spiky volume. Self-hosting has a fixed cost (GPUs, engineers, monitoring) and a low marginal cost, so it wins at sustained high volume and high GPU utilisation; compute your break-even honestly, including idle time and staff.

Control and privacy: open weights allow fine-tuning, quantisation, pinned versions that never change underneath you, offline or on-device use, and data that never leaves your environment. Closed APIs may deprecate or silently update models, and their data-handling terms vary, though enterprise agreements often include zero-retention options and regional processing. Operations: an API means no GPUs, autoscaling or serving expertise; self-hosting means you run inference engines (vLLM, TGI), capacity planning, security patches and on-call.

A break-even sketch

If an API costs $2 per million tokens and a four-GPU node plus ops costs $12,000 a month, the node breaks even near 6 billion tokens a month (about 200M a day) at full utilisation. At 10% utilisation the real cost per token is ten times higher.

Key takeaway: APIs win on speed and spiky volume; open weights win on control and sustained scale.

Making and keeping the choice flexible

Evaluate candidates on your own task set, with your prompts and data, measuring quality, latency, cost and failure modes. Public leaderboards are a starting shortlist, not a decision. Check licences carefully: some open-weight licences restrict commercial use at scale, forbid using outputs to train other models, or require attribution; closed-provider terms constrain how outputs may be used too.

Reduce lock-in with a thin model-gateway layer (a single internal interface, structured-output schemas, prompts kept in configuration, eval suites that run against any model) so switching is a config change plus a re-evaluation. Many teams run a hybrid: a cheap open model for high-volume simple tasks, a closed frontier model for the hardest requests, and sensitive data routed only to approved environments. Revisit the decision regularly, because quality and prices change quickly.

Routing by sensitivity and difficulty

Requests containing PII go to the self-hosted open model only. Non-sensitive hard questions escalate to the frontier API. Everything passes through one gateway that logs cost, latency and eval scores per route.

Key takeaway: Evaluate on your data, abstract the model behind a gateway, and route hybrid.

How it works, step by step

Step 1 of 4
Requirements

1. List non-negotiables

Write down compliance and data residency rules, latency targets, volume and quality bar.

no PII off-VPC · p95 < 2 s · 300M tokens/day
Key numbers at this step
Decides
what's even allowed

When to use it & trade-offs

What it is

Closed models are reached through a provider's API: you send prompts, you get completions, and the weights stay private. Open-weight models publish their trained weights (under licences that vary from permissive to restricted), so you can download, run, fine-tune and inspect them on your own infrastructure or through hosting providers. "Open source" is stricter and usually not accurate: most open-weight releases don't include training data or full training code. The choice is a trade-off across quality, cost, control, privacy, compliance and operational burden.

Why it matters: This decision shapes your architecture, budget and risk. A startup may ship fastest on an API; a bank with data-residency rules may be unable to send customer text to a third party; a company with a million daily classification calls may save most of its bill by self-hosting a small open model. Engineers are expected to reason about the trade-offs and to prevent lock-in, rather than defend one camp.

When to reach for it

  • APIs for prototypes and unpredictable traffic
  • Open weights for sensitive data and high-volume stable tasks
  • A gateway and hybrid routing in larger systems

When to avoid or be careful

  • Choosing by leaderboard rank alone
  • Comparing API price with GPU price without utilisation and staff costs
  • Hard-coding one provider's API throughout the codebase

API (closed) vs self-hosted open weights

Closed API
Best for: Fast launch, spiky or low volume, frontier quality

Strengths: No infrastructure; always-improving models; pay as you go.

Watch out: Per-token cost at scale; less control; deprecations; data-sharing review.

Self-hosted open weights
Best for: High volume, strict privacy, customisation, offline use

Strengths: Data stays with you; pinned versions; fine-tuning; low marginal cost.

Watch out: GPUs, serving expertise and on-call; may trail frontier quality.

Hosted open models (inference providers)
Best for: Open-model flexibility without running GPUs

Strengths: Pay-per-token for open models; easy switching.

Watch out: Still third-party processing; fewer guarantees than your own VPC.

Interview signals & numbers to know

When this topic comes up

  • “Should we self-host?”
  • “Our compliance team won't allow sending data out”
  • “What does open-weight mean?”
  • Vendor lock-in
  • Model gateways

Benchmarks & rules of thumb

utilisation -
the number that makes or breaks self-hosting economics
~91% -
open model's relative score in the healthcare example
10× -
cost per token at 10% GPU utilisation vs full

Common mistakes & follow-ups

Common interview mistakes

  • Calling an open-weight model "open source" and ignoring a licence that restricts your use.
  • Self-hosting for a workload of a few thousand requests a day and paying for idle GPUs.
  • Writing prompts tuned to one provider's quirks with no evaluation set to port them.

Likely interviewer follow-ups

  • When does self-hosting an open model become cheaper than an API?
  • How would you keep the system provider-agnostic?
  • What compliance questions would you ask before using an API?
Interview tip: Give a break-even number and mention utilisation. Hybrid routing behind a gateway is the mature answer; neither camp wins everywhere.
Loading hands-on exercise

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Open vs Closed Models with generative AI interview Q&A and hands-on practice.

Open Generative AI Q&A →Tech Learn Q&A
Previous topic
Distillation
Next topic
Embeddings