Skip to content

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]

fix(cost): keep the deployment's OCR page rate when the model has no published price

mateo-berridd79c1f77d7f
diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py
index 04c9675cc83..38758867a11 100644
--- a/litellm/cost_calculator.py
+++ b/litellm/cost_calculator.py
@@ -2151,11 +2151,11 @@ def ocr_batch_cost(
)
if needs_published_pricing and published is None:
verbose_logger.warning(
- "OCR batch cost: model=%s custom_llm_provider=%s has no pricing entry; returning 0.0 cost.",
+ "OCR batch cost: model=%s custom_llm_provider=%s has no pricing entry; "
+ "billing only the per-page families the deployment prices.",
_single_log_line(model),
_single_log_line(custom_llm_provider),
)
- return 0.0, 0.0
page_rate: Final = (
deployment_page_rate
diff --git a/tests/test_litellm/batches/test_batch_utils.py b/tests/test_litellm/batches/test_batch_utils.py
index 1e7e0200754..708c472939e 100644
--- a/tests/test_litellm/batches/test_batch_utils.py
+++ b/tests/test_litellm/batches/test_batch_utils.py
@@ -1957,6 +1957,19 @@ def test_ocr_rows_keep_the_published_page_rate_when_the_deployment_prices_only_a
assert result.cost == pytest.approx(4 * 0.002 + 4 * 0.01)
+def test_ocr_rows_keep_the_deployment_page_rate_when_the_unmapped_model_has_no_annotation_price(monkeypatch):
+ def _unmapped(model, custom_llm_provider=None):
+ raise Exception(f"This model isn't mapped yet: {model}")
+
+ monkeypatch.setattr(litellm, "get_model_info", _unmapped)
+ result = bu._aggregate_batch_cost_usage_models(
+ entries=[_ocr_row(4, annotation_pages=4, model="my-private-ocr-model")],
+ custom_llm_provider="mistral",
+ model_info={"ocr_cost_per_page_batches": 0.001},
+ )
+ assert result.cost == pytest.approx(4 * 0.001 + 4 * 0.001)
+
+
def test_ocr_rows_bill_the_deployment_sync_page_rate_over_the_published_batch_rate(monkeypatch):
monkeypatch.setattr(
litellm, "get_model_info", lambda model, custom_llm_provider=None: pytest.fail("cost map must not be consulted")