BerriAI/litellm · error · OpenAIError
Failed to parse Clarifai response: {e}
Error message
Failed to parse Clarifai response: {e} What it means
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.
Source
Thrown at litellm/llms/clarifai/chat/transformation.py:107
api_key: str | None = None,
json_mode: bool | None = None,
) -> ModelResponse:
"""
Transform the Clarifai response to a standard ModelResponse.
Since Clarifai is OpenAI-compatible, we use OpenAI response transformation.
"""
## Logging
logging_obj.post_call(
input=messages,
api_key=api_key,
original_response=raw_response.text,
additional_args={"complete_input_dict": request_data},
)
## Reponse
try:
completion_response: Final = raw_response.json()
except Exception as e:
raise OpenAIError(
status_code=raw_response.status_code,
message=f"Failed to parse Clarifai response: {e}",
headers=raw_response.headers,
) from e
response: Final = ModelResponse(**completion_response)
if response.model is not None:
response.model = "clarifai/" + model
return response
def get_error_class(self, error_message: str, status_code: int, headers: dict | httpx.Headers) -> BaseLLMException:
"""
Get the appropriate error class for Clarifai errors.
Since Clarifai is OpenAI-compatible, we use OpenAI error handling.
"""
return OpenAIError(View on GitHub (pinned to 6c2dcb801b)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
import os
def clarifai_config_ready() -> bool:
return bool(os.environ.get("CLARIFAI_API_KEY")) Try / catch
try:
resp = litellm.completion(model="clarifai/<user>/<app>/<model>", messages=msgs)
except OpenAIError as e:
log.error("clarifai parse failure status=%s msg=%.300s", e.status_code, e.message)
if e.status_code and e.status_code >= 500:
backoff_and_retry()
else:
verify_pat_and_model_string() # 4xx: config problem Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Mavvrik FOCUS destination: register failed ({resp.status_cod
- Unable to get json response - {e}, Original Response: {raw_r
- Error parsing response: {raw_response.text}, error: {e}
- raw_response.text
- Failed to transform Braintrust response: {str(e)}
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/dd23b0f11f115db4.
Report an issue: GitHub.