查询可用模型
模型清单会随账户权限和平台供给变化。发起调用前,请通过 GET /v1/models 查询当前可用的模型 ID, 并将返回值中的 ID 用于请求。
查询可用模型
const response = await fetch("https://api.mindon.fun/v1/models", {
headers: {
Authorization: "Bearer YOUR_API_KEY",
},
});
const models = await response.json();创建 Chat Completion
使用 POST /v1/chat/completions 发送消息。将 your-model-id 替换为模型查询接口返回的 ID。
cURL
curl https://api.mindon.fun/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "your-model-id",
"messages": [
{"role": "system", "content": "你是一个有帮助的助手。"},
{"role": "user", "content": "用一句话介绍 MindOn。"}
]
}'流式响应
设置 stream: true 后,接口会以 Server-Sent Events 持续返回增量内容。以下 TypeScript 示例会逐段输出回答。
TypeScript
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.MINDON_API_KEY,
baseURL: "https://api.mindon.fun/v1",
});
const stream = await client.chat.completions.create({
model: "your-model-id",
messages: [{ role: "user", content: "写一首四行小诗。" }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}流结束后再保存完整结果;不要假定每个数据块都包含文本内容。