{"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/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/clarifai/chat/transformation.py#L89-L125","documentation":"OpenAIError raised by the Clarifai adapter when raw_response.json() fails — the Clarifai API replied with a body that is not valid JSON. The status code and headers of the offending response are attached to the error, so a 401 HTML page vs a 200 malformed body is distinguishable. Typically the non-JSON body is an error page from auth failure or a wrong model/user/app path.","triggerScenarios":"Calling completion() with a clarifai/* model where CLARIFAI_API_KEY (PAT) is wrong (error page instead of JSON), the model id user.app.model is malformed, or an upstream gateway returns HTML/empty on 5xx.","commonSituations":"Missing or expired ClarifAI PAT environment variable; model string not in 'user_id.app_id.model_id' form; hitting rate limits or outages that return non-JSON error bodies; region-blocked requests.","solutions":["Verify CLARIFAI_API_KEY is set to a valid Clarifai PAT (starts with 'Key ' or raw PAT depending on setup)","Check the model name has the full user.app.model path, e.g. clarifai/main/your-model","Read the status_code on the error: 401/403 means credentials, 404 means model path, 5xx means retry later","Log raw_response.text (captured in litellm logs) to see the actual non-JSON body returned"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import litellm, os\n\n# smoke-test credentials/path before the real call\ntry:\n    litellm.completion(\n        model=\"clarifai/main/<model_id>\",\n        messages=[{\"role\": \"user\", \"content\": \"ping\"}],\n        max_tokens=1,\n    )\nexcept Exception as e:\n    if \"Failed to parse Clarifai response\" in str(e):\n        raise RuntimeError(\"Clarifai returned a non-JSON body; check CLARIFAI_API_KEY and model path\")","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.completion(model=f\"clarifai/{user}.{app}.{model_id}\", messages=messages)\nexcept litellm.llms.openai.common_utils.OpenAIError as e:\n    if \"Failed to parse Clarifai response\" in str(e):\n        if e.status_code in (401, 403):\n            raise RuntimeError(\"Clarifai PAT invalid/expired\") from e\n        if e.status_code == 404:\n            raise RuntimeError(\"Clarifai model path wrong; use user.app.model\") from e\n    raise","preventionTips":["Validate CLARIFAI_API_KEY is set and non-empty before startup","Always format Clarifai model ids as user_id.app_id.model_id","Run a 1-token smoke request at deploy time to catch credential/path errors early"],"tags":["clarifai","json-parse","http-response","provider-error"],"backgroundTag":"invalid-json-response","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}