
Qwen 3.5 API:通过 OpenRouter 和阿里云调用 Qwen 模型
如果你在搜 qwen 3.5 api,说明你想通过代码调用 Qwen 3.5 模型,而不想自己管理基础设施。目前主要有两条路:OpenRouter,一个聚合了多家模型供应商的统一 API;以及阿里云灵积(DashScope),Qwen 团队的官方第一方 API。
这篇文章两个方案都会讲,并附上可用的代码示例。如果你只想和 Qwen 3.5 对话,完全不想写代码,可以先免费试用 Qwen 3.5。
API 方案概览
| 供应商 | 接口风格 | 核心优势 |
|---|---|---|
| OpenRouter | OpenAI 兼容 | 一个 API Key 访问多家模型,方便切换 |
| 阿里云灵积 DashScope | OpenAI 兼容 | 第一方官方 API,价格有竞争力 |
两家供应商都提供 OpenAI 兼容接口,这意味着你现有的 OpenAI SDK 代码只需改动极少就能对接 Qwen 3.5。
通过 OpenRouter 使用 Qwen 3.5
OpenRouter 的流行在于它让你通过一个 API 访问多家供应商的模型。Qwen 3.5 模型和其他系列模型并列提供,方便对比和切换。
获取 API Key
- 访问 openrouter.ai
- 注册或登录
- 进入 API Keys 页面
- 创建新的 API Key
Python 示例(OpenRouter)
import openai
client = openai.OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key="your-openrouter-api-key"
)
response = client.chat.completions.create(
model="qwen/qwen3.5-7b-instruct",
messages=[
{"role": "system", "content": "你是一个有帮助的助手。"},
{"role": "user", "content": "介绍一下 Qwen 3.5 的主要改进。"}
],
max_tokens=512
)
print(response.choices[0].message.content)curl 示例(OpenRouter)
curl https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer your-openrouter-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen/qwen3.5-7b-instruct",
"messages": [
{"role": "user", "content": "什么是混合专家模型?"}
],
"max_tokens": 256
}'OpenRouter 上的 Qwen 3.5 模型 ID
OpenRouter 上常见的模型 ID(以最新列表为准):
qwen/qwen3.5-7b-instructqwen/qwen3.5-32b-instructqwen/qwen3.5-72b-instruct
具体模型 ID 可能会随 OpenRouter 更新而变化,请查看其模型页面获取最新列表。
通过阿里云灵积使用 Qwen 3.5
灵积(DashScope)是阿里云的 AI 模型服务平台,也是 Qwen API 的官方归属地。它通常提供最全的 Qwen 模型选择和最有竞争力的价格。
获取 API Key
- 访问 dashscope.aliyuncs.com
- 创建阿里云账号(或登录已有账号)
- 开通灵积服务
- 在控制台生成 API Key
Python 示例(DashScope)
DashScope 同样支持 OpenAI 兼容格式:
import openai
client = openai.OpenAI(
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
api_key="your-dashscope-api-key"
)
response = client.chat.completions.create(
model="qwen3.5-7b-instruct",
messages=[
{"role": "system", "content": "你是一个有帮助的助手。"},
{"role": "user", "content": "对比一下 dense 模型和 MoE 模型架构。"}
],
max_tokens=512
)
print(response.choices[0].message.content)curl 示例(DashScope)
curl https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer your-dashscope-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.5-7b-instruct",
"messages": [
{"role": "user", "content": "什么是 PagedAttention?"}
],
"max_tokens": 256
}'DashScope 上的 Qwen 3.5 模型 ID
常见模型 ID:
qwen3.5-7b-instructqwen3.5-14b-instructqwen3.5-32b-instructqwen3.5-72b-instructqwen3.5-moe-a3b-instruct
作为第一方供应商,DashScope 通常拥有最完整的模型选择。
定价概览
API 定价因供应商和模型大小而异,以下是大致参考:
| 模型 | 供应商 | 输入(每百万 token) | 输出(每百万 token) |
|---|---|---|---|
| Qwen3.5-7B-Instruct | OpenRouter | ~$0.10 | ~$0.10 |
| Qwen3.5-32B-Instruct | OpenRouter | ~$0.30 | ~$0.30 |
| Qwen3.5-7B-Instruct | DashScope | ~$0.05 | ~$0.10 |
| Qwen3.5-32B-Instruct | DashScope | ~$0.20 | ~$0.40 |
这些价格是近似值,经常变动。务必查看供应商的最新定价页面获取准确数字。DashScope 通常为新用户提供免费试用额度。
流式响应
两家供应商都支持流式输出,这对聊天应用至关重要:
stream = client.chat.completions.create(
model="qwen3.5-7b-instruct",
messages=[
{"role": "user", "content": "写一首关于人工智能的短诗。"}
],
max_tokens=256,
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")由于 OpenRouter 和 DashScope 都遵循 OpenAI 流式格式,这段代码在两个平台上的用法完全相同。
如何选择 API 供应商
选择 OpenRouter 当你:
- 想用一个 API Key 访问多家模型供应商
- 在对比 Qwen 3.5 和其他系列的模型
- 看重统一的计费和限流体验
选择 DashScope 当你:
- 想用官方第一方 API
- 需要访问最全的 Qwen 模型列表
- 想要 Qwen 专属的最优价格
- 已经在阿里云生态中
选择浏览器当你:
- 只想试试 Qwen 3.5,不想写代码
- 还在评估哪个模型大小适合自己
- 想先免费试用 Qwen 3.5,再决定是否接入 API
快速 FAQ
可以用 OpenAI Python SDK 调用 Qwen 3.5 API 吗?
可以。OpenRouter 和 DashScope 都支持 OpenAI 兼容格式。只需更改 base_url 和 api_key,并更新模型名称。
有免费额度吗?
DashScope 通常为新账号提供免费试用额度。OpenRouter 对较小模型的定价起步很低。请查看各供应商的当前优惠。
应该用哪个模型 ID?
对于大多数聊天和通用任务,Instruct 变体是正确选择。从 7B 模型开始以节省成本,如果质量需要提升再扩展到 32B 或更大。
Qwen 3.5 API 支持函数调用吗?
支持。Qwen 3.5 Instruct 模型通过标准 OpenAI 兼容格式支持函数调用(tool use)。OpenRouter 和 DashScope 都透传了这些能力。

