{"record":{"id":"352ae092945ec7d7","repo":"BerriAI/litellm","slug":"failed-to-parse-dashscope-response-as-json-e","errorCode":null,"errorMessage":"Failed to parse DashScope response as JSON: {e}","messagePattern":"Failed to parse DashScope response as JSON: (.+?)","errorType":"http","errorClass":"DashScopeError","httpStatus":null,"severity":"error","filePath":"litellm/llms/dashscope/embed/transformation.py","lineNumber":133,"sourceCode":"            if value is not None:\n                data[key] = value\n        return data\n\n    def transform_embedding_response(\n        self,\n        model: str,\n        raw_response: httpx.Response,\n        model_response: EmbeddingResponse,\n        logging_obj: LiteLLMLoggingObj,\n        api_key: str | None,\n        request_data: dict,\n        optional_params: dict,\n        litellm_params: dict,\n    ) -> EmbeddingResponse:\n        try:\n            response_json: Final = raw_response.json()\n        except Exception as e:\n            raise DashScopeError(\n                status_code=raw_response.status_code,\n                message=f\"Failed to parse DashScope response as JSON: {e}\",\n            )\n\n        logging_obj.post_call(\n            input=request_data.get(\"input\"),\n            api_key=api_key,\n            additional_args={\"complete_input_dict\": request_data},\n            original_response=response_json,\n        )\n\n        if \"error\" in response_json:\n            error: Final = response_json[\"error\"]\n            message: Final = error.get(\"message\", str(error)) if isinstance(error, dict) else str(error)\n            raise DashScopeError(\n                status_code=raw_response.status_code,\n                message=message,\n            )","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/dashscope/embed/transformation.py#L115-L151","documentation":"LiteLLM's DashScope embedding handler calls raw_response.json() on the HTTP body returned by the embeddings endpoint (default https://dashscope.aliyuncs.com/compatible-mode/v1/embeddings, overridable via api_base or DASHSCOPE_API_BASE) and the body was not valid JSON. The original parser exception is embedded in the message and the error is raised as DashScopeError carrying the upstream HTTP status code. Typical root cause: something other than the DashScope API answered (HTML gateway page, empty body, wrong host).","triggerScenarios":"litellm.embedding(model='dashscope/text-embedding-v3', input=[...]) when DASHSCOPE_API_BASE is mistyped and points at a console/docs URL, a corporate proxy/WAF returns an HTML block page, the connection drops mid-body leaving truncated JSON, or DashScope serves an HTML 5xx page during an outage.","commonSituations":"DASHSCOPE_API_BASE set to a help.aliyun.com or console page instead of the compatible-mode API; egress proxy injecting an auth page; regional outage returning HTML; response garbled by a middlebox so httpx cannot decode it.","solutions":["Inspect the embedded parser exception and, in a debug run, log raw_response.text for the same call — the non-JSON payload (usually HTML) tells you which server actually answered","Verify DASHSCOPE_API_BASE / api_base points at the DashScope compatible-mode endpoint (e.g. https://dashscope.aliyuncs.com/compatible-mode/v1) and not a docs or console page","If the body is a gateway/proxy 5xx page, retry with exponential backoff or fail over to another embedding provider","Bypass or correctly configure corporate proxies (HTTPS_PROXY) so the API response reaches httpx untouched"],"exampleFix":"# before\nos.environ['DASHSCOPE_API_BASE'] = 'https://help.aliyun.com/zh/model-studio'  # docs page -> HTML body\nlitellm.embedding(model='dashscope/text-embedding-v3', input=['hi'])\n\n# after\nos.environ['DASHSCOPE_API_BASE'] = 'https://dashscope.aliyuncs.com/compatible-mode/v1'\nlitellm.embedding(model='dashscope/text-embedding-v3', input=['hi'])","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.embedding(model='dashscope/text-embedding-v3', input=['hi'])\nexcept Exception as e:\n    status = getattr(e, 'status_code', None)\n    if status is not None and status >= 500:\n        backoff_and_retry()  # transient HTML 5xx page / outage\n    else:\n        log_raw_body_hint(e)  # message embeds the JSON parse exception\n        raise","preventionTips":["Point DASHSCOPE_API_BASE only at the compatible-mode API host, never console/docs URLs","During integration, curl the configured embeddings URL once to assert it answers JSON","Route through a tested proxy config; block pages are the top source of HTML-instead-of-JSON"],"tags":["dashscope","embeddings","json","response-parsing"],"backgroundTag":"invalid-json-response","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}