BerriAI/litellm · error · ValueError

OCR response usage_info is None

Error message

OCR response usage_info is None

What it means

The object passed the isinstance check for an OCRResponse, but its usage_info field is None. The OCR cost helper requires usage_info to extract token counts, so it raises instead of computing a cost from nothing.

Solutions

  1. The OCR provider response is missing usage_info; update litellm or check the provider integration.
  2. As a workaround, compute cost manually from pages processed.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/cost_calculator.py:1826 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/acc44e351a44b943. Report an issue: GitHub.

Appendix: source

Thrown at litellm/cost_calculator.py:1826

        model: str - model name
        custom_llm_provider: Optional[str] - custom LLM provider
        response: Optional[Any] - response object

    Returns:
        Tuple[float, float]: cost of OCR processing

        (Parent function requires a tuple, so we return a tuple. Cost is only in the first element.)
    """
    from litellm.llms.base_llm.ocr.transformation import OCRResponse

    #########################################################
    # validate it's an OCR response
    #########################################################
    if response is None or not isinstance(response, OCRResponse):
        raise ValueError(f"response must be of type OCRResponse got type={type(response)}")

    if response.usage_info is None:
        raise ValueError("OCR response usage_info is None")

    try:
        model_info: ModelInfo | None = litellm.get_model_info(model=model, custom_llm_provider=custom_llm_provider)
    except Exception:
        model_info = None

    credits: Final = getattr(response.usage_info, "credits", None)
    cost_per_credit = None
    if model_info is not None:
        cost_per_credit = model_info.get("ocr_cost_per_credit")
    if credits is not None and cost_per_credit is not None:
        return cost_per_credit * credits, 0.0

    ocr_cost_per_page: float | None = None
    if model_info is not None:
        ocr_cost_per_page = model_info.get("ocr_cost_per_page")

    pages_processed: Final = response.usage_info.pages_processed

View on GitHub (pinned to 77b7c6c40c)