{"record":{"id":"d3d5070ebbea55d0","repo":"BerriAI/litellm","slug":"response-json-get-message-str-response-json","errorCode":null,"errorMessage":"response_json.get(\"message\", str(response_json))","messagePattern":"response_json\\.get\\(\"message\", str\\(response_json\\)\\)","errorType":"exception","errorClass":"DashScopeError","httpStatus":null,"severity":"error","filePath":"litellm/llms/dashscope/rerank/transformation.py","lineNumber":187,"sourceCode":"        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\n        results: Final = response_json.get(\"results\")\n        if results is None:\n            raise DashScopeError(\n                status_code=raw_response.status_code,\n                message=f\"No results in DashScope rerank response: {response_json}\",\n            )\n\n        # qwen3-rerank returns:\n        #   {\"index\": int, \"relevance_score\": float}\n        # plus, when return_documents=true was sent:\n        #   \"document\": {\"text\": \"...\"}\n        # which already matches LiteLLM's RerankResponseDocument shape.\n        transformed_results: Final[list[dict]] = []\n        for r in results:","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/dashscope/rerank/transformation.py#L169-L205","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    out = litellm.rerank(model=m, query=q, documents=docs)\nexcept Exception as e:\n    msg = str(e)\n    status = getattr(e, 'status_code', None)\n    if status == 401 or 'InvalidApiKey' in msg:\n        rotate_credentials()\n    elif status == 429 or 'Throttl' in msg:\n        backoff_and_retry()\n    else:\n        raise","preventionTips":["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"],"tags":["dashscope","rerank","upstream-error","throttling","api-key"],"backgroundTag":"upstream-api-error","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}