The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
refactor(cost_map): drop docstrings from the provenance helpers and their tests
mateo-berri41c0897c7aa2
diff --git a/litellm/litellm_core_utils/get_model_cost_map.py b/litellm/litellm_core_utils/get_model_cost_map.pyindex 2bdfbc66088..cdc4810ff04 100644--- a/litellm/litellm_core_utils/get_model_cost_map.py+++ b/litellm/litellm_core_utils/get_model_cost_map.py@@ -45,7 +45,6 @@ def _count_model_entries(model_cost: dict) -> int:def git_blob_id(body: bytes) -> str:- """The sha1 git gives these bytes as a blob, so ``git rev-parse <commit>:<path>`` reproduces it for the file"""return hashlib.sha1(b"blob %d\0" % len(body) + body, usedforsecurity=False).hexdigest()@@ -70,7 +69,6 @@ class GetModelCostMap:@staticmethoddef load_local_model_cost_map_with_revision() -> "ModelCostMapReloaded":- """The bundled backup map together with the git blob id of the file it was parsed from"""body: Final = GetModelCostMap.read_local_model_cost_map_bytes()content: Final = json.loads(body)return ModelCostMapReloaded(model_cost_map=content, revision=git_blob_id(body))@@ -413,9 +411,6 @@ class CostMapSourceInfo(CostMapProvenance):def get_model_cost_map_provenance() -> CostMapProvenance:- """Which revision of the cost map this process serves: the git blob id of the bytes it loaded, the- same id ``git rev-parse <commit>:model_prices_and_context_window.json`` prints for a checkout, plus- the ETag the remote fetch returned (None for the bundled backup)"""return {"source_revision": _cost_map_source_info.source_revision,"etag": _cost_map_source_info.etag,@@ -520,7 +515,6 @@ def _finalize_model_cost_map(model_cost: dict) -> dict:def _finalize_loaded_model_cost_map(loaded: ModelCostMapReloaded) -> ModelCostMapReloaded:- """Record which bytes this process now serves, then finalize the map they parsed into"""_cost_map_source_info.source_revision = loaded.revision_cost_map_source_info.etag = loaded.etagreturn replace(loaded, model_cost_map=_finalize_model_cost_map(loaded.model_cost_map))diff --git a/tests/test_litellm/litellm_core_utils/test_get_model_cost_map.py b/tests/test_litellm/litellm_core_utils/test_get_model_cost_map.pyindex 7c3ad283639..18794ea7eec 100644--- a/tests/test_litellm/litellm_core_utils/test_get_model_cost_map.py+++ b/tests/test_litellm/litellm_core_utils/test_get_model_cost_map.py@@ -40,8 +40,6 @@ def _bundled_blob_id() -> str:def test_git_blob_id_is_what_git_hash_object_prints():- """An operator checks a reported revision with ``git hash-object`` or ``git rev-parse <commit>:<path>``,- so the id must be git's blob sha1 of the exact bytes, not a plain sha1 or a hash of the parsed JSON."""assert git_blob_id(b'{"gpt-5.4-mini": {"mode": "chat"}}\n') == "18b9a8381e13a3b38a2128f184f631f95829e987"@@ -516,9 +514,6 @@ async def test_refetch_respects_local_env_override(monkeypatch):@pytest.mark.asyncioasync def test_refetch_records_the_blob_id_of_the_bytes_served_and_the_fetch_etag():- """A reload reports which revision of the map it swapped in: the git blob id of the exact bytes the- fetch returned, so ``git rev-parse <commit>:model_prices_and_context_window.json`` can confirm it,- plus the ETag the fetch returned."""body = _real_map_bytes()client, _ = _mock_client([httpx.Response(200, headers={"ETag": 'W/"abc123"'}, content=body)])@@ -532,7 +527,6 @@ async def test_refetch_records_the_blob_id_of_the_bytes_served_and_the_fetch_eta@pytest.mark.asyncioasync def test_refetch_revision_follows_the_bytes_not_the_url():- """Two fetches of the same URL that return different bytes report different revisions."""edited = json.loads(_real_map_bytes())edited["gpt-5.4-mini"]["input_cost_per_token"] = 0.5client, _ = _mock_client(@@ -549,8 +543,6 @@ async def test_refetch_revision_follows_the_bytes_not_the_url():@pytest.mark.asyncioasync def test_refetch_local_override_reports_the_bundled_blob_id_without_an_etag(monkeypatch):- """Forcing the bundled backup after a remote reload must report the backup's own blob id and drop the- remote ETag, since the map served is no longer the one that ETag identifies."""remote, _ = _mock_client([httpx.Response(200, headers={"ETag": 'W/"remote"'}, content=_real_map_bytes())])await refetch_model_cost_map(url=_URL, sleep=_SleepRecorder(), rng=random.Random(0), client=remote)monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True")@@ -670,8 +662,6 @@ def test_boot_load_records_the_blob_id_of_the_bytes_served_and_the_fetch_etag():def test_boot_load_fallback_to_the_backup_reports_its_blob_id_and_drops_the_remote_etag():- """A boot that lands on the bundled backup reports the backup's own blob id and no ETag, even- when an earlier load in the same process had fetched the remote map."""remote, _ = _mock_client([httpx.Response(200, headers={"ETag": 'W/"boot"'}, content=_real_map_bytes())], client_cls=httpx.Client)@@ -687,8 +677,6 @@ def test_boot_load_fallback_to_the_backup_reports_its_blob_id_and_drops_the_remodef test_boot_load_that_fails_the_integrity_check_reports_the_backup_not_the_rejected_fetch():- """A fetch that succeeds but fails integrity validation is thrown away, so the provenance must- describe the backup that got loaded, never the ETag or bytes of the map that was rejected."""remote, _ = _mock_client([httpx.Response(200, headers={"ETag": 'W/"boot"'}, content=_real_map_bytes())], client_cls=httpx.Client)diff --git a/tests/test_litellm/proxy/proxy_server/test_routes_model_cost_map.py b/tests/test_litellm/proxy/proxy_server/test_routes_model_cost_map.pyindex 0490993a314..36c364fb82b 100644--- a/tests/test_litellm/proxy/proxy_server/test_routes_model_cost_map.py+++ b/tests/test_litellm/proxy/proxy_server/test_routes_model_cost_map.py@@ -50,7 +50,6 @@ def _attach_litellm_config(mock_prisma):def _pin_provenance(monkeypatch):- """Fix what this process reports as its cost map revision, independent of the map loaded at import."""monkeypatch.setattr("litellm.litellm_core_utils.get_model_cost_map.get_model_cost_map_provenance",lambda: dict(_PROVENANCE),@@ -110,8 +109,6 @@ def test_reload_model_cost_map_happy(client, auth_as, monkeypatch, mock_prisma):def test_reload_model_cost_map_surfaces_the_blob_id_of_the_bytes_served_on_every_status_surface(client, auth_as, monkeypatch, mock_prisma):- """A real refetch through the reload route reports the git blob id of the exact bytes it fetched and- the fetch ETag on the reload response, the source route, and the schedule status alike."""import httpximport litellm