外观
阿里云百炼使用
阿里云百炼云平台
介绍
阿里云百炼是一站式大模型开发与应用平台,集成了通义千问及主流第三方模型。它为开发者提供了兼容OpenAI的API及全链路模型服务;同时,也提供可视化应用构建能力,让业务人员能快速创建智能体、知识库问答等AI应用。
获取API KEY
- 登录阿里云百炼——应用开发——应用管理——立即创建

- 创建后,选择模型——更多,选择“通义千问3-Max”。然后点击发布。
- 应用发布成功后,返回到应用开发——应用管理,能看到上面创建并发布的
大模型测试

- 点击密钥管理——创建API-KEY,选择用户——确定。复制并保管好API KEY,不要对外泄露。
聊天机器人示例
- 登录阿里云百炼——模型服务——模型广场,点击
通义千文3-Max - 可以看到免费的额度,以及代码示例

参考资料
请求示例
使用Apifox请求
登录阿里云百炼——模型服务——模型广场,点击通义千文3-Max,点击“查看API示例”
bash
curl -X POST https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen-plus",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "你是谁?"
}
]
}'Apifox访问百炼模型API:新建快捷请求,参考上面代码填写
- 设置请求方式:
POST,填写URL地址 - 设置
Headers,设置Body参数

使用OpenAI库请求-非流式
非流式请求
python
from openai import OpenAI
client = OpenAI(
api_key="sk-",
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="deepseek-v3.2",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "你好"},
],
)
# 非流式响应
print(completion.model_dump_json())非流式响应
json
{
"id": "chatcmpl-b88f8ac8-b573-9cd4-b114-d95fab1766d2",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"logprobs": null,
"message": {
"content": "你好!很高兴见到你。有什么我可以帮助你的吗?无论是解答问题、提供建议,还是闲聊,我都很乐意陪伴你哦! 😊",
"refusal": null,
"role": "assistant",
"annotations": null,
"audio": null,
"function_call": null,
"tool_calls": null
}
}
],
"created": 1769505790,
"model": "deepseek-v3.2",
"object": "chat.completion",
"service_tier": null,
"system_fingerprint": null,
"usage": {
"completion_tokens": 31,
"prompt_tokens": 11,
"total_tokens": 42,
"completion_tokens_details": null,
"prompt_tokens_details": { "audio_tokens": null, "cached_tokens": 0 }
}
}使用OpenAI库请求-流式
流式请求
python
from openai import OpenAI
client = OpenAI(
api_key="sk-",
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="deepseek-v3.2",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "你好"},
],
stream=True,
)
# 流式响应处理
for chunk in completion:
# print(chunk.choices[0].delta.content, end="", flush=True)
print(chunk)