Chat Completions API
OpenAI 格式的对话接口,也就是常说的 Chat Completions。已经用 OpenAI SDK 的项目,换个 base_url 就能直接调。
POST https://open.feiyutoken.com/v1/chat/completions
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model |
string | 是 | 模型名。沿用厂商官方命名,注意大小写;可用值见模型列表 |
messages |
array | 是 | 对话历史,每项含 role(system / user / assistant / tool)与 content |
stream |
boolean | 否 | true 时走 SSE 流式;默认 false |
stream_options |
object | 否 | 流式下加 {"include_usage": true} 才会在最后一个 chunk 带用量 |
max_tokens |
integer | 否 | 本次回复的长度上限。设小了回复会被截断,此时 finish_reason 为 length |
temperature |
number | 否 | 采样温度 |
top_p |
number | 否 | 核采样 |
stop |
string | array | 否 | 遇到这些字符串就停止生成 |
tools / tool_choice |
array / object | 否 | 工具调用(Function Calling),字段与 OpenAI 一致 |
response_format |
object | 否 | 结构化输出,如 {"type": "json_object"} |
其余 OpenAI 标准参数按原样透传。
请求示例
curl https://open.feiyutoken.com/v1/chat/completions \
-H "Authorization: Bearer <你的飞鱼Token API Key>" \
-H "Content-Type: application/json" \
-d '{
"model": "<模型名>",
"messages": [
{"role": "system", "content": "你是一个简洁的助手。"},
{"role": "user", "content": "用一句话解释什么是 API 网关。"}
],
"max_tokens": 256
}'
响应
{
"id": "chatcmpl-...",
"object": "chat.completion",
"created": 1770000000,
"model": "<模型名>",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "..." },
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 32,
"completion_tokens": 48,
"total_tokens": 80
}
}
finish_reason 的含义:stop 正常结束、content_filter 被内容策略拦截、length 达到 max_tokens 被截断、
tool_calls 请求了工具调用。
流式输出
请求里加 "stream": true,响应是 text/event-stream,每个 chunk 形如:
data: {"choices":[{"delta":{"content":"你"},"index":0}]}
data: {"choices":[{"delta":{"content":"好"},"index":0}]}
data: [DONE]
需要在流式下统计用量时,再加上 "stream_options": {"include_usage": true},
最后一个 chunk 会带上 usage(那一条的 choices 是空数组,判断时注意)。