API 参考
Chat Completions
OpenAI 兼容的对话补全接口
POST https://netnexus.top/api/v1/chat/completions请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型 ID,见模型广场 |
messages | array | 是 | 对话消息列表,结构见下文 |
stream | boolean | 否 | 是否流式返回,默认 false |
stream_options | object | 否 | 流式选项,如 {"include_usage": true} 返回用量 |
temperature | number | 否 | 采样温度,越高越随机 |
top_p | number | 否 | 核采样概率阈值 |
max_tokens | integer | 否 | 最多生成的 token 数 |
stop | string / array | 否 | 遇到这些字符串时停止生成 |
tools | array | 否 | 可供调用的工具列表,见函数调用 |
tool_choice | string / object | 否 | 工具调用策略,如 auto、none |
response_format | object | 否 | 输出格式,见结构化输出 |
n | integer | 否 | 生成的候选回答数量 |
presence_penalty | number | 否 | 话题新鲜度惩罚 |
frequency_penalty | number | 否 | 重复度惩罚 |
user | string | 否 | 终端用户标识,便于排查问题 |
个别参数是否生效取决于具体模型,例如部分推理模型会忽略 temperature。
messages 结构
| 字段 | 类型 | 说明 |
|---|---|---|
role | string | system、user、assistant 或 tool |
content | string / array | 消息内容;多模态时为数组,见视觉理解 |
tool_calls | array | assistant 消息中模型发起的工具调用 |
tool_call_id | string | tool 消息对应的工具调用 ID |
请求示例
curl https://netnexus.top/api/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.7-plus",
"messages": [{ "role": "user", "content": "你好" }],
"temperature": 0.7,
"max_tokens": 1024
}'返回示例
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1790000000,
"model": "qwen3.7-plus",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "你好!有什么可以帮你?" },
"finish_reason": "stop"
}
],
"usage": { "prompt_tokens": 9, "completion_tokens": 10, "total_tokens": 19 }
}| 字段 | 说明 |
|---|---|
id | 本次请求的唯一 ID |
object | 固定为 chat.completion |
created | 创建时间(Unix 时间戳,秒) |
model | 实际使用的模型 |
choices[].message | 模型生成的消息 |
choices[].finish_reason | 结束原因:stop、length、tool_calls 等 |
usage | token 用量 |
流式返回
stream: true 时,按 SSE 格式逐块返回,每块的 object 为 chat.completion.chunk,增量内容在 choices[].delta 中:
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"你好"}}]}
data: [DONE]