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): treat annotation-only deployment pricing as custom OCR pricing

mateo-berri763270e875f9
diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py
index 422e340abf5..09700ad6b72 100644
--- a/litellm/cost_calculator.py
+++ b/litellm/cost_calculator.py
@@ -1999,6 +1999,7 @@ def ocr_cost(
credits: Final = getattr(response.usage_info, "credits", None)
has_custom_ocr_pricing: Final = model_info is not None and (
model_info.get("ocr_cost_per_page") is not None
+ or model_info.get("annotation_cost_per_page") is not None
or (credits is not None and model_info.get("ocr_cost_per_credit") is not None)
)
pricing: Final = model_info if has_custom_ocr_pricing else _cost_map_model_info(model, custom_llm_provider)
diff --git a/tests/test_litellm/test_cost_calculator.py b/tests/test_litellm/test_cost_calculator.py
index a0ae9511aff..a05fadce42d 100644
--- a/tests/test_litellm/test_cost_calculator.py
+++ b/tests/test_litellm/test_cost_calculator.py
@@ -4795,6 +4795,24 @@ def test_ocr_cost_uses_deployment_per_page_pricing_for_unmapped_model(pages_proc
assert cost == pytest.approx(0.004 * pages_processed)
+def test_ocr_cost_uses_deployment_annotation_only_pricing_for_unmapped_model():
+ from litellm.cost_calculator import ocr_cost
+
+ assert UNMAPPED_OCR_MODEL not in litellm.model_cost
+ response: Final = OCRResponse(
+ pages=[OCRPage(index=index, markdown=f"page {index}") for index in range(3)],
+ model=UNMAPPED_OCR_MODEL,
+ usage_info=OCRUsageInfo(pages_processed=3, pages_processed_annotation=2),
+ )
+ cost, _ = ocr_cost(
+ model=UNMAPPED_OCR_MODEL,
+ custom_llm_provider="azure_ai",
+ response=response,
+ model_info={"annotation_cost_per_page": 0.01},
+ )
+ assert cost == pytest.approx(0.01 * 2)
+
+
def test_ocr_cost_uses_deployment_per_credit_pricing_for_unmapped_model():
from litellm.cost_calculator import ocr_cost