对话补全 (Chat)
GPT 系列
OpenAI GPT 系列对话模型
适用模型
| 模型 | 上下文 | 说明 |
|---|---|---|
gpt-5.6 | 400K | GPT-5.6 |
gpt-5.4 | 400K | GPT-5.4 |
gpt-5.4-mini | 400K | GPT-5.4 Mini |
gpt-4o | 8K | GPT-4o |
实际可用模型以模型列表为准。
请求协议
完全遵循 OpenAI 官方 Chat Completions 协议(POST /v1/chat/completions),平台通用规则(校验链、预扣、流式 usage 注入)见接口说明。GPT 系列上游为 OpenAI 官方实现,以下参数均按 OpenAI 官方语义生效:
| 参数 | 类型 | 说明 |
|---|---|---|
model | string | 上表中的模型名 |
messages | array | 对话消息列表,content 支持字符串或多模态内容块数组(见下文"多模态输入") |
max_completion_tokens | int | 生成最大 Token 数(含推理 Token);max_tokens 已被 OpenAI 官方废弃,GPT-5 系列不再接受,请改用本参数。注意平台预扣估算只读 max_tokens,可两者同传 |
temperature | float | 采样温度,[0, 2],默认 1;GPT-5 系列推理模型仅支持默认值 |
top_p | float | 核采样,(0, 1];GPT-5 系列推理模型仅支持默认值 |
reasoning_effort | string | 推理力度:minimal / low / medium(默认) / high,仅 GPT-5 系列支持 |
verbosity | string | 输出详尽度:low / medium(默认) / high,仅 GPT-5 系列支持 |
n | int | 生成候选回复数量,默认 1 |
stream / stream_options | bool / object | SSE 流式,平台行为见接口说明 |
stop | string/array | 停止序列,最多 4 个;GPT-5 系列推理模型不支持 |
frequency_penalty | float | 频率惩罚,[-2, 2],默认 0 |
presence_penalty | float | 存在惩罚,[-2, 2],默认 0 |
logit_bias | map | token ID → 偏置值(-100 到 100) |
logprobs / top_logprobs | bool / int | 返回对数概率;top_logprobs 取值 0-20,需 logprobs: true |
seed | int | 尽力而为的确定性采样,配合响应中的 system_fingerprint 判断复现性 |
response_format | object | {"type":"text"} / {"type":"json_object"} / {"type":"json_schema","json_schema":{...}}(结构化输出,见下文) |
tools / tool_choice / parallel_tool_calls | — | 工具调用(见下文) |
prediction | object | 预测输出(Predicted Outputs),加速已知大部分内容的改写场景 |
user | string | 终端用户标识,用于上游滥用检测 |
store、metadata、service_tier 等账户级参数经中转链路不保证生效,不建议依赖。
多模态输入
GPT 系列支持图片输入(视觉理解),content 使用内容块数组,图片以 image_url 块传入(支持 https URL 或 data: base64):
{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "这张图里有什么?"},
{"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg", "detail": "auto"}}
]
}
]
}detail 可选 low / high / auto(默认),影响图片消耗的输入 token 数。
结构化输出
response_format 传 json_schema 可强约束输出为指定 JSON Schema:
{
"model": "gpt-5.4",
"messages": [{"role": "user", "content": "北京今天多云,25 度"}],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "weather",
"strict": true,
"schema": {
"type": "object",
"properties": {
"city": {"type": "string"},
"temperature": {"type": "number"},
"condition": {"type": "string"}
},
"required": ["city", "temperature", "condition"],
"additionalProperties": false
}
}
}
}工具调用
标准 OpenAI Function Calling:tools 声明工具,模型返回 finish_reason: "tool_calls" 和 choices[].message.tool_calls,执行后以 role: "tool" 消息回传结果:
{
"model": "gpt-5.4",
"messages": [{"role": "user", "content": "上海现在天气怎么样?"}],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "查询指定城市的当前天气",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}
],
"tool_choice": "auto"
}请求示例
curl https://api.looptoken.cc/v1/chat/completions \
-H "Authorization: Bearer $LOOPTOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4",
"messages": [{"role": "user", "content": "用一句话介绍量子计算"}],
"reasoning_effort": "low",
"max_completion_tokens": 1024
}'计费与错误
与接口说明一致:按 token 计费(GPT-5 系列的推理 Token 计入输出 token),价格见模型列表,错误码见错误码。