{"record":{"id":"de02ad7e2b6c50d8","repo":"BerriAI/litellm","slug":"response-must-be-of-type-ocrresponse-got-type-typ","errorCode":null,"errorMessage":"response must be of type OCRResponse got type={type(response)}","messagePattern":"response must be of type OCRResponse got type=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/cost_calculator.py","lineNumber":1823,"sourceCode":") -> tuple[float, float]:\n    \"\"\"\n    Args:\n        model: str - model name\n        custom_llm_provider: Optional[str] - custom LLM provider\n        response: Optional[Any] - response object\n\n    Returns:\n        Tuple[float, float]: cost of OCR processing\n\n        (Parent function requires a tuple, so we return a tuple. Cost is only in the first element.)\n    \"\"\"\n    from litellm.llms.base_llm.ocr.transformation import OCRResponse\n\n    #########################################################\n    # validate it's an OCR response\n    #########################################################\n    if response is None or not isinstance(response, OCRResponse):\n        raise ValueError(f\"response must be of type OCRResponse got type={type(response)}\")\n\n    if response.usage_info is None:\n        raise ValueError(\"OCR response usage_info is None\")\n\n    try:\n        model_info: ModelInfo | None = litellm.get_model_info(model=model, custom_llm_provider=custom_llm_provider)\n    except Exception:\n        model_info = None\n\n    credits: Final = getattr(response.usage_info, \"credits\", None)\n    cost_per_credit = None\n    if model_info is not None:\n        cost_per_credit = model_info.get(\"ocr_cost_per_credit\")\n    if credits is not None and cost_per_credit is not None:\n        return cost_per_credit * credits, 0.0\n\n    ocr_cost_per_page: float | None = None\n    if model_info is not None:","sourceCodeStart":1805,"sourceCodeEnd":1841,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/cost_calculator.py#L1805-L1841","documentation":"The OCR cost calculator validates its input before pricing: the object passed as `response` is not an OCRResponse (actual type echoed), so usage fields like pages_processed cannot be trusted/read for cost computation.","triggerScenarios":"Thrown at litellm/cost_calculator.py:1823 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass an OCRResponse object to the OCR cost calculation, not a raw dict or other type.","Use litellm.aocr/ocr which returns the properly typed response."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}