BerriAI/litellm · error · ValueError
response must be of type OCRResponse got type=
Error message
response must be of type OCRResponse got type={type(response)} What it means
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.
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.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at litellm/cost_calculator.py:1823 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/de02ad7e2b6c50d8.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/cost_calculator.py:1823
) -> tuple[float, float]:
"""
Args:
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:View on GitHub (pinned to 77b7c6c40c)