{"record":{"id":"ae54ccd0e7090fb0","repo":"BerriAI/litellm","slug":"raw-response-text-ae54cc","errorCode":null,"errorMessage":"raw_response.text","messagePattern":"raw_response\\.text","errorType":"http","errorClass":"OpenAIError","httpStatus":null,"severity":"error","filePath":"litellm/llms/azure_ai/image_generation/mai_transformation.py","lineNumber":209,"sourceCode":"            )\n\n    def transform_image_generation_response(\n        self,\n        model: str,\n        raw_response: httpx.Response,\n        model_response: ImageResponse,\n        logging_obj: \"LiteLLMLoggingObj\",\n        request_data: dict,\n        optional_params: dict,\n        litellm_params: dict,\n        encoding: Any,\n        api_key: str | None = None,\n        json_mode: bool | None = None,\n    ) -> ImageResponse:\n        try:\n            response: Final = raw_response.json()\n        except Exception:\n            raise OpenAIError(message=raw_response.text, status_code=raw_response.status_code)\n\n        if \"usage\" in response:\n            response[\"usage\"] = self.normalize_mai_image_usage(response.get(\"usage\"))\n\n        logging_obj.post_call(\n            input=request_data.get(\"prompt\", \"\"),\n            api_key=api_key,\n            additional_args={\"complete_input_dict\": request_data},\n            original_response=response,\n        )\n\n        image_response: Final[ImageResponse] = convert_to_model_response_object(\n            response_object=response,\n            model_response_object=model_response,\n            response_type=\"image_generation\",\n        )\n\n        width: Final = optional_params.get(\"width\", self.DEFAULT_WIDTH)","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure_ai/image_generation/mai_transformation.py#L191-L227","documentation":"Raised by the Azure AI (MAI) image-generation handler when the upstream HTTP response body cannot be parsed as JSON. The raw response is attempted with raw_response.json(); on any parse failure LiteLLM wraps the body text and HTTP status in an OpenAIError so the caller sees what Azure actually returned instead of a bare JSONDecodeError. Typical causes are non-JSON error pages (HTML auth failures, gateway errors) or truncated bodies.","triggerScenarios":"Calling image generation via the azure_ai/mai provider (e.g. model 'azure_ai/mai/...') and the endpoint returns a non-JSON body: expired/invalid API key returning an HTML or plain-text 401/403, a 5xx from a proxy/gateway, or a malformed gateway timeout page. Any Exception from raw_response.json() (JSONDecodeError, UnicodeDecodeError) hits this branch.","commonSituations":"Misconfigured AZURE_AI_API_KEY or wrong api_base pointing at a gateway that returns HTML error pages; Azure outages returning plain-text 503s; regional endpoint mismatches; using a model name the endpoint doesn't host.","solutions":["Inspect the OpenAIError message: it contains raw_response.text and status_code from Azure — that body is the real upstream error, fix what it reports (auth, endpoint, model).","Verify AZURE_AI_API_KEY / api_key and AZURE_AI_API_BASE point to a valid Azure MAI endpoint with curl -i to confirm it returns JSON.","If a transient 5xx, retry the call or check Azure status; ensure no corporate proxy is injecting HTML error pages.","Confirm the model string is correct for the MAI image-generation route so you don't land on an error page."],"exampleFix":"# before\nresponse = litellm.image_generation(model=\"azure_ai/mai/foo\", prompt=\"a cat\")\n\n# after\nimport litellm\nfrom litellm.exceptions import OpenAIError\ntry:\n    response = litellm.image_generation(model=\"azure_ai/mai/foo\", prompt=\"a cat\")\nexcept OpenAIError as e:\n    # e.message carries Azure's raw body + status; surface it for diagnosis\n    logger.error(\"Azure MAI image call failed: %s\", e)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from litellm.exceptions import OpenAIError\ntry:\n    resp = litellm.image_generation(model=\"azure_ai/mai/<model>\", prompt=p)\nexcept OpenAIError as e:\n    # e.message contains Azure's raw body + status code — log and surface it\n    log.error(\"azure mai image failed: %s\", e)\n    raise","preventionTips":["Verify AZURE_AI_API_KEY and api_base with a direct curl call that returns JSON before wiring into LiteLLM.","Log the wrapped raw_response.text — it names the real upstream problem.","Keep model strings aligned with the MAI image-generation route."],"tags":["azure","image-generation","json-parse","upstream-error"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}