In one paragraph
Once an LLM is in a production path, three problems appear: which model, what did it cost, and why did it do that. LiteLLM answers the routing, Langfuse answers the tracing, and vLLM or Ollama answers the hosting. All three are open source and all three are runnable on one machine.
What you end up with
- One OpenAI-compatible endpoint in front of every provider, with per-key budgets and fallbacks
- Every request traced: prompt, response, latency, token counts, cost, and the user it belonged to
- A local model option for anything that must not leave your network
- A cost report per feature, per day, that finance can read
The reference stack
Every project below is open source and self-hostable. Licences are the ones the project publishes today; check them against your own distribution model before you ship, because a licence can change and an AGPL project has obligations a MIT project does not.
| Layer | Open-source project | Licence | What it does for you |
|---|---|---|---|
| Gateway / router | LiteLLM | MIT | One API for 100+ providers, virtual keys with budgets, retries, fallbacks and a spend log you own. |
| Tracing | Langfuse | MIT (core) | Traces, spans, prompt versions, scores and datasets. Self-hosted, so prompts stay on your infrastructure. |
| Local inference | Ollama | MIT | Fast path to running an open model locally with an OpenAI-compatible endpoint. |
| Serving at volume | vLLM | Apache-2.0 | Paged attention, continuous batching, tensor parallel — the difference between 3 and 300 requests/sec on the same GPU. |
| Chat UI | Open WebUI | BSD-3-Clause | Internal chat front end against your gateway, with users, models and history under your control. |
| Evaluation | promptfoo | MIT | Regression tests over a prompt set, so a model swap is a measured change and not a hope. |
| Storage | PostgreSQL | PostgreSQL | Backing store for LiteLLM keys/spend and Langfuse traces. |
Build it
1. Put one endpoint in front of every provider
Applications should never hold a provider SDK and an API key. They call your gateway with a virtual key that has a budget and a model list, and the gateway decides the provider. That indirection is what makes a provider change a config edit instead of a code release.
# litellm proxy config (excerpt)
model_list:
- model_name: fast
litellm_params: { model: gpt-4o-mini, api_key: os.environ/OPENAI_KEY }
- model_name: fast
litellm_params: { model: ollama/llama3.1:8b, api_base: http://ollama:11434 }
router_settings: { fallbacks: [{ fast: [fast] }], num_retries: 2 }
litellm_settings: { success_callback: ["langfuse"] }
2. Issue keys per application, not per company
One virtual key per feature, with its own monthly budget, rate limit and allowed models. When a feature misbehaves you can see its spend and disable it without touching anything else. A single shared key makes every incident a company-wide incident.
3. Trace everything, including the inputs you need to debug
Trace id, user id, model, prompt hash, token counts, latency and the full messages. Be deliberate about PII: trace the minimum that lets you reproduce a bad answer, and document the retention window. Observability that stores customer data forever is a liability, not a feature.
4. Build a golden set before you change models
30–100 real prompts with expected properties (not exact strings). Run the set against the candidate model and compare. Without this, every model change is an untested deploy, and the failure mode is a slow quality drift nobody can date.
5. Put a local model behind the same endpoint
Anything that cannot leave your network gets a local model entry. Ollama for a quick path, vLLM when concurrency matters. Because the endpoint is the same, the application does not change; only the model name does.
6. Report cost per feature per day
LiteLLM writes spend per request. Aggregate it by key and by day; that table is the whole cost conversation. Publish it weekly, including the features that are cheaper than expected.
7. Test the failure paths
Provider 429, provider 500, 60-second timeout, malformed JSON in a structured output, context overflow. Five scenarios, automated. A fallback that was never tested is a hope, not a fallback.
Acceptance checks
If you cannot verify a claim, it is not a finding. These are the checks that close the work; each one can be run by somebody who did not build it.
| Acceptance check | How to verify it |
|---|---|
| No application holds a raw provider key | Grep the repositories and the environment files for provider key patterns; only the gateway container may have them. |
| Every request has a trace with cost and latency | Count gateway requests vs trace records for the same hour; the delta must be zero. |
| Per-key budget is enforced | Exceed the budget in staging and confirm a 429 rather than a charge. |
| Fallback works under an injected provider failure | Point the primary at a black-hole host and assert a successful response from the fallback. |
| Golden set pass rate is recorded per model version | promptfoo output stored and compared between releases. |
| Trace retention and PII policy are written and applied | A documented window plus a scheduled deletion job that is verified once. |
Effort and cost
| Estimate | |
|---|---|
| Skill needed | Advanced: containers, an LLM API, Postgres, and enough HTTP to debug a gateway |
| Build time | 1 day for LiteLLM, 1 day for Langfuse, 1–2 days for the golden set and evaluations |
| Running cost | Provider token cost dominates. The infrastructure is a single 8–16 GB host; local models need a GPU |
| What you must host | One 8 GB host for gateway + tracing. GPU host only if you serve local models. |
What open source does not give you
The honest half of the comparison. Each of these is a reason somebody buys the service instead of building it, and pretending otherwise would make the rest of this page worthless.
- Tracing is not evaluation. Knowing what the model did does not tell you whether it did the right thing; that requires a labelled set and human review.
- Self-hosted inference costs are real: a GPU that idles still costs money, and throughput per dollar is usually worse than a hosted API at low volume. Local models are a privacy and latency decision more often than a cost decision.
- Prompt caching, batch discounts and enterprise agreements are provider-side features the gateway can pass through but cannot create.
- Open models lag frontier models on hard reasoning and tool use. For a support triage or a JSON extraction task that gap is invisible; for an agent making 20 tool calls it is not.
- Langfuse’s core is MIT but some enterprise features are paid. Check the feature you need against the edition.
What the service adds
Scope only, stated so you can compare it with the build above.
- The routing policy: which task goes to which model class, priced against quality you have measured
- Golden-set design and the quality read on a model swap
- Cost governance across teams, including budgets and the chargeback report
Sources and further reading
Related guides
What this page does not include. This guide documents an open-source implementation of the same outcome. It deliberately leaves out 5 Kings’ internal playbooks, client data, vendor terms and unpublished method: we publish what any competent team can reproduce, and we do not publish what belongs to a client or to a contract. Where a step depends on a decision only your business can make, the guide says so instead of guessing.
Take it with you
Run LLM operations on open source: routing, observability, cost
The full guide as an A4 PDF: the reference stack with licences, the build steps, the acceptance checks and the honest limits — in one file you can hand to an engineer or print for a planning session.