外观
接入指南
Token Factory 完全兼容 OpenAI 接口规范:任何支持自定义服务地址的 OpenAI 客户端或 SDK,改两个配置即可接入。
服务地址与鉴权
服务地址(Base URL):
txt
https://apicoo.com/api/v1鉴权方式:每个请求在 HTTP 头中携带 API Key(在控制台「API Keys」页创建):
http
Authorization: Bearer <你的 API Key>对话接口 POST /chat/completions
请求字段
| 字段 | 必填 | 说明 |
|---|---|---|
model | 必填 | 模型名,可用模型见定价页模型列表 |
messages | 必填 | 对话消息数组,每条含 role(system / user / assistant)与 content |
stream | 可选 | 是否流式返回,默认 false;为 true 时以 SSE 流式输出 |
| 其余参数 | 可选 | temperature、max_tokens 等 OpenAI 兼容参数原样透传上游模型 |
响应字段
choices[].message.content—— 模型回复正文;usage.prompt_tokens/usage.completion_tokens—— 本次调用的输入 / 输出 token 数,计费按此计量。
普通调用
Python / Node.js 示例使用官方 openai SDK(pip install openai / npm install openai):
bash
curl https://apicoo.com/api/v1/chat/completions \
-H "Authorization: Bearer sk-tf-你的Key" \
-H "Content-Type: application/json" \
-d '{"model": "glm-4.5-air", "messages": [{"role": "user", "content": "你好,介绍一下你自己"}]}'python
from openai import OpenAI
client = OpenAI(base_url="https://apicoo.com/api/v1", api_key="sk-tf-你的Key")
resp = client.chat.completions.create(model="glm-4.5-air", messages=[{"role": "user", "content": "你好,介绍一下你自己"}])
print(resp.choices[0].message.content)js
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://apicoo.com/api/v1", apiKey: "sk-tf-你的Key" });
const resp = await client.chat.completions.create({ model: "glm-4.5-air", messages: [{ role: "user", content: "你好,介绍一下你自己" }] });
console.log(resp.choices[0].message.content);流式调用
请求体加 "stream": true 后,响应以 SSE(Server-Sent Events)流式返回:每个增量是一行 data: 开头的 JSON 块,全部输出完毕以 data: [DONE] 结束。
bash
# 响应为 SSE 流:逐行返回 data: 块,以 data: [DONE] 结束
curl https://apicoo.com/api/v1/chat/completions \
-H "Authorization: Bearer sk-tf-你的Key" \
-H "Content-Type: application/json" \
-d '{"model": "glm-4.5-air", "messages": [{"role": "user", "content": "你好,介绍一下你自己"}], "stream": true}'python
from openai import OpenAI
client = OpenAI(base_url="https://apicoo.com/api/v1", api_key="sk-tf-你的Key")
resp = client.chat.completions.create(model="glm-4.5-air", messages=[{"role": "user", "content": "你好,介绍一下你自己"}], stream=True)
for chunk in resp:
print(chunk.choices[0].delta.content or "", end="", flush=True)js
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://apicoo.com/api/v1", apiKey: "sk-tf-你的Key" });
const resp = await client.chat.completions.create({ model: "glm-4.5-air", messages: [{ role: "user", content: "你好,介绍一下你自己" }], stream: true });
for await (const chunk of resp) process.stdout.write(chunk.choices[0]?.delta?.content ?? "");模型列表接口
GET /models(需鉴权)返回当前账号可用的模型列表,格式与 OpenAI 一致。
常见客户端
任意 OpenAI 兼容客户端均可接入,只需配置两要素:
- API 地址:填上方服务地址
https://apicoo.com/api/v1; - API Key:填你在控制台创建的 Key。
TIP
例如 Chatbox、Cherry Studio:在设置中选择「OpenAI 兼容 / 自定义提供方」,填入以上两项并选择模型(如 glm-4.5-air)即可对话。
逐工具配置教程见「工具接入」栏目。