agentscope-ai/agentscope · error · RuntimeError

DashScope text embedding API error

Error message

DashScope text embedding API error: {response}

What it means

Raised when the DashScope text embedding HTTP API returns a non-200 status code; the whole response object is embedded in the message for diagnosis (auth errors, quota, invalid model name, bad request).

Solutions

  1. Print the response body to identify the exact status code and message, then fix credentials/model/quota accordingly
  2. Verify DASHSCOPE_API_KEY is set and valid for the model used
  3. Retry with the built-in retry/backoff for transient 429/5xx and reduce batch size

Example fix

# before
resp = await model(texts)  # raises RuntimeError on failure
# after
try:
    resp = await model(texts)
except RuntimeError as e:
    logging.error("dashscope failed: %s", e)
    raise
Defensive patterns

Strategy: retry

Validate before calling

assert os.getenv(\"DASHSCOPE_API_KEY\"), \"set DASHSCOPE_API_KEY\"

Try / catch

try:\n    await model(texts)\nexcept RuntimeError as e:\n    log.error(\"dashscope: %s\", e)\n    if is_transient(str(e)): await asyncio.sleep(backoff); await model(texts)\n    else: raise

Prevention

When it happens

Trigger: Calling the text embedding model and DashScope returns status != 200: wrong/missing API key, unknown model name, malformed request payload, rate limits, or service outages.

Common situations: DASHSCOPE_API_KEY not set or revoked; using a model id not enabled for the account; hitting QPS/quota limits at high batch sizes.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28). Data as JSON: /api/errors/bc8fbdee7de8acc1. Report an issue: GitHub.

Appendix: source

Thrown at src/agentscope/embedding/_dashscope/_model.py:379

            )
            if cached:
                return EmbeddingResponse(
                    embeddings=cached,
                    usage=EmbeddingUsage(tokens=0, time=0),
                    source="cache",
                )

        import dashscope

        start_time = datetime.now()
        response = dashscope.embeddings.TextEmbedding.call(
            api_key=self.api_key,
            **api_kwargs,
        )
        time = (datetime.now() - start_time).total_seconds()

        if response.status_code != 200:
            raise RuntimeError(
                f"DashScope text embedding API error: {response}",
            )

        embeddings = [
            entry["embedding"] for entry in response.output["embeddings"]
        ]
        if self.embedding_cache:
            await self.embedding_cache.store(
                identifier=api_kwargs,
                embeddings=embeddings,
            )
        return EmbeddingResponse(
            embeddings=embeddings,
            usage=EmbeddingUsage(
                tokens=response.usage["total_tokens"],
                time=time,
            ),
        )

View on GitHub (pinned to e90f1c7592)