Sub topic 3
Hosted or Self-Hosted: Weighing the Trade-Offs
Assume you can call an HTTP API, read basic Python, and understand prompts, tokens, and context. The main choice is where inference runs: on a provider's servers or on infrastructure you control.
Hosted or Self-Hosted
A hosted API gives you a ready model, scaling, monitoring, and upgrades. You pay per input and output token. You also send application data to a provider, so retention, location, and compliance terms matter.
A self-hosted model runs on your own hardware or a managed server. It can reduce per-request cost at high volume and gives you more control over data, versions, and latency. You must pay for hardware, deployment, monitoring, updates, and failures. Check the model license before commercial use. “Open-weight” means the parameter files are available; it does not necessarily mean the software and usage rights are fully open-source.
| Requirement | Hosted API | Self-hosted model |
|---|---|---|
| Fast launch | Strong | Weaker |
| Maximum infrastructure control | Limited | Strong |
| Variable traffic | Usually convenient | Requires capacity planning |
| Strict data boundary | Depends on provider | Easier to enforce |
Compare Candidates on Your Own Examples
Public benchmarks may not match your application. Build a small evaluation set from real, reviewed cases. Include normal inputs, difficult inputs, and cases where the correct response is to refuse or request clarification. Measure task accuracy, latency, cost, and failure rate.
cases = [
("Invoice INV-2041 is due May 3.", "INV-2041"),
("Reference: INV-17, total $90.", "INV-17"),
]
def evaluate(model, examples):
passed = sum(expected in model(text) for text, expected in examples)
return passed / len(examples)
models = {
"small": lambda text: "INV-2041" if "2041" in text else "INV-17",
"large": lambda text: text.split(" ")[1].rstrip(","),
}
for name, model in models.items():
print(name, evaluate(model, cases))Design So the Model Can Be Swapped
Keep model-specific code behind one application function. Store the endpoint, model name, and credentials in configuration. This lets you change providers or move from hosted inference to a local OpenAI-compatible server without rewriting business logic.
Route Requests Between Sizes
Use a small model for extraction, classification, and routine support. Route ambiguous, long, or high-impact requests to a larger model. Your evaluation set should verify that routing improves cost without reducing required quality.
Checklist for Making and Revisiting the Choice
- Define quality, latency, volume, privacy, and budget targets.
- Check licenses, retention policies, and data residency.
- Test candidates on representative examples.
- Choose the smallest model that meets the targets.
- Keep the model interface replaceable.
- Re-evaluate after traffic, requirements, or model versions change.
Exercise
When is self-hosting usually worth the added operational work?
Show answer
It is worth considering when data control is strict, traffic is predictable and high, or infrastructure control is more valuable than fast deployment.