阿里云百炼 API
阿里云百炼模型服务通过 DashScope 提供。使用 OpenAI 兼容客户端时,请使用 DashScope 兼容模式地址,并通过 DashScope API Key 鉴权。
官方文档:
鉴权
- Header:
Authorization: Bearer $DASHSCOPE_API_KEY - Header:
Content-Type: application/json
Base URL
请按百炼业务空间所在地域选择地址。
Chat Completions
- 方法:
POST - 路径:
/chat/completions - 北京地域完整地址:
https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions
请求参数
请求示例
curl
curl https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-d '{
"model": "qwen-plus",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "用一句话介绍GGPU平台。"
}
],
"temperature": 0.7,
"max_tokens": 512
}'流式调用
请求体中设置 stream: true,客户端按 SSE 流读取返回。
curl https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-d '{
"model": "qwen-plus",
"messages": [
{
"role": "user",
"content": "请分三点说明 API 网关的作用。"
}
],
"stream": true
}'原生异步视频生成
DashScope 视频生成不是 OpenAI 兼容的 Chat Completions 请求。请使用 DashScope 原生异步接口格式:顶层 model,input 放提示词内容,parameters 放生成参数。
- 方法:
POST - 路径:
/api/v1/services/aigc/video-generation/video-synthesis - 北京地域完整地址:
https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis - 必需 Header:
X-DashScope-Async: enable
视频请求参数
curl https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "X-DashScope-Async: enable" \
-d '{
"model": "wanx2.1-t2v-turbo",
"input": {
"prompt": "日出时分的平静海面",
"negative_prompt": "低画质"
},
"parameters": {
"size": "1280*720",
"duration": 5,
"prompt_extend": true,
"watermark": false
}
}'GGPU网关映射
通过GGPU调用时,请保留同样的 OpenAI 兼容请求体,把 Base URL 替换为GGPU网关地址,并把 DashScope API Key 替换为GGPU访问凭证明文。
curl http://127.0.0.1:18080/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <access-credential-secret>" \
-d '{
"model": "qwen-plus",
"messages": [
{
"role": "user",
"content": "用一句话介绍GGPU平台。"
}
]
}'通过GGPU调用 DashScope 原生视频生成时,请保留同样的原生异步请求体,并调用对应的网关路径:
curl http://127.0.0.1:18080/api/v1/services/aigc/video-generation/video-synthesis \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <access-credential-secret>" \
-d '{
"model": "wanx2.1-t2v-turbo",
"input": {
"prompt": "日出时分的平静海面"
},
"parameters": {
"size": "1280*720",
"duration": 5
}
}'