{"record":{"id":"24b85de84e3ef27f","repo":"BerriAI/litellm","slug":"image-response-must-be-of-type-imageresponse-got-t-24b85d","errorCode":null,"errorMessage":"image_response must be of type ImageResponse got type={type(image_response)}","messagePattern":"image_response must be of type ImageResponse got type=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/gemini/image_generation/cost_calculator.py","lineNumber":28,"sourceCode":"    calculate_image_response_web_search_cost,\n)\nfrom litellm.types.utils import ImageResponse\n\n\ndef cost_calculator(\n    model: str,\n    image_response: Any,\n) -> float:\n    \"\"\"\n    Google AI Image Generation Cost Calculator\n    \"\"\"\n    _model_info: Final = litellm.get_model_info(\n        model=model,\n        custom_llm_provider=\"gemini\",\n    )\n\n    if not isinstance(image_response, ImageResponse):\n        raise ValueError(f\"image_response must be of type ImageResponse got type={type(image_response)}\")\n\n    web_search_cost: Final = calculate_image_response_web_search_cost(\n        image_response=image_response,\n        custom_llm_provider=\"gemini\",\n        model_info=_model_info,\n    )\n\n    token_based_cost: Final = calculate_image_response_cost_from_usage(\n        model=model,\n        image_response=image_response,\n        custom_llm_provider=\"gemini\",\n    )\n    if token_based_cost is not None:\n        return token_based_cost + web_search_cost\n\n    output_cost_per_image: Final[float] = _model_info.get(\"output_cost_per_image\") or 0.0\n    num_images: Final[int] = len(image_response.data) if image_response.data else 0\n    return output_cost_per_image * num_images + web_search_cost","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/gemini/image_generation/cost_calculator.py#L10-L46","documentation":"Error \"image_response must be of type ImageResponse got type={type(image_response)}\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/llms/gemini/image_generation/cost_calculator.py:28 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass an ImageResponse object to the Gemini image cost calculator."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}