BerriAI/litellm · error · DashScopeError
raw_response.text (upstream DashScope error body)
Error message
raw_response.text (upstream DashScope error body)
What it means
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.
Source
Thrown at litellm/llms/dashscope/rerank/transformation.py:173
def transform_rerank_response(
self,
model: str,
raw_response: httpx.Response,
model_response: RerankResponse,
logging_obj: LiteLLMLoggingObj,
api_key: str | None = None,
request_data: dict | None = None,
optional_params: dict | None = None,
litellm_params: dict | None = None,
) -> RerankResponse:
request_data = request_data or {}
optional_params = optional_params or {}
litellm_params = litellm_params or {}
try:
response_json: Final = raw_response.json()
except Exception:
raise DashScopeError(
status_code=raw_response.status_code,
message=raw_response.text,
)
logging_obj.post_call(
input=request_data.get("query"),
api_key=api_key,
additional_args={"complete_input_dict": request_data},
original_response=response_json,
)
# DashScope error envelope: {"code": "...", "message": "...", "request_id": "..."}
if "code" in response_json and "results" not in response_json:
raise DashScopeError(
status_code=raw_response.status_code,
message=response_json.get("message", str(response_json)),
)
View on GitHub (pinned to 6c2dcb801b)
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)
Defensive patterns
Strategy: retry
Try / catch
try:
resp = litellm.rerank(model=m, query=q, documents=docs)
except Exception as e:
if "<html" in str(e).lower() or "502" in str(e) or "504" in str(e):
resp = backoff_retry(lambda: litellm.rerank(model=m, query=q, documents=docs))
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- response_json.get("message", str(response_json)) (upstream D
- No results in DashScope rerank response: {response_json}
- message (upstream DashScope response error message)
- DashScope API key is required. Set 'DASHSCOPE_API_KEY' env v
- query is required for DashScope rerank
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/9f9bdc5fbc08bcda.
Report an issue: GitHub.