best_engine_ai_helper.sources.litellm_prices module

sources.litellm_prices — paid-model list prices from LiteLLM’s public table.

pricing.yaml is hand-maintained, and its own header says to “refresh when a provider reprices or ships a new flagship”. Nothing enforced that, and nothing could: there was no source to refresh from, so the file aged silently while observe.py priced every paid call against it and cloud_catalog.rank_cloud ranked on the same numbers.

LiteLLM publishes one JSON covering every major provider, kept current because their own router bills against it:

https://github.com/BerriAI/litellm → model_prices_and_context_window.json

What it supplies, and the whole reason this adapter exists:

  • input_cost_per_token / output_cost_per_token — list price, which is what a cost estimate needs to be worth printing.

  • max_input_tokens — the context length. A separate open item on the local side, and free here.

  • supports_vision → our kind (vlm when true, llm when not); supports_response_schema → our structured_output.

One deliberate gap, mirroring :mod:`sources.apxml`. The table carries no benchmark scores, so this adapter never synthesises them. It contributes price and capability metadata; the quality axes stay hand-maintained, and a refresh preserves the scores already in the seed rather than blanking them.

Author

Warith Harchaoui <warithmetics@deraison.ai>

best_engine_ai_helper.sources.litellm_prices.PRICES_URL = 'https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json'

The table itself. Raw rather than the API so a refresh needs no token and no dependency on LiteLLM the package.

best_engine_ai_helper.sources.litellm_prices.fetch_cloud_prices(timeout=30.0, url=None)[source]

Fetch and normalise the public price table.

Parameters:
  • timeout (float) – Seconds to wait for the HTTP response.

  • url (str or None) – Override the source URL (tests point this at a fixture file served locally, or monkeypatch requests.get()).

Returns:

Normalised entries, one per usable model, sorted by provider then id.

Return type:

list[dict[str, Any]]

Raises:

requests.RequestException – Propagated from the fetch; the CLI turns it into a readable message rather than a traceback.

best_engine_ai_helper.sources.litellm_prices.normalize_price_entry(key, spec, fetched_at)[source]

Turn one LiteLLM table row into a cloud-catalog entry, or None to skip it.

Parameters:
  • key (str) – The table key, either a bare model id or <provider>/<model>.

  • spec (dict[str, Any]) – The row.

  • fetched_at (str) – ISO date stamp recorded on the entry.

Returns:

An entry carrying id, provider, kind, structured_output, input_per_1m, output_per_1m, context_length, source and fetched_at — or None when the row names a provider, mode or id this package cannot use.

Return type:

dict[str, Any] or None

Examples

>>> row = {"litellm_provider": "openai", "mode": "chat",
...        "input_cost_per_token": 2.5e-06, "output_cost_per_token": 1e-05,
...        "max_input_tokens": 128000, "supports_vision": True,
...        "supports_response_schema": True}
>>> entry = normalize_price_entry("gpt-4o", row, "2026-10-28")
>>> entry["id"], entry["kind"], entry["input_per_1m"]
('gpt-4o', 'vlm', 2.5)
>>> normalize_price_entry("x", {"litellm_provider": "bedrock"}, "2026-10-28") is None
True