{"record":{"id":"9f9bdc5fbc08bcda","repo":"BerriAI/litellm","slug":"raw-response-text-upstream-dashscope-error-body","errorCode":null,"errorMessage":"raw_response.text (upstream DashScope error body)","messagePattern":"raw_response\\.text \\(upstream DashScope error body\\)","errorType":"http","errorClass":"DashScopeError","httpStatus":null,"severity":"error","filePath":"litellm/llms/dashscope/rerank/transformation.py","lineNumber":173,"sourceCode":"\n    def transform_rerank_response(\n        self,\n        model: str,\n        raw_response: httpx.Response,\n        model_response: RerankResponse,\n        logging_obj: LiteLLMLoggingObj,\n        api_key: str | None = None,\n        request_data: dict | None = None,\n        optional_params: dict | None = None,\n        litellm_params: dict | None = None,\n    ) -> RerankResponse:\n        request_data = request_data or {}\n        optional_params = optional_params or {}\n        litellm_params = litellm_params or {}\n        try:\n            response_json: Final = raw_response.json()\n        except Exception:\n            raise DashScopeError(\n                status_code=raw_response.status_code,\n                message=raw_response.text,\n            )\n\n        logging_obj.post_call(\n            input=request_data.get(\"query\"),\n            api_key=api_key,\n            additional_args={\"complete_input_dict\": request_data},\n            original_response=response_json,\n        )\n\n        # DashScope error envelope: {\"code\": \"...\", \"message\": \"...\", \"request_id\": \"...\"}\n        if \"code\" in response_json and \"results\" not in response_json:\n            raise DashScopeError(\n                status_code=raw_response.status_code,\n                message=response_json.get(\"message\", str(response_json)),\n            )\n","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/dashscope/rerank/transformation.py#L155-L191","documentation":"Raised when the DashScope rerank response body cannot be parsed as JSON. LiteLLM falls back to raising DashScopeError with the raw response text as the message and the HTTP status from the response, so the body (often an HTML error page or proxy message) appears in the exception text.","triggerScenarios":"DashScope or an intermediate proxy/gateway returns a non-JSON body: HTML 502/504 from a gateway, a WAF block page, a plain-text overload message, or truncated response due to connection reset.","commonSituations":"Corporate proxies or self-managed gateways in front of dashscope.aliyuncs.com; transient CDN/gateway errors during Alibaba Cloud incidents; regional endpoint (dashscope-intl) routed through a filtering proxy.","solutions":["Inspect the raw text in the exception message — it usually reveals the proxy/gateway source of the non-JSON body","Retry with backoff; transient gateway errors commonly resolve on retry","If a corporate proxy is in play, add an exception/bypass for the DashScope domain","Check Alibaba Cloud status page for ongoing DashScope incidents","Confirm you are using the correct endpoint (international vs China mainland base URL)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.rerank(model=m, query=q, documents=docs)\nexcept Exception as e:\n    if \"<html\" in str(e).lower() or \"502\" in str(e) or \"504\" in str(e):\n        resp = backoff_retry(lambda: litellm.rerank(model=m, query=q, documents=docs))\n    else:\n        raise","preventionTips":["Wrap rerank calls with bounded exponential-backoff retry for gateway-class failures","Monitor for non-JSON bodies as a signal of proxy misconfiguration on the DashScope route"],"tags":["dashscope","rerank","network","upstream-error"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}