通过阿里云 DashScope API 调用 wan2.6-t2i 模型生成图片,下载到本地桌面,并上传到 catbox.moe 图床获取公网链接。
DASHSCOPE_API_KEY="需要此 KEY 时询问用户"
调用 DashScope 同步接口生成图片:
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer $DASHSCOPE_API_KEY' \
--data '{
"model": "wan2.6-t2i",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"text": "<用户提示词>"
}
]
}
]
},
"parameters": {
"prompt_extend": true,
"watermark": false,
"n": 1,
"negative_prompt": "",
"size": "1280*1280"
}
}'
注意事项:
size 格式使用 分隔(如 12801280),不是 x10241024、12801280、7201280、1280720 等从响应中提取图片 URL,下载到桌面目录:
curl -o ~/Desktop/generated_image.png "<图片URL>"
/home/{用户名}/Desktop/(Linux)或 ~/Desktop/(macOS)将图片上传到 catbox.moe 获取公网永久链接:
curl -F "reqtype=fileupload" -F "fileToUpload=@~/Desktop/generated_image.png" https://catbox.moe/user/api.php
https://files.catbox.moe/xxxx.pngexport DASHSCOPE_API_KEY="sk-ec70253d8fb14e53a679726ad2e1563c"
# 1. 生成图片
RESPONSE=$(curl -s --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
"model": "wan2.6-t2i",
"input": {
"messages": [{"role":"user","content":[{"text":"一只可爱的猫咪"}]}]
},
"parameters": {
"prompt_extend": true,
"watermark": false,
"n": 1,
"negative_prompt": "",
"size": "1280*1280"
}
}')
# 2. 提取图片 URL 并下载
IMAGE_URL=$(echo "$RESPONSE" | python3 -c "import sys,json; print(json.load(sys.stdin)['output']['choices'][0]['message']['content'][0]['image'])")
curl -o ~/Desktop/generated_image.png "$IMAGE_URL"
echo "图片已下载到: $(cd ~/Desktop && pwd)/generated_image.png"
# 3. 上传到 catbox.moe
PUBLIC_URL=$(curl -s -F "reqtype=fileupload" -F "fileToUpload=@$HOME/Desktop/generated_image.png" https://catbox.moe/user/api.php)
echo "公网地址: $PUBLIC_URL"
code 和 message 字段共 1 个版本