Skip to main content

DashScope Python SDK

The DashScope Python SDK provides a comprehensive interface to Alibaba Cloud Model Studio (Bailian) APIs, covering text generation, multi-modal understanding, embeddings, reranking, image/video generation, speech synthesis & recognition, and more.

What is New

v1.27.0 ships an interactive AI assistant — DashScope SDK Expert. Run dashscope with no arguments (or ask directly, e.g. dashscope "how do I stream Generation output") to get SDK/API answers, runnable examples, CLI usage, and error diagnosis right in your terminal. Guidance is drawn from per-domain quick-reference skills (text, multimodal, speech, retrieval, fine-tuning, agent, cli) built on the SDK's public interfaces — parameters, outputs, and error codes — so you can ask instead of reading the docs. Type /help inside the assistant to view available commands.

Installation

To install the DashScope Python SDK, simply run:

pip install dashscope

If you clone the code from github, you can install from source by running:

pip install -e .

To use tokenizer in local mode without downloading any files, run:

pip install dashscope[tokenizer]

Quick Start

from http import HTTPStatus
from dashscope import Generation

responses = Generation.call(
    model="qwen-plus",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Who are you?"},
    ],
    result_format="message",
)

if responses.status_code == HTTPStatus.OK:
    print(responses.output.choices[0].message.content)
else:
    print(f"Error: {responses.code} - {responses.message}")

API Key Authentication

The SDK uses API key for authentication. Please refer to official documentation for alibabacloud china and official documentation for alibabacloud international regarding how to obtain your api-key.

Using the API Key

  1. Set the API key via code
import dashscope

dashscope.api_key = 'YOUR-DASHSCOPE-API-KEY'
# Or specify the API key file path via code
# dashscope.api_key_file_path='~/.dashscope/api_key'
  1. Set the API key via environment variables

a. Set the API key directly using the environment variable below

export DASHSCOPE_API_KEY='YOUR-DASHSCOPE-API-KEY'

b. Specify the API key file path via an environment variable

export DASHSCOPE_API_KEY_FILE_PATH='~/.dashscope/api_key'
  1. Save the API key to a file
from dashscope import save_api_key

save_api_key(api_key='YOUR-DASHSCOPE-API-KEY',
             api_key_file_path='api_key_file_location or (None, will save to default location "~/.dashscope/api_key"')

AI Assistant: DashScope SDK Expert

The SDK ships with an interactive AI assistant, DashScope SDK Expert, built on the bundled Agentic CLI (dashscope/acli) framework. For DashScope SDK/CLI users it is the recommended way to get development consultation and AI coding help — answering SDK/API questions, generating runnable examples, showing CLI usage, and diagnosing errors, right in your terminal.

  • Run dashscope with no arguments to start the assistant. On first run it offers to install the SDK Expert knowledge pack (per-domain quick-reference skills: text, multimodal, speech, retrieval, fine-tuning, agent, cli), so guidance comes from the SDK's public interfaces — parameters, outputs, error codes — without reading the source
  • Ask it instead of reading docs — e.g. dashscope "how do I stream Generation output" or dashscope "CLI command to cancel a fine-tuning job". Type /help inside the assistant to list available commands (/setup, /skill, /stats, ...); classic SDK subcommands still work, and unrecognized commands are routed to the assistant

Supported Models

Category Recommended Models SDK Class
Text Generation qwen3.8-max, qwen3.7-max, qwen3.7-plus, qwen3.6-flash Generation
Multi-Modal Understanding qwen3.5-omni-plus, qwen3.7-plus (vision) MultiModalConversation
Text Embedding text-embedding-v4, text-embedding-v3 TextEmbedding
Multi-Modal Embedding tongyi-embedding-vision-plus, qwen3-vl-embedding MultiModalEmbedding
Text ReRank qwen3-rerank, gte-rerank-v2 TextReRank
Image Generation wan2.7-image-pro, qwen-image-2.0-pro ImageSynthesis
Video Generation wan2.7-t2v, wan2.7-i2v, happyhorse-1.0-t2v/i2v VideoSynthesis
Speech Synthesis (TTS) cosyvoice-v3.5-plus, cosyvoice-v1 SpeechSynthesizer, HttpSpeechSynthesizer
Speech Recognition (ASR) fun-asr-realtime, fun-asr, paraformer-v1 Transcription
Omni (Real-time) qwen3.5-omni-plus-realtime MultiModalConversation

For the latest model list, visit Bailian Model Plaza.

Logging

To output Dashscope logs, you need to configure the logger.

export DASHSCOPE_LOGGING_LEVEL='info'

Output

The output contains the following fields:

     request_id (str): The request id.
     status_code (int): HTTP status code, 200 indicates that the
         request was successful, others indicate an error.
     code (str): Error code if error occurs, otherwise empty str.
     message (str): Set to error message on error.
     output (Any): The request output.
     usage (Any): The request usage information.

License

This project is licensed under the Apache License (Version 2.0).

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dashscope-1.27.1-py3-none-any.whl (1.9 MB view details)

Uploaded Python 3

File details

Details for the file dashscope-1.27.1-py3-none-any.whl.

File metadata

  • Download URL: dashscope-1.27.1-py3-none-any.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.3

File hashes

Hashes for dashscope-1.27.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8416cfcd08735011ccf240d694d338c0590f7276c1bb735525bc0afc8e53eaf9
MD5 b6802679bd1b3a9fe64bba00d3df954b
BLAKE2b-256 9867c2fde513904a4794d3464b85479c97ff9923dde20b840e53ad5c10ac35ef

See more details on using hashes here.

Release history Release notifications | RSS feed

1.27.2

2 files

This release

1.27.1 This release

1 file

1.27.0

2 files

1.26.7

1 file

1.26.6

2 files

1.26.5

1 file

1.26.4

1 file

1.26.3

2 files

1.26.2

2 files

1.26.1

1 file

1.26.0

2 files

1.25.24

1 file

1.25.23

1 file

1.25.22

1 file

1.25.21

1 file

1.25.20

1 file

1.25.19

1 file

1.25.18

1 file

1.25.17

1 file

1.25.16

1 file

1.25.15

1 file

1.25.14

1 file

1.25.13

1 file

1.25.12

1 file

1.25.11

1 file

1.25.10

1 file

1.25.9

1 file

1.25.8

1 file

1.25.7

1 file

1.25.6

1 file

1.25.5

1 file

1.25.4

1 file

1.25.3

1 file

1.25.2

1 file

1.25.1

1 file

1.25.0

1 file

1.24.10

1 file

1.24.9

1 file

1.24.8

1 file

1.24.7

1 file

1.24.6

1 file

1.24.5

1 file

1.24.4

1 file

1.24.3

1 file

1.24.2

1 file

1.24.1

1 file

1.24.0

1 file

1.23.9

1 file

1.23.8

1 file

1.23.7

1 file

1.23.6

1 file

1.23.5

1 file

1.23.4

1 file

1.23.3

1 file

1.23.2

1 file

1.23.1

1 file

1.23.0

1 file

1.22.2

1 file

1.22.1

1 file

1.22.0

1 file

1.21.0

1 file

1.20.14

1 file

1.20.13

1 file

1.20.12

1 file

1.20.11

1 file

1.20.10

1 file

1.20.9

1 file

1.20.8

1 file

1.20.7

1 file

1.20.6

1 file

1.20.5

1 file

1.20.4

1 file

1.20.3

1 file

1.20.2

1 file

1.20.1

1 file

1.20.0

1 file

1.19.3

1 file

1.19.2

1 file

1.19.1

1 file

1.19.0

1 file

1.18.1

1 file

1.18.0

1 file

1.17.1

1 file

1.17.0

1 file

1.16.0

1 file

1.15.0

1 file

1.14.1

1 file

1.14.0

1 file

1.13.6

1 file

1.13.5

1 file

1.13.4

1 file

1.13.3

1 file

1.13.2

1 file

1.13.1

1 file

1.13.0

1 file

1.12.0

1 file

1.11.0

1 file

1.10.1

1 file

1.10.0

1 file

1.9.1

1 file

1.9.0

1 file

1.8.1

1 file

1.8.0

1 file

1.7.2

1 file

1.7.1

1 file

1.7.0

1 file

1.6.0

1 file

1.5.0

1 file

1.4.0

1 file

1.3.1

1 file

1.3.0

1 file

1.2.0

1 file

1.1.1

1 file

1.1.0

1 file

1.0.4

1 file

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page