dashscope
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDashScope
DashScope
Current API
当前API
CRITICAL: DashScope's only supports and . Image generation, TTS, and ASR all use DashScope-native endpoints — not OpenAI-compatible paths.
/compatible-mode/v1//chat/completions/embeddingsAll three tools use .
Authorization: Bearer $DASHSCOPE_API_KEY重要提示: DashScope的接口仅支持和。图像生成、文本转语音(TTS)和自动语音识别(ASR)均使用DashScope原生接口,而非兼容OpenAI的路径。
/compatible-mode/v1//chat/completions/embeddings这三个工具均使用进行身份验证。
Authorization: Bearer $DASHSCOPE_API_KEYImage Generation
图像生成
text
POST https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation- Model: (default),
qwen-image-2.0-pro,qwen-image-max,wan2.7-imagez-image-turbo - Body:
{model, input: {messages: [{role: "user", content: [{text: "prompt"}]}]}, parameters: {size: "W*H", n, prompt_extend, watermark}} - Size format uses asterisk: not
"1024*1024""1024x1024" - Response: (URL, valid ~24h) — must download separately
output.choices[0].message.content[0].image
text
POST https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation- 模型:(默认)、
qwen-image-2.0-pro、qwen-image-max、wan2.7-imagez-image-turbo - 请求体:
{model, input: {messages: [{role: "user", content: [{text: "prompt"}]}]}, parameters: {size: "W*H", n, prompt_extend, watermark}} - 尺寸格式使用星号分隔: ,而非
"1024*1024""1024x1024" - 响应:(图片URL,有效期约24小时)——需单独下载
output.choices[0].message.content[0].image
Text-to-Speech
文本转语音(TTS)
text
POST https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generationSame endpoint as image gen, different body.
- Model: (default),
qwen3-tts-flash,qwen3-tts-instruct-flashqwen-tts-2025-05-22 - Body:
{model, input: {text, voice: "Cherry", language_type: "Auto"}} - Response: (WAV, valid ~24h) — must download separately
output.audio.url
text
POST https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation与图像生成使用相同的接口,但请求体不同。
- 模型:(默认)、
qwen3-tts-flash、qwen3-tts-instruct-flashqwen-tts-2025-05-22 - 请求体:
{model, input: {text, voice: "Cherry", language_type: "Auto"}} - 响应:(WAV格式音频URL,有效期约24小时)——需单独下载
output.audio.url
ASR with Word-Level Timestamps
带词级时间戳的自动语音识别(ASR)
text
POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/transcription
Header: X-DashScope-Async: enable- Model: (NOT
qwen3-asr-flash-filetrans— the sync version has no word timestamps)qwen3-asr-flash - Body:
{model, input: {file_url: "https://public-url/audio.mp3"}, parameters: {enable_words: true, language_hints: ["zh","en"]}} - Returns → poll
task_iduntilGET /api/v1/tasks/{task_id}→ downloadSUCCEEDED→ JSON withoutput.result.transcription_urltranscripts[].sentences[].words[] - Timestamps in /
begin_timeare in milliseconds — the tool normalizes to secondsend_time
text
POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/transcription
Header: X-DashScope-Async: enable- 模型:(注意:不是
qwen3-asr-flash-filetrans,同步版本不支持词级时间戳)qwen3-asr-flash - 请求体:
{model, input: {file_url: "https://public-url/audio.mp3"}, parameters: {enable_words: true, language_hints: ["zh","en"]}} - 返回→ 轮询
task_id直到状态为GET /api/v1/tasks/{task_id}→ 下载SUCCEEDED对应的文件 → 得到包含output.result.transcription_url的JSON数据transcripts[].sentences[].words[] - /
begin_time中的时间戳单位为毫秒——工具会自动将其转换为秒end_time
OpenMontage Usage
OpenMontage 使用方法
Image via selector
通过选择器生成图像
python
from tools.graphics.image_selector import ImageSelector
result = ImageSelector().execute({
"preferred_provider": "dashscope",
"prompt": "一只猫坐在沙发上",
"output_path": "projects/my-video/assets/images/cat.png",
})python
from tools.graphics.image_selector import ImageSelector
result = ImageSelector().execute({
"preferred_provider": "dashscope",
"prompt": "一只猫坐在沙发上",
"output_path": "projects/my-video/assets/images/cat.png",
})TTS via selector
通过选择器生成TTS
python
from tools.audio.tts_selector import TTSSelector
result = TTSSelector().execute({
"preferred_provider": "dashscope",
"text": "如果 AI 真的会改变未来,普通人到底该怎么参与?",
"voice": "Cherry",
"output_path": "projects/my-video/assets/audio/narration.wav",
})python
from tools.audio.tts_selector import TTSSelector
result = TTSSelector().execute({
"preferred_provider": "dashscope",
"text": "如果 AI 真的会改变未来,普通人到底该怎么参与?",
"voice": "Cherry",
"output_path": "projects/my-video/assets/audio/narration.wav",
})ASR directly (word timestamps for subtitles)
直接调用ASR(用于生成带时间戳的字幕)
python
from tools.analysis.dashscope_asr import DashscopeAsr
result = DashscopeAsr().execute({
"audio_url": "https://example.com/narration.wav",
"output_path": "projects/my-video/assets/audio/transcription.json",
})python
from tools.analysis.dashscope_asr import DashscopeAsr
result = DashscopeAsr().execute({
"audio_url": "https://example.com/narration.wav",
"output_path": "projects/my-video/assets/audio/transcription.json",
})result.data["words"] is a flat list of {text, begin_time_seconds, end_time_seconds}
result.data["words"] 是一个扁平化列表,每个元素包含{text, begin_time_seconds, end_time_seconds}
undefinedundefinedRecommended Workflow
推荐工作流程
- Image: Generate a sample first. Check (default) — DashScope rewrites your prompt for better results. Disable if you need literal prompt adherence.
prompt_extend: true - TTS: Generate a 10-15 second sample before full narration. Approve voice and pacing before committing to full generation.
- ASR: Audio must be at a publicly accessible URL. Upload to any public host (S3, etc.) first. Local paths are rejected with a clear error.
- Subtitles: Build from — each word has
result.data["words"]andbegin_time_seconds. Group words into caption phrases by language semantics, not fixed character count.end_time_seconds
- 图像生成:先生成样图。默认开启——DashScope会自动优化你的提示词以获得更好效果。如果需要严格遵循原提示词,可禁用该选项。
prompt_extend: true - 文本转语音:在生成完整旁白前,先生成10-15秒的样音。确认音色和语速合适后,再生成完整内容。
- 自动语音识别:音频文件必须位于可公开访问的URL。需先上传至公共存储服务(如S3等)。本地路径会被直接拒绝并返回明确错误。
- 字幕生成:基于构建字幕——每个单词都包含
result.data["words"]和begin_time_seconds。需根据语义将单词组合成字幕短语,而非按固定字符数分组。end_time_seconds
Parameters
参数说明
Image (dashscope_image
)
dashscope_image图像生成参数(dashscope_image
)
dashscope_image- (required): text prompt
prompt - : default
modelqwen-image-2.0-pro - : default
size— asterisk separator, not "x""1024*1024" - : 1-6 images
n - : things to avoid (max 500 chars)
negative_prompt - : default
prompt_extend— auto-rewrite prompt for better resultstrue - : default
watermarkfalse - : for reproducibility
seed
- (必填):文本提示词
prompt - :默认值为
modelqwen-image-2.0-pro - :默认值为
size——使用星号分隔,而非"x""1024*1024" - :生成图像数量,范围1-6
n - :需要避免的内容(最多500字符)
negative_prompt - :默认值为
prompt_extend——自动优化提示词以获得更好效果true - :默认值为
watermarkfalse - :用于生成可复现的结果
seed
TTS (dashscope_tts
)
dashscope_tts文本转语音参数(dashscope_tts
)
dashscope_tts- (required): text to synthesize (max 600 chars for qwen3-tts-flash)
text - : default
modelqwen3-tts-flash - : default
voice— other voices:"Cherry","Ethan", etc."Chelsie" - : default
language_type—"Auto","Chinese","English","Japanese""Korean" - : natural language delivery instructions (only for
instructions)qwen3-tts-instruct-flash
- (必填):需要合成的文本(qwen3-tts-flash模型最多支持600字符)
text - :默认值为
modelqwen3-tts-flash - :默认值为
voice——其他可选音色包括"Cherry"、"Ethan"等"Chelsie" - :默认值为
language_type——可选值包括"Auto"、"Chinese"、"English"、"Japanese""Korean" - :自然语言风格指令(仅适用于
instructions模型)qwen3-tts-instruct-flash
ASR (dashscope_asr
)
dashscope_asr自动语音识别参数(dashscope_asr
)
dashscope_asr- (required): must be publicly accessible URL
audio_url - :
model(only model that supports word timestamps)qwen3-asr-flash-filetrans - : default
language_hints["zh", "en"] - : default
enable_words— required for word-level timestampstrue - : default
poll_interval_seconds5.0 - : default
timeout_seconds300
- (必填):必须是可公开访问的URL
audio_url - :
model(唯一支持词级时间戳的模型)qwen3-asr-flash-filetrans - :默认值为
language_hints["zh", "en"] - :默认值为
enable_words——开启后才能获取词级时间戳true - :默认值为5.0
poll_interval_seconds - :默认值为300
timeout_seconds
Troubleshooting
故障排查
- Image size error: Use with asterisk, not
"W*H". Example:"WxH"."2048*2048" - TTS no audio URL: Check — if empty, the model name or voice may be wrong.
output.audio.url - ASR "file not accessible": must be publicly reachable. DashScope servers fetch the file; local paths and auth-gated URLs don't work.
audio_url - ASR poll timeout: Increase (default 300). Long audio files take longer to transcribe.
timeout_seconds - ASR no word timestamps: Ensure and model is
enable_words: true(not the syncqwen3-asr-flash-filetrans).qwen3-asr-flash - Auth error (401): Verify is set. Use
DASHSCOPE_API_KEYheader.Authorization: Bearer $KEY
- 图像尺寸错误:使用格式(星号分隔),而非
"W*H"。例如:"WxH"。"2048*2048" - TTS无音频URL:检查——如果为空,可能是模型名称或音色选择错误。
output.audio.url - ASR提示"文件无法访问":必须是可公开访问的地址。DashScope服务器会主动拉取文件,本地路径和需要身份验证的URL均无法使用。
audio_url - ASR轮询超时:增大的值(默认300)。音频文件越长,转录所需时间越久。
timeout_seconds - ASR无词级时间戳:确保已开启,且使用的模型是
enable_words: true(而非同步版本qwen3-asr-flash-filetrans)。qwen3-asr-flash - 身份验证错误(401):确认已配置,且请求头使用
DASHSCOPE_API_KEY格式。Authorization: Bearer $KEY
Safety
安全注意事项
Never print or write the API key to logs, metadata, patches, or project artifacts. should contain only empty variable names. The tool's method redacts the key from error messages.
.env.example_safe_error()切勿将API密钥打印或写入日志、元数据、补丁或项目产物中。文件应仅包含空的变量名。工具的方法会在错误信息中自动屏蔽密钥。
.env.example_safe_error()