Chat Completions
POST https://api.moyuncourse.site/v1/chat/completions
OpenAI 兼容的对话补全接口,是 Nodaryx 最核心的调用方式。
请求字段
| 字段 | 类型 | 说明 |
|---|---|---|
| model | string | 模型 ID,如 gemini-flash、deepseek-v4-flash(见 模型总览) |
| messages | array | 对话消息数组,每条含 role(system/user/assistant)和 content |
| temperature | number | 采样温度,越高越随机(可选) |
| max_tokens | number | 生成的最大 token 数(可选;不传则用模型默认值) |
| stream | boolean | 是否流式返回,见 流式调用 |
响应字段
| 字段 | 说明 |
|---|---|
| id | 本次补全的唯一 ID |
| model | 实际使用的模型 |
| choices | 候选回复数组,正文在 choices[0].message.content |
| usage | token 用量:prompt_tokens / completion_tokens / total_tokens |
Node.js 示例
const res = await fetch("https://api.moyuncourse.site/v1/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.NODARYX_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "gemini-flash",
messages: [
{ role: "system", content: "你是一个简洁的助手。" },
{ role: "user", content: "你好" },
],
}),
});
const data = await res.json();
console.log(data.choices[0].message.content);
Python 示例
from openai import OpenAI
client = OpenAI(
base_url="https://api.moyuncourse.site/v1",
api_key="sk-nodaryx-xxxxxxxxxxxxxxxx",
)
resp = client.chat.completions.create(
model="gemini-flash",
messages=[{"role": "user", "content": "你好"}],
)
print(resp.choices[0].message.content)