Examples¶
Start with a working program, then follow the guide for the capability it uses. The examples live in the SDK repository; use the checkout or tag that matches the SDK version you want to try. See the full repository catalog for every script and its requirements.
Run your first example¶
Clone the Python SDK repository. From its root, create a virtual environment and install that checkout:
python -m venv .venv
source .venv/bin/activate
python -m pip install .
python examples/02_advanced_engineering/local_mock_debugging.py
No API key or cloud request. Look for output text and token usage, then a typed error and an inline error response. See local mock debugging.
export DASHSCOPE_API_KEY="<your-api-key>"
python examples/01_atomic_capabilities/text_generation/chat.py
Look for a complete reply, then text printed incrementally. Set DASHSCOPE_MODEL if needed for your workspace; see configuration. Cloud calls may incur charges.
Find an example by capability¶
| I want to… | Start with | Learn how |
|---|---|---|
| Chat, stream, or make an async request | Chat script | Chat and streaming, async client |
| Ask a question about an image | Multimodal chat | Multimodal |
| Retrieve and rerank knowledge | Embeddings, rerank | Embeddings and rerank |
| Generate images or videos and track tasks | Images, videos | Images and videos |
| Synthesize, transcribe, or start a live session | Audio catalog | Audio, Qwen Live |
| Upload data or monitor fine-tuning | Files, fine-tuning | Files and fine-tuning |
| Count tokens or run a managed agent | Token count, AgentStudio | Tokenization, AgentStudio |
Also see the capability recipes for applications, decision models, TingWu, and model listing.
Go from a call to an application¶
| Layer | What to look for |
|---|---|
01_atomic_capabilities |
Start here for one capability at a time. Read the request shape, response fields, and each script's prerequisites. |
02_advanced_engineering |
Learn offline mocking, client-side caching, and circuit breaking and failover. |
03_agent_recipes |
Combine calls into a tool loop, RAG pipeline, MCP demo, or managed agent. |
04_real_world_scenarios |
Read complete scenarios. RAG, meeting transcription, and ticket triage run offline by default; customer service calls the cloud. |
05_cli |
Use the CLI guide and shell/CI examples for machine-readable output, exit codes, and automation. |
For example, run python examples/04_real_world_scenarios/production_ready_rag_harness.py for an offline demo of retrieval, streaming, and failover. Use a test workspace for examples that create cloud resources. The legacy_1x directory is archived; use the current layers for new projects and the migration guide for 1.x code.