From f6b2860c142958911a5c750498cfb2406159e568 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 20 May 2026 19:37:08 +0000 Subject: [PATCH] fix(greptile): warn when OCR cost silently returns 0.0 Address greptile's P2 thread (#3144753707) about ocr_cost silently under-reporting billing when response.usage_info.pages_processed is missing. The credit-priced and unpriced fallback still has to return 0.0 (we don't know how to bill without usage), but emit a warning so the missing-data case is visible in logs instead of disappearing. The per-page-priced branch still raises, preserving the original ValueError signal callers may catch. --- litellm/cost_calculator.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py index 612375faa70..98e00cf5788 100644 --- a/litellm/cost_calculator.py +++ b/litellm/cost_calculator.py @@ -1900,6 +1900,17 @@ def ocr_cost( pages_processed = response.usage_info.pages_processed if pages_processed is None: if cost_per_credit is not None or ocr_cost_per_page is None: + # Surface missing usage data instead of silently under-reporting + # cost. The previous behavior raised ValueError; we now return 0.0 + # for credit-priced or unpriced models, so log a warning to keep + # the regression visible to operators. + verbose_logger.warning( + "OCR cost: model=%s custom_llm_provider=%s response.usage_info." + "pages_processed is None and credits=%s; returning 0.0 cost.", + model, + custom_llm_provider, + credits, + ) return 0.0, 0.0 raise ValueError("OCR response pages_processed is None")