BerriAI/litellm · error · DashScopeError
response_json.get("message", str(response_json))
Error message
response_json.get("message", str(response_json)) What it means
DashScope's rerank API signals failures with a top-level envelope {"code": ..., "message": ..., "request_id": ...} and no "results". LiteLLM detects that shape and re-raises DashScopeError with the upstream message (str(response_json) as fallback) and the HTTP status — the text you see is DashScope's own error description.
Solutions
- Act on the upstream message text: InvalidApiKey -> fix/rotate the key; Throttling -> slow down or raise quota; NotFound/model errors -> use a rerank-capable model (gte-rerank / qwen3-rerank families)
- Keep the request_id from your logs when escalating to DashScope support
- For throttling, add client-side rate limiting and retry with backoff honoring Retry-After when present
Defensive patterns
Strategy: try-catch
Try / catch
try:
out = litellm.rerank(model=m, query=q, documents=docs)
except Exception as e:
msg = str(e)
status = getattr(e, 'status_code', None)
if status == 401 or 'InvalidApiKey' in msg:
rotate_credentials()
elif status == 429 or 'Throttl' in msg:
backoff_and_retry()
else:
raise Prevention
- Keep a curated list of rerank-capable model names and validate model against it before calling
- Rate-limit rerank traffic client-side to stay under DashScope QPS
- Persist request_id from logs for support escalation
When it happens
Trigger: Invalid API key (401 envelope); throttling/QPS limits ('Throttling' code); requesting a model that does not support the rerank endpoint (code like 'Algorithm.NotFound'); unsupported parameters in the rerank body.
Common situations: Using an embedding/chat model name on the rerank route; cn-region credentials against the intl endpoint; bursty background jobs hitting per-account QPS; newly rotated key not yet deployed.
Related errors
- DashScope API key is required. Set 'DASHSCOPE_API_KEY' env…
- {error.message}
- DASHSCOPE_API_KEY is not set
- documents is required for DashScope rerank
- err.response.text
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/d3d5070ebbea55d0.
Report an issue: GitHub.
Appendix: 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 77b7c6c40c)