Pareto-optimal OpenRouter provider chooser for LiteLLM
Project description
litellm-plugin-openrouter-pareto
A LiteLLM callback that picks the best-value OpenRouter provider per request for a model served by multiple upstream providers. It applies hard filters (quantization, min context, zero-data-retention, 5-minute uptime, min sample size), builds a pareto frontier over input price per million tokens vs P50 throughput, then runs a greedy value-walk to one winner, with flap damping.
Install
pip install litellm-plugin-openrouter-pareto
Wire it into a LiteLLM proxy
Register the module-level callback instance in litellm_settings.callbacks
using a dotted path (the tail must be an instance, not the class):
litellm_settings:
callbacks: ["litellm_plugin_openrouter_pareto.plugin.openrouter_pareto_callback"]
model_list:
- model_name: z-ai/glm-5.2
litellm_params:
model: openrouter/z-ai/glm-5.2
extra_body:
provider: {only: [baseten], zdr: true, allow_fallbacks: false, quantizations: [fp8]}
model_info:
id: or-baseten
- model_name: z-ai/glm-5.2
litellm_params:
model: openrouter/z-ai/glm-5.2
extra_body:
provider: {only: [novita], zdr: true, allow_fallbacks: false, quantizations: [fp8]}
model_info:
id: or-novita
Each deployment is one OpenRouter provider pinned via extra_body.provider.only.
The callback matches a deployment to a winner provider slug by reading
model_info.id and stripping an or- prefix (so or-baseten becomes baseten),
falling back to extra_body.provider.only[0].
The proxy must use an async-native routing strategy (the default simple-shuffle
works) so the callback deployment filter runs. Use the latest model in a family
unless you have a reason not to.
Behavior
- On stale or empty telemetry, or no winner, the full healthy deployment set is returned unchanged. The callback never narrows to an empty list.
- If the winner is in cooldown / not healthy, it falls back to the next preferred provider in the safe set (cheapest-first), then to the full list.
- Telemetry is cached and refreshed on a 5-minute poll; a new value-winner must
win
promotion_pollsconsecutive polls before it is promoted. A winner that stops passing the hard filters is evicted immediately.
429 rate-limit fallback
A provider that returns HTTP 429 is treated as a transitory upstream rate limit. Two layers cooperate:
- Per-request walk: LiteLLM puts the 429'ing deployment in cooldown immediately
and its tenacity retry re-runs deployment selection, so the next attempt lands
on a different provider. Bound this with
num_retrieson the model group. - Cross-request cooldown: the callback tracks 429s per provider. A provider that 429s three or more times within five minutes is "hot" and is skipped as the winner for new requests until its 429s age out of the window. This is the memory LiteLLM's short per-429 cooldown lacks; it stops a persistently rate-limited winner from being retried first on every new request. It is in-process and not persisted; it resets on restart.
The 429 is recorded in the async_log_failure_event hook (status from
kwargs["exception"].status_code); the "hot" skip is applied in
async_filter_deployments. When every provider is hot, the constrained winner is
kept rather than emitting unconstrained routing.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file litellm_plugin_openrouter_pareto-0.1.0.tar.gz.
File metadata
- Download URL: litellm_plugin_openrouter_pareto-0.1.0.tar.gz
- Upload date:
- Size: 19.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c4a71695973d44235ac0d242f9ccd83ccfc7da2dae4c8d68cb540fffe767a48
|
|
| MD5 |
e45c56cb69347c79f76434990eed4109
|
|
| BLAKE2b-256 |
79644ff313d2db1303aaffd8b92549d92d8061f333649f39fde1c83fda9188d7
|
File details
Details for the file litellm_plugin_openrouter_pareto-0.1.0-py3-none-any.whl.
File metadata
- Download URL: litellm_plugin_openrouter_pareto-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45397cbb6d30d303868c983a79e96e8493eaae129327bcb1bc8053028acc82d8
|
|
| MD5 |
a2cedd43de099bbf0e22a31e6e47c4d7
|
|
| BLAKE2b-256 |
b90c79671884d81eb56f0209f7eff34f82119242b013cc6226b5535e66ac8ca4
|