curl https://api.nodylink.com/v1/chat/completions \
-H "Authorization: Bearer sk-你的密钥" \
-H "Content-Type: application/json" \
-N \
-d '{
"model": "gpt-6",
"messages": [
{"role": "system", "content": "你是一个专业的 AI 助手。"},
{"role": "user", "content": "介绍一下人工智能的发展历史。"}
],
"stream": true,
"stream_options": {"include_usage": true}
}'
from openai import OpenAI
client = OpenAI(base_url="https://api.nodylink.com/v1", api_key="sk-你的密钥")
stream = client.chat.completions.create(
model="gpt-6",
messages=[
{"role": "system", "content": "你是一个专业的 AI 助手。"},
{"role": "user", "content": "介绍一下人工智能的发展历史。"},
],
stream=True,
stream_options={"include_usage": True},
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
if chunk.usage:
print("\n用量:", chunk.usage)
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.nodylink.com/v1",
apiKey: "sk-你的密钥",
});
const stream = await client.chat.completions.create({
model: "gpt-6",
messages: [
{ role: "system", content: "你是一个专业的 AI 助手。" },
{ role: "user", content: "介绍一下人工智能的发展历史。" },
],
stream: true,
stream_options: { include_usage: true },
});
for await (const chunk of stream) {
const delta = chunk.choices[0]?.delta?.content;
if (delta) process.stdout.write(delta);
if (chunk.usage) console.log("\n用量:", chunk.usage);
}
data: {"id":"chatcmpl-9f3b2c1a","object":"chat.completion.chunk","created":1792000000,"model":"gpt-6","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"chatcmpl-9f3b2c1a","object":"chat.completion.chunk","created":1792000000,"model":"gpt-6","choices":[{"index":0,"delta":{"content":"人工智能"},"finish_reason":null}]}
data: {"id":"chatcmpl-9f3b2c1a","object":"chat.completion.chunk","created":1792000000,"model":"gpt-6","choices":[{"index":0,"delta":{"content":"的发展可以追溯到 1950 年代……"},"finish_reason":null}]}
data: {"id":"chatcmpl-9f3b2c1a","object":"chat.completion.chunk","created":1792000000,"model":"gpt-6","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"id":"chatcmpl-9f3b2c1a","object":"chat.completion.chunk","created":1792000000,"model":"gpt-6","choices":[],"usage":{"prompt_tokens":28,"completion_tokens":412,"total_tokens":440}}
data: [DONE]
{
"error": {
"message": "未指定模型名称,模型名称不能为空 (request id: 2026101412000012345678)",
"type": "new_api_error",
"param": "",
"code": ""
}
}
{
"error": {
"message": "用户额度不足, 剩余额度: ¥0.012 (request id: 2026101412000012345678)",
"type": "new_api_error",
"param": "",
"code": "insufficient_user_quota"
}
}
文本对话系列
对话补全(流式)
兼容 OpenAI Chat Completions 协议,通过 SSE 逐段返回生成内容。
POST
/
v1
/
chat
/
completions
curl https://api.nodylink.com/v1/chat/completions \
-H "Authorization: Bearer sk-你的密钥" \
-H "Content-Type: application/json" \
-N \
-d '{
"model": "gpt-6",
"messages": [
{"role": "system", "content": "你是一个专业的 AI 助手。"},
{"role": "user", "content": "介绍一下人工智能的发展历史。"}
],
"stream": true,
"stream_options": {"include_usage": true}
}'
from openai import OpenAI
client = OpenAI(base_url="https://api.nodylink.com/v1", api_key="sk-你的密钥")
stream = client.chat.completions.create(
model="gpt-6",
messages=[
{"role": "system", "content": "你是一个专业的 AI 助手。"},
{"role": "user", "content": "介绍一下人工智能的发展历史。"},
],
stream=True,
stream_options={"include_usage": True},
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
if chunk.usage:
print("\n用量:", chunk.usage)
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.nodylink.com/v1",
apiKey: "sk-你的密钥",
});
const stream = await client.chat.completions.create({
model: "gpt-6",
messages: [
{ role: "system", content: "你是一个专业的 AI 助手。" },
{ role: "user", content: "介绍一下人工智能的发展历史。" },
],
stream: true,
stream_options: { include_usage: true },
});
for await (const chunk of stream) {
const delta = chunk.choices[0]?.delta?.content;
if (delta) process.stdout.write(delta);
if (chunk.usage) console.log("\n用量:", chunk.usage);
}
data: {"id":"chatcmpl-9f3b2c1a","object":"chat.completion.chunk","created":1792000000,"model":"gpt-6","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"chatcmpl-9f3b2c1a","object":"chat.completion.chunk","created":1792000000,"model":"gpt-6","choices":[{"index":0,"delta":{"content":"人工智能"},"finish_reason":null}]}
data: {"id":"chatcmpl-9f3b2c1a","object":"chat.completion.chunk","created":1792000000,"model":"gpt-6","choices":[{"index":0,"delta":{"content":"的发展可以追溯到 1950 年代……"},"finish_reason":null}]}
data: {"id":"chatcmpl-9f3b2c1a","object":"chat.completion.chunk","created":1792000000,"model":"gpt-6","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"id":"chatcmpl-9f3b2c1a","object":"chat.completion.chunk","created":1792000000,"model":"gpt-6","choices":[],"usage":{"prompt_tokens":28,"completion_tokens":412,"total_tokens":440}}
data: [DONE]
{
"error": {
"message": "未指定模型名称,模型名称不能为空 (request id: 2026101412000012345678)",
"type": "new_api_error",
"param": "",
"code": ""
}
}
{
"error": {
"message": "用户额度不足, 剩余额度: ¥0.012 (request id: 2026101412000012345678)",
"type": "new_api_error",
"param": "",
"code": "insufficient_user_quota"
}
}
- 统一的对话接口,支持平台上所有文本模型,包括 GPT、Claude、Gemini、DeepSeek 等,通过
model参数切换。 - 与 OpenAI Chat Completions 协议兼容,可以直接使用 OpenAI 官方 SDK。
- 设置
"stream": true后以 Server-Sent Events 流式返回;不设置时默认非流式,见 对话补全(非流式)。
curl https://api.nodylink.com/v1/chat/completions \
-H "Authorization: Bearer sk-你的密钥" \
-H "Content-Type: application/json" \
-N \
-d '{
"model": "gpt-6",
"messages": [
{"role": "system", "content": "你是一个专业的 AI 助手。"},
{"role": "user", "content": "介绍一下人工智能的发展历史。"}
],
"stream": true,
"stream_options": {"include_usage": true}
}'
from openai import OpenAI
client = OpenAI(base_url="https://api.nodylink.com/v1", api_key="sk-你的密钥")
stream = client.chat.completions.create(
model="gpt-6",
messages=[
{"role": "system", "content": "你是一个专业的 AI 助手。"},
{"role": "user", "content": "介绍一下人工智能的发展历史。"},
],
stream=True,
stream_options={"include_usage": True},
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
if chunk.usage:
print("\n用量:", chunk.usage)
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.nodylink.com/v1",
apiKey: "sk-你的密钥",
});
const stream = await client.chat.completions.create({
model: "gpt-6",
messages: [
{ role: "system", content: "你是一个专业的 AI 助手。" },
{ role: "user", content: "介绍一下人工智能的发展历史。" },
],
stream: true,
stream_options: { include_usage: true },
});
for await (const chunk of stream) {
const delta = chunk.choices[0]?.delta?.content;
if (delta) process.stdout.write(delta);
if (chunk.usage) console.log("\n用量:", chunk.usage);
}
data: {"id":"chatcmpl-9f3b2c1a","object":"chat.completion.chunk","created":1792000000,"model":"gpt-6","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"chatcmpl-9f3b2c1a","object":"chat.completion.chunk","created":1792000000,"model":"gpt-6","choices":[{"index":0,"delta":{"content":"人工智能"},"finish_reason":null}]}
data: {"id":"chatcmpl-9f3b2c1a","object":"chat.completion.chunk","created":1792000000,"model":"gpt-6","choices":[{"index":0,"delta":{"content":"的发展可以追溯到 1950 年代……"},"finish_reason":null}]}
data: {"id":"chatcmpl-9f3b2c1a","object":"chat.completion.chunk","created":1792000000,"model":"gpt-6","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"id":"chatcmpl-9f3b2c1a","object":"chat.completion.chunk","created":1792000000,"model":"gpt-6","choices":[],"usage":{"prompt_tokens":28,"completion_tokens":412,"total_tokens":440}}
data: [DONE]
{
"error": {
"message": "未指定模型名称,模型名称不能为空 (request id: 2026101412000012345678)",
"type": "new_api_error",
"param": "",
"code": ""
}
}
{
"error": {
"message": "用户额度不足, 剩余额度: ¥0.012 (request id: 2026101412000012345678)",
"type": "new_api_error",
"param": "",
"code": "insufficient_user_quota"
}
}
鉴权
请求参数
array
必填
对话消息列表,按时间顺序排列。
显示 消息对象
显示 消息对象
string
必填
消息角色:
system、developer、user、assistant 或 tool。string | array
必填
消息内容。纯文本直接传字符串;包含图片等多模态内容时传数组,例如:
[
{"type": "text", "text": "图里有什么?"},
{"type": "image_url", "image_url": {"url": "https://example.com/cat.png"}}
]
string
参与者名称,用于区分同一角色下的不同发言者。
array
assistant 消息中模型发起的工具调用,多轮工具调用时原样回传。string
tool 消息对应的工具调用 ID。boolean
默认值:"false"
是否流式返回。设为
true 时以 text/event-stream 返回,每个事件以 data: 开头,最后以 data: [DONE] 结束。number
采样温度,取值 0 到 2。值越高输出越随机,值越低越确定。不建议与
top_p 同时调整。number
核采样阈值,取值 0 到 1。例如 0.1 表示只从累计概率前 10% 的 token 中采样。
integer
生成内容的最大 token 数。推理模型建议改用
max_completion_tokens。integer
生成内容(含推理 token)的最大 token 数。
string
推理强度,适用于支持推理的模型。常用取值:
low、medium、high。string | string[]
停止序列,最多 4 个。生成内容遇到其中任意一个时停止。
integer
默认值:"1"
为每条输入生成的候选回复数量。部分模型只支持 1。
number
存在惩罚,取值 -2.0 到 2.0。正值鼓励模型谈论新话题。
number
频率惩罚,取值 -2.0 到 2.0。正值降低逐字重复的概率。
integer
随机种子。相同种子和参数下,模型会尽量返回相同结果。
array
string | object
工具调用策略:
none 不调用、auto 由模型决定、required 必须调用,或通过 {"type": "function", "function": {"name": "..."}} 指定函数。boolean
是否允许模型在一次回复中并行发起多个工具调用。
object
输出格式。
{"type": "json_object"} 输出合法 JSON;{"type": "json_schema", "json_schema": {...}} 按给定 Schema 输出。string
终端用户标识,用于上游的滥用监控。
流式响应
每个 SSE 事件的data 是一个 chat.completion.chunk 对象。
string
本次补全的唯一 ID,同一次请求的所有数据块相同。
string
固定为
chat.completion.chunk。integer
创建时间,Unix 时间戳(秒)。
string
实际使用的模型。
array
鉴权失败、余额不足、参数错误等问题在流开始前就会被发现,此时返回普通的 JSON 错误体和对应的 HTTP 状态码,而不是 SSE 流。

