API 接入
用个人 API Key 把 WonderAgent 的模型和会员额度接到任何支持 OpenAI 接口的平台或脚本。
WonderAgent 提供与 OpenAI 接口兼容的调用方式。在左侧栏「API」页生成一把个人 API Key,填到任何支持 OpenAI 接口的客户端、工作流平台或你自己写的脚本里,就能用 WonderAgent 的模型,用量计入你的会员额度,不需要再单独购买第三方额度。
三步接入
- 1
生成 API Key。 打开左侧栏「API」,点右上角「创建 API Key」,起一个能认出用途的名字。明文只在创建时显示一次,请立即复制保存。
- 2
填写接口地址。 在客户端的「API 地址 / Base URL」里填
https://wonderagent.hiwonder.com.cn/api/ai/v1,「API Key」里填刚才的 Key。 - 3
选择模型。 模型名与网页端相同,可以先调用
GET /models取一遍清单,再在客户端里选一个。
Key 丢了无法找回,到「API」页撤销后重新创建即可;撤销立即生效。每个账号最多同时保留 10 个 Key。
接口
| 项目 | 值 |
|---|---|
| Base URL | https://wonderagent.hiwonder.com.cn/api/ai/v1 |
| 认证 | 请求头 Authorization: Bearer <API Key> |
| 对话 | POST /chat/completions,OpenAI Chat Completions 格式,支持 stream: true 流式输出 |
| 模型清单 | GET /models,返回当前在架的模型 |
请求体与返回结构和 OpenAI 一致:model、messages、temperature、stream 等字段照常使用,返回里的 choices[0].message.content 是回复,usage 是本次的 token 数。
调用示例
curl:
curl https://wonderagent.hiwonder.com.cn/api/ai/v1/chat/completions \
-H "Authorization: Bearer $WONDERAGENT_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "<模型名>", "messages": [{"role": "user", "content": "你好"}]}'
Python(openai 库):
from openai import OpenAI
client = OpenAI(
base_url="https://wonderagent.hiwonder.com.cn/api/ai/v1",
api_key="你的 API Key",
)
reply = client.chat.completions.create(
model="<模型名>",
messages=[{"role": "user", "content": "你好"}],
)
print(reply.choices[0].message.content)
Node.js(openai 库):
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://wonderagent.hiwonder.com.cn/api/ai/v1",
apiKey: "你的 API Key",
});
const reply = await client.chat.completions.create({
model: "<模型名>",
messages: [{ role: "user", content: "你好" }],
});
console.log(reply.choices[0].message.content);
在图形化客户端或工作流平台里,一般是在「模型供应商」里选「OpenAI 兼容」,填上面的 Base URL 和 Key,模型名手动填写即可。
额度与限制
- 通过 Key 的调用和网页端对话记在同一个账号上,共用每日 / 每周额度,额度每日 0 点、每周一 0 点刷新(北京时间)。额度与档位见档位与额度。
- 模型与计价与网页端相同,见模型与计价。成本倍率高于 2.0× 的高级模型需开通会员;Free 档按每日对话次数计,开通会员后按 token 计量、不限次数。
- 同一账号同时在途的请求最多 4 个,超出返回
429。 - 通过 Key 的调用不注入网页端「设置 → 个性化」里的自定义指令,系统提示由你的客户端自己控制。
常见返回码
| 状态码 | error.type | 含义 |
|---|---|---|
| 401 | invalid_api_key | Key 无效或已撤销 |
| 403 | account_disabled | 账号已被禁用 |
| 400 | model_not_allowed | 模型名不在架,先用 GET /models 确认 |
| 403 | model_requires_membership | 高级模型需开通会员 |
| 429 | quota_exceeded / too_many_requests | 额度用尽,或并发超限 |
安全建议
- Key 等同于你的账号额度,不要写进公开仓库或前端页面;放在环境变量或客户端的密钥设置里。
- 一个用途一把 Key,便于出问题时只撤销那一把。
- 不再使用的 Key 及时撤销,「API」页里能看到每把 Key 的最近使用时间。