千问(Qwen / DashScope)双兼容端点接入说明
#API Key
sk-ws-H.EMXYYPR...ZHSmNhL-(<KEY>)#兼容接口地址
阿里云百炼(DashScope)提供两种兼容模式,同一个 API Key 通用:
#1. Anthropic 兼容接口(Claude 格式)
https://dashscope.aliyuncs.com/apps/anthropic适用于 Anthropic SDK / Claude Code 等按 Anthropic API 格式调用的客户端。
环境变量示例:
export ANTHROPIC_BASE_URL="https://dashscope.aliyuncs.com/apps/anthropic"
export ANTHROPIC_AUTH_TOKEN="你的千问APIKey"#2. OpenAI 兼容接口(OpenAI 格式)
https://dashscope.aliyuncs.com/compatible-mode/v1适用于 OpenAI SDK 或任何支持自定义 base_url 的 OpenAI 格式客户端。
调用示例(Python):
from openai import OpenAI
client = OpenAI(
api_key="你的千问APIKey",
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
resp = client.chat.completions.create(
model="qwen-plus", # 也可用 qwen-max、qwen-turbo 等
messages=[{"role": "user", "content": "你好"}],
)
print(resp.choices[0].message.content)#备注
- 两个接口共用同一个 DashScope API Key。
- 常用模型名:
qwen-max、qwen-plus、qwen-turbo、qwen-coder-plus等。
来源:配置信息/千问API密钥.md(整理于 2026-08-18)