ai newsMi., 25. Nov.
EilmeldungYale’s Sonnenfeld: Nvidia is a ‘detriment’ to U.S. industrial might — not a champion

LiteLLM: Open-Source-Proxy für einheitlichen Zugriff auf über 100 LLM-Anbieter

LiteLLM ist ein Open-Source-Proxy in Python, der einen einzigen OpenAI-kompatiblen Endpunkt für mehr als 100 Modellanbieter bereitstellt und Anfragen automatisch an OpenAI, Anthropic, Google, Bedrock oder lokale vLLM-Instanzen weiterleitet.

dev.toDienstag 16:58 · 24.11.DE9 Min. Lesezeit
Bild: dev.to

Veröffentlicht am 24. Nov • Ursprünglich veröffentlicht auf blog.sandbase.ai

Ursprünglich veröffentlicht im SandBase Blog.

TL;DR — LiteLLM ist ein Open-Source-Python-Proxy, der Ihnen einen einzigen OpenAI-kompatiblen Endpunkt für über 100 Modell-Provider bietet. Sie rufen eine API auf, und sie leitet an OpenAI, Anthropic, Google, Bedrock, lokales vLLM oder alles andere von Ihnen Konfigurierte weiter — mit automatischem Failover, Kostenverfolgung, Rate Limiting und Budgetlimits. Wenn Ihre Agenten mit mehreren Modellen kommunizieren (was sie sollten), ist LiteLLM die Schicht, die Sie davor bewahrt, providerspezifischen Code zu schreiben.

Sie vergleichen den Proxy mit verwalteten und multimodalen Optionen? Werfen Sie vor der Wahl einer Gateway-Architektur einen Blick auf den Leitfaden zu OpenRouter-Alternativen.

Sie bauen einen Agenten. Er braucht ein starkes Modell für die Planung (Claude), ein schnelles Modell für einfache Tool-Aufrufe (GPT-4o-mini) und ein günstiges Modell für die Zusammenfassung (ein lokales Llama über vLLM). Das sind drei verschiedene APIs, drei verschiedene Auth-Muster, drei verschiedene Antwortformate, drei verschiedene Fehlercodes und drei verschiedene Abrechnungs-Dashboards.

Multiplizieren Sie das mit jeder Modellaktualisierung, die die Preise ändert, jedem Rate-Limit, das Sie um 2 Uhr nachts erreichen, und jedem Ausfall eines Providers, bei dem Ihre Agenten abstürzen, statt kontrolliert auf einen Ersatz zurückzufallen.

LiteLLM verdichtet das alles in einen Endpunkt. Ihr Agentencode ruft POST /chat/completions mit einem Modellnamen auf. LiteLLM erledigt alles darunter.

Der Proxy ist der Ort, an dem der echte Wert für Produktions-Agenten-Stacks liegt. Er ist die zentrale Kontrollinstanz für den gesamten Modellzugriff.

┌──────────────────────────────────────────────────┐ │ Agent Runtime │ │ (ruft POST /v1/chat/completions auf) │ ├──────────────────────────────────────────────────┤ │ LiteLLM Proxy ←── das Gateway │ │ ┌────────────────────────────────────────────┐ │ │ │ Router: Modell → Provider Zuordnung │ │ │ │ Load Balancer: Round-Robin / Least-Busy │ │ │ │ Fallback: Provider A fällt aus → versuche B │ │ │ │ Cost Tracker: pro Token, pro Key, pro Team │ │ │ │ Rate Limiter: TPM / RPM Limits │ │ │ │ Budget: harte Ausgabegrenzen pro virtuellem Key │ │ │ │ Cache: semantisch oder exakt │ │ │ │ Guardrails: Inhaltsfilterung │ │ │ └────────────────────────────────────────────┘ │ ├──────────────────────────────────────────────────┤ │ Provider │ │ OpenAI | Anthropic | Bedrock | vLLM | SGLang │ │ Google | Mistral | Cohere | Ollama |... │ └──────────────────────────────────────────────────┘ Vollbildmodus öffnen Vollbildmodus schließen Ihr Agentencode weiß nicht (und kümmert sich nicht darum), welcher Provider welches Modell bedient. Das ist die Aufgabe des Gateways.

Einheitliche API — Ein Endpunkt, ein Format. Wechseln Sie von Claude zu GPT-4o, indem Sie einen Modellnamen-String ändern, statt Ihre Tool-Calling-Logik neu zu schreiben.

Automatisches Failover — Wenn Anthropic einen 529 zurückgibt, wiederholt LiteLLM auf einer Backup-Bereitstellung oder weicht auf einen anderen Provider aus. Ihre Agenten-Session stirbt nicht, weil eine API kurz gestolpert ist.

Kostenverfolgung — Jede Anfrage wird mit Eingabe-/Ausgabe-Tokens und Kosten protokolliert. Sie sehen Aufschlüsselungen pro Agent, pro Team und pro Modell. Wenn Ihr Coding-Agent 40 Dollar in einer Debugging-Schleife verbrennt, wissen Sie genau, welche Session es war.

Budgetlimits — Setzen Sie harte Grenzen pro virtuellem API-Key. Geben Sie jeder Agenteninstanz ein Tagesbudget von 5 Dollar. Ist es aufgebraucht, werden Anfragen abgewiesen, statt Ihre Kreditkarte leerzubrennen.

Load Balancing — Mehrere API-Keys für denselben Provider? Mehrere vLLM-Instanzen? LiteLLM verteilt die Anfragen darauf. Erreicht eine Instanz Rate-Limits, verlagert sich der Verkehr auf eine andere.

Virtuelle Keys — Erstellen Sie API-Keys für Teams oder Agenten, ohne Ihre echten Provider-Keys zu teilen. Jeder virtuelle Key hat eigene Budgets, Rate-Limits und Modellzugriffs-Berechtigungen.

Caching — Exaktes oder semantisches Caching von Antworten. Wenn zwei Agenten-Sessions dieselbe Frage mit demselben Kontext stellen, wird die zwischengespeicherte Antwort ausgeliefert. Spart Tokens und Latenz.

Hier überschneidet sich LiteLLM mit einem wachsenden Trend in der Agenten-Infrastruktur. Forschung von ICLR 2025 (RouteLLM) und EMNLP 2025 (IPR) zeigte, dass das Weiterleiten von Anfragen an verschiedene Modell-Stufen je nach Schwierig die Kosten um 40-50% senken kann, bei gleichbleibender Qualität.

In der Praxis erzählen LiteLLMs GitHub-Issues dieselbe Geschichte. Suchergebnisse zeigen häufige Anfragen zu cost-based Routing (23 Issues), lowest-cost Routing (18), Budget-Routing (37) und Ausgabenverfolgung (76). Teams fragen: Wie leite ich bei gegebenen Qualitätsanforderungen an das günstigste ausreichende Modell weiter?

model_list: - model_name: agent-planner litellm_params: model: anthropic/claude-sonnet-4 api_key: sk-ant-... model_info: cost_per_token: 0.000003 - model_name: agent-executor litellm_params: model: openai/gpt-4o-mini api_key: sk-... model_info: cost_per_token: 0.00000015 - model_name: agent-summarizer litellm_params: model: openai/hosted_vllm/llama-3.3-70b api_base: http://vllm-internal:8000/v1 Vollbildmodus öffnen Vollbildmodus schließen Ihr Agent ruft für verschiedene Aufgaben verschiedene Modellnamen auf. Das Gateway leitet jede Anfrage an das richtige Backend weiter. Keine Provider-SDK-Imports in Ihrem Agentencode.

LiteLLM berechnet die Kosten jeder Antwort anhand seiner eigenen integrierten Preistabelle, nicht anhand dessen, was Ihr Upstream abrechnet. Das ist relevant, wenn der Upstream ein Gateway ist, das Modelle vergünstigt oder neu bepreist, etwa SandBase.

Ausgeführt am 24.11.2026 mit LiteLLM 1.110.2, ein Aufruf von openai/gpt-4.1-nano über SandBase' OpenAI-kompatiblen Endpunkt (13 Eingabe-Tokens, 1 Ausgabe-Token):

import os, litellm kwargs = dict ( model = "openai/openai/gpt-4.1-nano", # "openai/" wählt LiteLLMs OpenAI-kompatiblen Provider; der Rest ist die SandBase-Modell-ID api_base = "https://api.sandbase.ai/v1", api_key = os. environ [ "SANDBASE_API_KEY" ], messages = [ { "role": "user", "content": "Reply with one word: ok" } ], max_tokens = 5, ) default = litellm. completion ( ** kwargs ) print ( default. _hidden_params [ "response_cost" ] ) # 1.7e-06, aus LiteLLMs Preistabelle priced = litellm. completion ( ** kwargs, input_cost_per_token = 0.09e-6, output_cost_per_token = 0.36e-6 ) print ( priced. _hidden_params [ "response_cost" ] ) # 1.53e-06, von den Preisen auf der SandBase-Modellseite Vollbildmodus öffnen Vollbildmodus schließen Der Standardwert ist LiteLLMs Listenpreis für GPT-4.1 nano (0,10 und 0,40 Dollar pro 1M Tokens). Der zweite Wert verwendet die an jenem Tag auf der SandBase-Modellseite angezeigten 0,09 und 0,36 Dollar, die einen Rabatt von 10% beinhalteten. Beide sind Schätzungen, bis Sie sie mit dem abgleichen, was der Upstream tatsächlich abgerechnet hat.

Damit der Proxy den Upstream-Preis meldet, setzen Sie dieselben beiden Felder in litellm_params (getestet über litellm.Router, das dieselben Parameter liest wie die config.yaml des Proxys):

model_list: - model_name: nano litellm_params: model: openai/openai/gpt-4.1-nano api_base: https://api.sandbase.ai/v1 api_key: os.environ/SANDBASE_API_KEY input_cost_per_token: 0.00000009 output_cost_per_token: 0.00000036 Vollbildmodus öffnen Vollbildmodus schließen Zwei Warnungen. Rabatte ändern sich, kopieren Sie den Preis beim Deployment von der Modellseite und prüfen Sie ihn erneut, statt ihn dauerhaft fest zu hinterlegen. Und LiteLLMs Ausgabenprotokoll ist keine Rechnung: Gleichen Sie es mit den Nutzungsdatensätzen des Kontos ab, das tatsächlich zahlt, in SandBase' Fall die Kosten pro Aufruf unter Usage.

# Docker (am schnellsten) docker run -d \ -p 4000:4000 \ -v./litellm_config.yaml:/app/config.yaml \ -e DATABASE_URL = postgresql://... \ ghcr.io/berriai/litellm:main-latest \ --config /app/config.yaml # Test curl http://localhost:4000/v1/chat/completions \ -H "Authorization: Bearer sk-your-virtual-key" \ -H "Content-Type: application/json" \ -d '{ "model": "agent-planner", "messages": [{"role": "user", "content": "Plan the refactor"}], "max_tokens": 500 }' Vollbildmodus öffnen Vollbildmodus schließen Diese Anfrage erreicht LiteLLM, das agent-planner zu Claude Sonnet 4 auflöst, die Authentifizierung ergänzt, die Anfrage weiterleitet, die Kosten protokolliert und die Antwort im OpenAI-Format zurückgibt.

Das mit Abstand wertvollste LiteLLM-Feature für Produktions-Agenten ist Failover — und zugleich das, das Menschen falsch konfigurieren. Das naive Setup sieht so aus:

model_list: - model_name: agent-planner litellm_params: model: anthropic/claude-sonnet-4 api_key: os.environ/ANTHROPIC_KEY_1 - model_name: agent-planner # derselbe Name = eine Fallback-Gruppe litellm_params: model: anthropic/claude-sonnet-4 api_key: os.environ/ANTHROPIC_KEY_2 # anderer Key router_settings: num_retries: 2 retry_after: 5 allowed_fails: 3 cooldown_time: 30 fallbacks: [ { "agent-planner": [ "agent-planner-backup" ] } ] Vollbildmodus öffnen Vollbildmodus schließen Der feine Punkt, den die meisten übersehen: Wiederholungen beim selben Provider helfen nicht, wenn der Provider selbst ausgefallen ist. Wenn Anthropic einen 529 (überlastet) zurückgibt, liefert ein erneuter Versuch desselben Anthropic-Endpunkts 2 Sekunden später meist wieder einen 529. Echte Robustheit braucht einen providerübergreifenden Fallback:

- model_name: agent-planner-backup litellm_params: model: openai/gpt-4o # ANDERER Provider api_key: os.environ/OPENAI_KEY Vollbildmodus öffnen Vollbildmodus schließen Wenn Anthropic nun überlastet ist, fällt die Anfrage auf GPT-4o zurück. Ihr Agent erhält ein etwas anderes Modell, bleibt aber funktionsfähig. Für einen Planungsschritt lohnt sich dieser Kompromiss fast immer.

Die zweite Falle: allowed_fails und cooldown_time. Wenn ein Deployment allowed_fails Mal fehlschlägt, versetzt LiteLLM es für cooldown_time Sekunden in einen Cooldown und leitet den Traffic woanders hin. Setzt man cooldown_time zu niedrig (z. B. 5 s), belastet man einen kämpfenden Provider weiter massiv. Zu hoch (z. B. 300 s) und man verliert über eine vorübergehende Störung hinweg fünf Minuten lang Kapazität. 30 bis 60 Sekunden sind für die meisten Agent-Workloads der Sweet Spot.

Hier ist ein Bug, der specifically Agent-Entwickler trifft. Wenn man Antworten streamt (was man aus UX-Gründen tun sollte) und der primäre Provider mitten im Stream fehlschlägt, nachdem er bereits 50 Tokens gesendet hat und dann einen Fehler wirft, was passiert dann?

LiteLLM kann auf einen sekundären Provider ausweichen, aber der Client hat diese 50 Tokens bereits erhalten. Die Fallback-Antwort startet von null, sodass der Nutzer zuerst 50 Tokens sieht und dann der Stream mit anderem Inhalt neu startet. Für eine Chat-UI ist das irritierend; für einen Agenten, der strukturierte Ausgaben parst, ist es ein Parse-Fehler.

Die Abhilfe: Für Agent-Tool-Call-Anfragen, bei denen die Integrität der Ausgabe wichtiger ist als die Latenz, sollte man Streaming deaktivieren und den nicht streamenden Pfad mit Fallback nutzen. Streaming bleibt dem nutzerseitigen Chat vorbehalten, bei dem ein Neustart tolerierbar ist. LiteLLM löst das Problem nicht automatisch — man muss pro Endpunkt entscheiden, ob Streaming oder zuverlässiger Fallback wichtiger ist.

LiteLLM ist die Open-Source-Variante, die man selbst hostet. OpenRouter ist der verwaltete Marktplatz. SandBase bietet ein verwaltetes Gateway mit Sandbox- und Ausführungsfunktionen. Sie lösen überlappende, aber unterschiedliche Probleme — und man kann LiteLLM tatsächlich als Routing-Layer unter einer übergeordneten Plattform einsetzen.

Für die meisten produktiven Agent-Systeme wird ein Gateway ab dem Punkt unverzichtbar, an dem man mehr als ein Modell oder mehr als ein Team hat. Die Kosten des Fehlens sind unsichtbar, bis man eine überraschende Rechnung über 2.000 Dollar erhält oder einen dreistündigen Ausfall erleidet, weil man einen einzelnen Provider-Endpunkt hartkodiert hat.

LiteLLM ist die Gateway-Schicht des AI Agent Infrastructure Stack 2026. Verwandte Lektüre im selben Cluster:

Kann LiteLLM basierend auf Inhalt/Schwierigkeit routen?

Nicht nativ über einen eingebauten Classifier, aber man kann es selbst umsetzen. Man definiert in seinem Agent-Code unterschiedliche Modellnamen für verschiedene Komplexitätsstufen, und LiteLLM leitet jede Anfrage an den passenden Provider weiter. Manche Teams stellen einen leichtgewichtigen Classifier vor, der den Modellnamen auswählt.

Minimal — typischerweise 5 bis 15 ms pro Anfrage. Es handelt sich um einen schlanken Proxy ohne aufwändige Verarbeitung. Die Latenzkosten sind im Vergleich zur Modellgenerierungszeit vernachlässigbar.

Ja. Volle Unterstützung für SSE-Streaming, einschließlich mit Fallover (wenn der primäre Stream mitten in der Antwort fehlschlägt, kann auf einem Fallback erneut versucht werden).

Wie geht es mit unterschiedlichen Antwortformaten um?

LiteLLM normalisiert alles ins OpenAI-Format. Anthropics Messages API, das Gemini-Format von Google, die Bedrock-Struktur — all das kommt bei Ihrem Agent-Code als standardmäßige OpenAI-Chat-Completions zurück.

Stimmt LiteLLMs Kostenerfassung mit dem überein, was mein Provider berechnet? Nur, wenn seine Preistabelle mit den Preisen Ihres Upstreams übereinstimmt. Bei einem Gateway, das Modelle mit Rabatt anbietet, kann der Standardwert response_cost von der Rechnung abweichen: In einem Test vom 24.11.2026 meldete LiteLLM 0,0000017 Dollar für einen Aufruf, den der Upstream mit 0,00000153 Dollar berechnete. Setzen Sie input_cost_per_token und output_cost_per_token für dieses Deployment und gleichen Sie das anschließend mit den Usage-Daten des Upstreams ab.

Nur für dauerhafte Kostenerfassung und Budgetverwaltung. Ohne Datenbank erhält man weiterhin Routing und Failover, aber die Ausgabedaten überleben keinen Neustart.

Automatisch übersetzt. Das Original auf Englisch ist unten aufklappbar.

Original (Englisch) anzeigen

Posted on Nov 24 • Originally published at blog.sandbase.ai

Originally published on the SandBase Blog.

TL;DR — LiteLLM is an open-source Python proxy that gives you a single OpenAI-compatible endpoint for 100+ model providers. You call one API, it routes to OpenAI, Anthropic, Google, Bedrock, local vLLM, or whatever else you've configured — with automatic failover, cost tracking, rate limiting, and budget caps. If your agents talk to multiple models (they should), LiteLLM is the layer that keeps you from writing provider-specific code.

Comparing the proxy with managed and multimodal options? See the OpenRouter alternatives guide before choosing a gateway architecture.

You're building an agent. It needs a strong model for planning (Claude), a fast model for simple tool calls (GPT-4o-mini), and a cheap model for summarization (a local Llama via vLLM). That's three different APIs, three different auth patterns, three different response formats, three different error codes, and three different billing dashboards.

Now multiply that by every model update that changes pricing, every rate limit you hit at 2 AM, every time a provider has an outage and your agents crash instead of gracefully falling back.

LiteLLM collapses this into one endpoint. Your agent code calls POST /chat/completions with a model name. LiteLLM handles everything underneath.

The proxy is where the real value lives for production agent stacks. It's the centralized control plane for all model access.

┌──────────────────────────────────────────────────┐ │ Agent Runtime │ │ (calls POST /v1/chat/completions) │ ├──────────────────────────────────────────────────┤ │ LiteLLM Proxy ←── the gateway │ │ ┌────────────────────────────────────────────┐ │ │ │ Router: model → provider mapping │ │ │ │ Load Balancer: round-robin / least-busy │ │ │ │ Fallback: provider A fails → try B │ │ │ │ Cost Tracker: per-token, per-key, per-team │ │ │ │ Rate Limiter: TPM / RPM caps │ │ │ │ Budget: hard spend limits per virtual key │ │ │ │ Cache: semantic or exact-match │ │ │ │ Guardrails: content filtering │ │ │ └────────────────────────────────────────────┘ │ ├──────────────────────────────────────────────────┤ │ Providers │ │ OpenAI | Anthropic | Bedrock | vLLM | SGLang │ │ Google | Mistral | Cohere | Ollama |... │ └──────────────────────────────────────────────────┘ Enter fullscreen mode Exit fullscreen mode Your agent code doesn't know (or care) which provider serves which model. That's the gateway's job.

Unified API — One endpoint, one format. Switch from Claude to GPT-4o by changing a model name string, not rewriting your tool-calling logic.

Automatic failover — If Anthropic returns a 529, LiteLLM retries on a backup deployment or falls back to a different provider. Your agent session doesn't die because one API had a hiccup.

Cost tracking — Every request is logged with input/output tokens and cost. You can see per-agent, per-team, per-model breakdowns. When your coding agent burns $40 in a debugging loop, you know exactly which session did it.

Budget caps — Set hard limits per virtual API key. Give each agent instance a $5/day budget. When it's used up, requests get rejected instead of burning through your credit card.

Load balancing — Multiple API keys for the same provider? Multiple vLLM instances? LiteLLM distributes requests across them. If one is hitting rate limits, traffic shifts to another.

Virtual keys — Create API keys for teams or agents without sharing your real provider keys. Each virtual key has its own budget, rate limits, and model access permissions.

Caching — Exact-match or semantic caching of responses. If two agent sessions ask the same question with the same context, serve the cached response. Saves tokens and latency.

This is where LiteLLM intersects with a growing trend in agent infrastructure. Research from ICLR 2025 (RouteLLM) and EMNLP 2025 (IPR) showed that routing requests to different model tiers based on difficulty can cut costs by 40-50% while maintaining quality.

In practice, LiteLLM's GitHub issues tell the same story. Search results show frequent requests for cost-based routing (23 issues), lowest-cost routing (18), budget routing (37), and spend tracking (76). Teams are asking: given quality requirements, how do I route to the cheapest sufficient model?

model_list: - model_name: agent-planner litellm_params: model: anthropic/claude-sonnet-4 api_key: sk-ant-... model_info: cost_per_token: 0.000003 - model_name: agent-executor litellm_params: model: openai/gpt-4o-mini api_key: sk-... model_info: cost_per_token: 0.00000015 - model_name: agent-summarizer litellm_params: model: openai/hosted_vllm/llama-3.3-70b api_base: http://vllm-internal:8000/v1 Enter fullscreen mode Exit fullscreen mode Your agent calls different model names for different tasks. The gateway routes each to the right backend. No provider SDK imports in your agent code.

LiteLLM prices each response from its own built-in price table, not from what your upstream bills. That matters when the upstream is a gateway that discounts or re-prices models, such as SandBase.

Run on 2026-11-24 with LiteLLM 1.110.2, one call to openai/gpt-4.1-nano through SandBase's OpenAI-compatible endpoint (13 input tokens, 1 output token):

import os, litellm kwargs = dict ( model = "openai/openai/gpt-4.1-nano", # "openai/" selects LiteLLM's OpenAI-compatible provider; the rest is the SandBase model ID api_base = "https://api.sandbase.ai/v1", api_key = os. environ [ "SANDBASE_API_KEY" ], messages = [ { "role": "user", "content": "Reply with one word: ok" } ], max_tokens = 5, ) default = litellm. completion ( ** kwargs ) print ( default. _hidden_params [ "response_cost" ] ) # 1.7e-06, from LiteLLM's price table priced = litellm. completion ( ** kwargs, input_cost_per_token = 0.09e-6, output_cost_per_token = 0.36e-6 ) print ( priced. _hidden_params [ "response_cost" ] ) # 1.53e-06, from the prices on the SandBase model page Enter fullscreen mode Exit fullscreen mode The default figure is LiteLLM's list price for GPT-4.1 nano ($0.10 and $0.40 per 1M tokens). The second figure uses the $0.09 and $0.36 shown on the SandBase model page that day, which carried a 10% discount. Both are estimates until you compare them with what the upstream charged.

To make the proxy report the upstream price, put the same two fields in litellm_params (tested through litellm.Router, which reads the same parameters as the proxy's config.yaml ):

model_list: - model_name: nano litellm_params: model: openai/openai/gpt-4.1-nano api_base: https://api.sandbase.ai/v1 api_key: os.environ/SANDBASE_API_KEY input_cost_per_token: 0.00000009 output_cost_per_token: 0.00000036 Enter fullscreen mode Exit fullscreen mode Two cautions. Discounts change, so copy the price from the model page when you deploy and re-check it, instead of hard-coding it for good. And LiteLLM's spend log is not a bill: reconcile it against the usage records of the account that actually pays, which in SandBase's case are the per-call costs in Usage.

# Docker (quickest) docker run -d \ -p 4000:4000 \ -v./litellm_config.yaml:/app/config.yaml \ -e DATABASE_URL = postgresql://... \ ghcr.io/berriai/litellm:main-latest \ --config /app/config.yaml # Test curl http://localhost:4000/v1/chat/completions \ -H "Authorization: Bearer sk-your-virtual-key" \ -H "Content-Type: application/json" \ -d '{ "model": "agent-planner", "messages": [{"role": "user", "content": "Plan the refactor"}], "max_tokens": 500 }' Enter fullscreen mode Exit fullscreen mode That request hits LiteLLM, which resolves agent-planner to Claude Sonnet 4, adds auth, forwards the request, logs the cost, and returns the response in OpenAI format.

The single most valuable LiteLLM feature for production agents is failover — and it's also the one people configure wrong. The naive setup looks like this:

model_list: - model_name: agent-planner litellm_params: model: anthropic/claude-sonnet-4 api_key: os.environ/ANTHROPIC_KEY_1 - model_name: agent-planner # same name = a fallback group litellm_params: model: anthropic/claude-sonnet-4 api_key: os.environ/ANTHROPIC_KEY_2 # different key router_settings: num_retries: 2 retry_after: 5 allowed_fails: 3 cooldown_time: 30 fallbacks: [ { "agent-planner": [ "agent-planner-backup" ] } ] Enter fullscreen mode Exit fullscreen mode The subtle part most people miss: retries within the same provider don't help when the provider itself is down. If Anthropic returns 529 (overloaded), retrying the same Anthropic endpoint 2 seconds later usually returns another 529. Real resilience needs a cross-provider fallback:

- model_name: agent-planner-backup litellm_params: model: openai/gpt-4o # DIFFERENT provider api_key: os.environ/OPENAI_KEY Enter fullscreen mode Exit fullscreen mode Now when Anthropic is overloaded, the request falls through to GPT-4o. Your agent gets a slightly different model but stays alive. For a planning step, that trade-off is almost always worth it.

The other gotcha: allowed_fails and cooldown_time. When a deployment fails allowed_fails times, LiteLLM puts it in cooldown for cooldown_time seconds — routing traffic elsewhere. Set cooldown_time too low (e.g., 5s) and you'll keep hammering a struggling provider. Too high (e.g., 300s) and you lose capacity for 5 minutes over a transient blip. 30-60s is the sweet spot for most agent workloads.

Here's a bug that bites agent builders specifically. When you stream responses (which you should, for UX) and the primary provider fails mid-stream — after sending 50 tokens then erroring — what happens?

LiteLLM can fall back to a secondary provider, but the client has already received those 50 tokens. The fallback response starts from scratch, so the user sees 50 tokens, then the stream restarts with different content. For a chat UI this is jarring; for an agent parsing structured output, it's a parse failure.

The mitigation: for agent tool-call requests where output integrity matters more than latency, disable streaming and use the non-streaming path with fallback. Reserve streaming for user-facing chat where a restart is tolerable. LiteLLM doesn't solve this for you — you have to decide per-endpoint whether streaming or reliable-fallback matters more.

LiteLLM is the open-source option you self-host. OpenRouter is the managed marketplace. SandBase provides a managed gateway with sandbox/execution features. They solve overlapping but different problems — and you can actually use LiteLLM as the routing layer under a higher-level platform.

For most production agent systems, a gateway becomes essential at the point where you have more than one model or more than one team. The cost of not having one is invisible until you get a surprise $2,000 bill or a 3-hour outage because you hardcoded a single provider endpoint.

LiteLLM is the gateway layer of the AI Agent Infrastructure Stack 2026. Related reading in the same cluster:

Can LiteLLM route based on content/difficulty?

Not natively with a built-in classifier, but you can implement it. Set up different model names for different complexity tiers in your agent code, and LiteLLM routes each to the appropriate provider. Some teams put a lightweight classifier in front that picks the model name.

Minimal — typically 5-15ms per request. It's a thin proxy, not doing heavy processing. The latency cost is negligible compared to model generation time.

Yes. Full support for SSE streaming, including with fallover (if the primary stream fails mid-response, it can retry on a fallback).

How does it handle different response formats?

LiteLLM normalizes everything into OpenAI format. Anthropic's Messages API, Google's Gemini format, Bedrock's structure — all come back as standard OpenAI chat completions to your agent code.

Does LiteLLM's cost tracking match what my provider charges? Only if its price table matches your upstream's prices. With a gateway that discounts models, the default response_cost can differ from the bill: in a 2026-11-24 test, LiteLLM reported $0.0000017 for a call that the upstream priced at $0.00000153. Set input_cost_per_token and output_cost_per_token for that deployment, then reconcile against the upstream's usage records.

Only for persistent cost tracking and budget management. Without a database, you still get routing and failover, but spend data doesn't survive restarts.

Originaltitel: LiteLLM Explained: Open-Source LLM Proxy GatewayQuelle: dev.to (dev.to). Original öffnen