基础 URL 和认证
API 接受来自 https://api.qwenapipricing.com/v1. 每次调用都需要在 Authorization 头部,您在注册页面生成此密钥,它标识您的预付费积分账户。
- 使用标准的 HTTP 标头进行身份验证。
- 密钥在您的积分过期或撤销之前一直有效。
首次请求
发送聊天完成请求以测试连接。此简单调用验证您的密钥是否有效并返回基本响应。
您可以使用此示例验证您的密钥是否有效。
curl https://api.qwenapipricing.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "list the costs for the qwen2.5 models"}]
}'
Python 集成
使用官方 OpenAI Python SDK 与我们的服务交互。将客户端指向我们的 base URL 并提供您的密钥。
此配置适用于任何期望 OpenAI 端点的标准 Python 库。
from openai import OpenAI
client = OpenAI(base_url="https://api.qwenapipricing.com/v1", api_key="YOUR_KEY")
resp = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Summarise this thread without softening it."}],
)
print(resp.choices[0].message.content)
Node.js 集成
Node 开发人员可以使用 openai npm 包。配置客户端使用我们的 base URL 发送请求。
这种方法与现有的 OpenAI 代码库保持兼容。
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.qwenapipricing.com/v1", apiKey: process.env.API_KEY });
const resp = await client.chat.completions.create({
model: "uncensored",
messages: [{ role: "user", content: "Draft a villain monologue for my game." }],
});
console.log(resp.choices[0].message.content);
流式响应
通过将 stream: true 在您的请求中。API 通过服务器发送事件返回令牌。
每个事件的最后一个部分包含使用数据,允许您实时跟踪消耗量。
stream = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Tell the story in second person."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
速率限制与错误
每个密钥允许每分钟 300 次请求和 8 个并发连接。密钥无效时返回 401 错误,余额耗尽时返回 402 错误,达到速率限制时返回 429 错误。上下文窗口总共支持 100,000 个 token。