{"record":{"id":"dd23b0f11f115db4","repo":"BerriAI/litellm","slug":"failed-to-parse-clarifai-response-e","errorCode":null,"errorMessage":"Failed to parse Clarifai response: {e}","messagePattern":"Failed to parse Clarifai response: (.+?)","errorType":"exception","errorClass":"OpenAIError","httpStatus":null,"severity":"error","filePath":"litellm/llms/clarifai/chat/transformation.py","lineNumber":107,"sourceCode":"        api_key: str | None = None,\n        json_mode: bool | None = None,\n    ) -> ModelResponse:\n        \"\"\"\n        Transform the Clarifai response to a standard ModelResponse.\n        Since Clarifai is OpenAI-compatible, we use OpenAI response transformation.\n        \"\"\"\n        ## Logging\n        logging_obj.post_call(\n            input=messages,\n            api_key=api_key,\n            original_response=raw_response.text,\n            additional_args={\"complete_input_dict\": request_data},\n        )\n        ## Reponse\n        try:\n            completion_response: Final = raw_response.json()\n        except Exception as e:\n            raise OpenAIError(\n                status_code=raw_response.status_code,\n                message=f\"Failed to parse Clarifai response: {e}\",\n                headers=raw_response.headers,\n            ) from e\n\n        response: Final = ModelResponse(**completion_response)\n\n        if response.model is not None:\n            response.model = \"clarifai/\" + model\n\n        return response\n\n    def get_error_class(self, error_message: str, status_code: int, headers: dict | httpx.Headers) -> BaseLLMException:\n        \"\"\"\n        Get the appropriate error class for Clarifai errors.\n        Since Clarifai is OpenAI-compatible, we use OpenAI error handling.\n        \"\"\"\n        return OpenAIError(","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/clarifai/chat/transformation.py#L89-L125","documentation":"Raised as `OpenAIError` (preserving upstream status and headers) when the Clarifai response body cannot be parsed as JSON. The adapter calls `raw_response.json()` inside try/except; failure means the body is not JSON — typically an error page, empty body, or gateway output — even though an HTTP response was received.","triggerScenarios":"Calling `litellm.completion(model=\"clarifai/...\")` where Clarifai's API returns HTML (auth portal, block page), an empty 200, or a truncated body from a gateway timeout (502/504 HTML from a proxy in front of Clarifai).","commonSituations":"Invalid/expired Clarifai PAT causing a redirect to a login page; reverse proxies (nginx, Cloudflare) returning HTML error pages on backend failure; region-blocked endpoints; response truncation on slow links.","solutions":["Verify Clarifai credentials (`CLARIFAI_API_KEY` / PAT) and that the model/user/app IDs in the model string are correct.","Log `raw_response.status_code` and the first bytes of the body — the HTML/status reveals whether it is auth, proxy, or Clarifai-side.","Retry on 5xx/gateway errors; treat 4xx as configuration problems.","Check Clarifai status and your proxy/gateway config if HTML error pages appear."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import os\n\ndef clarifai_config_ready() -> bool:\n    return bool(os.environ.get(\"CLARIFAI_API_KEY\"))","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.completion(model=\"clarifai/<user>/<app>/<model>\", messages=msgs)\nexcept OpenAIError as e:\n    log.error(\"clarifai parse failure status=%s msg=%.300s\", e.status_code, e.message)\n    if e.status_code and e.status_code >= 500:\n        backoff_and_retry()\n    else:\n        verify_pat_and_model_string()  # 4xx: config problem","preventionTips":["Validate the Clarifai PAT and the user/app/model string format before calls.","Log response status and body prefix when this fires to distinguish proxy HTML from Clarifai errors.","Ensure direct (non-intercepting) egress to api.clarifai.com."],"tags":["clarifai","json-parsing","http","auth","proxy"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}