BerriAI/litellm · error · DashScopeError

response_json.get("message", str(response_json)) (upstream D

Error message

response_json.get("message", str(response_json)) (upstream DashScope error message)

What it means

Raised when the DashScope rerank response carries the DashScope error envelope ({"code": ..., "message": ..., "request_id": ...}) without a 'results' field. The exception message is the upstream 'message' value (or the whole body if absent) and the status code comes from the HTTP response.

Source

Thrown at litellm/llms/dashscope/rerank/transformation.py:187

        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)),
            )

        results: Final = response_json.get("results")
        if results is None:
            raise DashScopeError(
                status_code=raw_response.status_code,
                message=f"No results in DashScope rerank response: {response_json}",
            )

        # qwen3-rerank returns:
        #   {"index": int, "relevance_score": float}
        # plus, when return_documents=true was sent:
        #   "document": {"text": "..."}
        # which already matches LiteLLM's RerankResponseDocument shape.
        transformed_results: Final[list[dict]] = []
        for r in results:

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Match the upstream 'code' field in the response body to DashScope's error-code docs to pinpoint the cause
  2. For throttling errors, add retry with exponential backoff and respect QPS limits
  3. For auth errors, refresh DASHSCOPE_API_KEY
  4. For parameter errors, validate model name and documents/query sizes before calling
  5. Include the request_id from the body when opening a support case with Alibaba Cloud
Defensive patterns

Strategy: retry

Try / catch

try:
    resp = litellm.rerank(model=m, query=q, documents=docs)
except Exception as e:
    msg = str(e)
    if "Throttling" in msg or "RateLimit" in msg:
        resp = backoff_retry(lambda: litellm.rerank(model=m, query=q, documents=docs))
    elif "ApiKey" in msg or "Unauthorized" in msg:
        raise ConfigError("DASHSCOPE_API_KEY invalid") from e
    else:
        raise

Prevention

When it happens

Trigger: DashScope rerank API call rejected server-side: invalid model (code InvalidParameter.ModelNotFound), expired API key (InvalidApiKey), throttling (Throttling), or input exceeding limits — any case where the response contains 'code' but no 'results'.

Common situations: Model name typo for qwen3-rerank/gte-rerank variants; API key rotated but old one cached in env; QPS/quota throttling under bursty RAG traffic; documents payload too large.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/551c535bcb48f2a3. Report an issue: GitHub.