agentscope-ai/agentscope · error · RuntimeError
DashScope text embedding API error: {response}
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).
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)
Solutions
- Print the response body to identify the exact status code and message, then fix credentials/model/quota accordingly
- Verify DASHSCOPE_API_KEY is set and valid for the model used
- 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
- Log the full response payload on failure
- Keep batches small to avoid 429s
- Configure max_retries for transient errors
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.
Related errors
- DashScope multimodal embedding API error: {res}
- Text embedding model {self.model!r} only accepts str inputs,
- Invalid input: {item!r}. Expected str or DataBlock.
- Multimodal embedding API only supports URL input for video d
- Unsupported media type {media_type!r} in DataBlock. Expected
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/bc8fbdee7de8acc1.
Report an issue: GitHub.