{"record":{"id":"176a992dc3806c4d","repo":"BerriAI/litellm","slug":"raw-response-text-176a99","errorCode":null,"errorMessage":"raw_response.text","messagePattern":"raw_response\\.text","errorType":"exception","errorClass":"CohereError","httpStatus":null,"severity":"error","filePath":"litellm/llms/cohere/chat/v2_transformation.py","lineNumber":199,"sourceCode":"\n    def transform_response(\n        self,\n        model: str,\n        raw_response: httpx.Response,\n        model_response: ModelResponse,\n        logging_obj: LiteLLMLoggingObj,\n        request_data: dict,\n        messages: list[AllMessageValues],\n        optional_params: dict,\n        litellm_params: dict,\n        encoding: Any,\n        api_key: str | None = None,\n        json_mode: bool | None = None,\n    ) -> ModelResponse:\n        try:\n            raw_response_json: Final = raw_response.json()\n        except Exception:\n            raise CohereError(message=raw_response.text, status_code=raw_response.status_code)\n\n        try:\n            cohere_v2_chat_response: Final = CohereV2ChatResponse(**raw_response_json)\n        except Exception:\n            raise CohereError(message=raw_response.text, status_code=422)\n\n        cohere_content: Final = cohere_v2_chat_response[\"message\"].get(\"content\", None)\n        if cohere_content is not None:\n            model_response.choices[0].message.content = \"\".join(\n                [content.get(\"text\", \"\") for content in cohere_content if content is not None]\n            )\n\n        ## ADD CITATIONS AS ANNOTATIONS\n        annotations: list[ChatCompletionAnnotation] | None = None\n        citations = None\n\n        if \"message\" in cohere_v2_chat_response and \"citations\" in cohere_v2_chat_response[\"message\"]:\n            citations = cohere_v2_chat_response[\"message\"][\"citations\"]","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/cohere/chat/v2_transformation.py#L181-L217","documentation":"In the Cohere v2 chat transformation, the first parse step is raw_response.json(). If the body is not valid JSON (empty body, HTML from a gateway, truncated stream), a CohereError is raised with the raw text as message and the response's real status code. This is a decode failure, not a schema failure — schema failures happen one step later (errorIndex 1430).","triggerScenarios":"Cohere v2 chat call (command-r, command-r-plus, command-a via /v2/chat) returning a non-JSON body: 200-with-HTML from a misrouted proxy, an empty 5xx body, or a response corrupted in transit; also a custom api_base serving non-JSON.","commonSituations":"Corporate proxies intercepting TLS and serving block pages; wrong api_base; transient gateway errors. The status_code in the CohereError is the genuine HTTP status, so a 200 + non-JSON body strongly implies a middlebox.","solutions":["Check error.status_code: non-200 means a real API failure whose body is in error.message; 200 + non-JSON means a proxy/gateway intercepted the request.","Verify api_base points at https://api.cohere.com (or compat/v1) if customized.","Retry transient failures with backoff.","Reproduce with curl from the same environment to confirm the raw body."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from litellm.exceptions import CohereError\n\ntry:\n    resp = litellm.completion(model=\"cohere/command-a\", messages=msgs)\nexcept CohereError as e:\n    if e.status_code == 200:\n        # 200 + unparseable body => middlebox interference, not Cohere\n        log_proxy_suspicion(e.message)\n    raise","preventionTips":["Keep api_base at the official Cohere endpoints unless you control the proxy.","Add TLS-inspecting proxies' root CA to the runtime trust store to avoid HTML error pages.","Retry once on decode failures; alert if a pattern emerges."],"tags":["cohere","json-parsing","http-error","proxy"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}