Errors and diagnosis¶
The SDK raises DashScopeError subclasses by default for request failures. Log code, status_code and request_id for investigation; avoid printing credentials or raw request and response bodies to shared logs.
from dashscope import Client, DashScopeError
from dashscope.devkit.diagnosis import render
try:
with Client() as client:
result = client.chat.completions.create(
model="qwen-plus", messages=[{"role": "user", "content": "Hello"}],
)
print(result.output_text)
except DashScopeError as exc:
print(exc.code, exc.status_code, exc.request_id)
diagnosis = exc.diagnosis
if diagnosis is not None:
print(render(diagnosis, lang="en"))
What to do next¶
| Symptom | Start here |
|---|---|
| 401 or 403 | Check that the key, region, workspace and model permission match. Do not keep retrying invalid credentials. |
| 429 | Reduce concurrency and respect server backoff. Check the SDK's max_retries before adding an application retry loop. |
ValueError before sending |
Check local parameters and configuration; this is not necessarily a service error. |
| Stream breaks after the first chunk | An underlying transport error may propagate. There is no automatic resume; decide how to handle partial output, and avoid blindly repeating tool actions or job submissions. |
Diagnosis is local and may not match every error. See the exception hierarchy for types, and local mock debugging to test failure handling offline.