BerriAI/litellm · error · DashScopeError

message (upstream DashScope response error message)

Error message

message (upstream DashScope response error message)

What it means

Raised by LiteLLM's DashScope embeddings handler when the upstream DashScope (Alibaba Cloud) embeddings API returns a body containing an 'error' object. The message is taken verbatim from the upstream error payload, so the text you see is DashScope's own error description. LiteLLM wraps it in DashScopeError along with the HTTP status code from the raw response.

Source

Thrown at litellm/llms/dashscope/embed/transformation.py:148

        try:
            response_json: Final = raw_response.json()
        except Exception as e:
            raise DashScopeError(
                status_code=raw_response.status_code,
                message=f"Failed to parse DashScope response as JSON: {e}",
            )

        logging_obj.post_call(
            input=request_data.get("input"),
            api_key=api_key,
            additional_args={"complete_input_dict": request_data},
            original_response=response_json,
        )

        if "error" in response_json:
            error: Final = response_json["error"]
            message: Final = error.get("message", str(error)) if isinstance(error, dict) else str(error)
            raise DashScopeError(
                status_code=raw_response.status_code,
                message=message,
            )

        model_response.object = "list"
        model_response.data = response_json.get("data", [])
        model_response.model = response_json.get("model", model)

        usage: Final = response_json.get("usage") or {}
        prompt_tokens: Final = usage.get("prompt_tokens", 0)
        total_tokens: Final = usage.get("total_tokens", prompt_tokens)
        setattr(
            model_response,
            "usage",
            Usage(
                prompt_tokens=prompt_tokens,
                completion_tokens=0,
                total_tokens=total_tokens,

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Read the upstream message and status code — they identify the exact DashScope failure (auth, model, limits)
  2. Verify the model name is a valid DashScope embedding model for your account/region
  3. Check that DASHSCOPE_API_KEY is valid and has quota (test with a minimal 1-input embedding call)
  4. Reduce batch size / input length to comply with DashScope embedding limits
  5. If auth-related, rotate the API key in the Alibaba Cloud DashScope console

Example fix

# before
resp = litellm.embedding(model="dashscope/BadModelName", input=["hi"])

# after
resp = litellm.embedding(model="dashscope/text-embedding-v3", input=["hi"], api_key=os.environ["DASHSCOPE_API_KEY"])
Defensive patterns

Strategy: try-catch

Validate before calling

model = "dashscope/text-embedding-v3"
inputs = ["short text"]
assert inputs and all(isinstance(i, str) and 0 < len(i) < 8000 for i in inputs), "invalid embedding input"

Try / catch

from litellm.exceptions import APIError
try:
    resp = litellm.embedding(model=model, input=inputs)
except APIError as e:
    logger.error("DashScope embed failed (%s): %s", getattr(e, 'status_code', '?'), e)
    raise

Prevention

When it happens

Trigger: Calling litellm.embedding() with a DashScope model (e.g. text-embedding-v3/qwen embeddings) and the upstream API responding with a JSON body containing an 'error' key: invalid/expired API key, nonexistent model name, malformed 'input' array, token-per-input limits exceeded, or quota exhaustion.

Common situations: Using a model string not available in your DashScope region/account; sending more inputs or longer texts than the endpoint allows; a DASHSCOPE_API_KEY from a different environment; rate/quota limits on a fresh Alibaba Cloud account.

Related errors


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