Skip to content

对话补全 · 高级参数 ​

本文档供调参、联调、对字段使用。端点速览与可复制示例见 创建对话补全。


请求体字段 ​

字段类型必填说明
modelstring是模型 ID,见 获取模型 或 模型广场
messagesarray是见下节 messages[]
streamboolean否默认 false
stream_optionsobject否include_usage、chunk_include_usage(仅 stream=true)
temperaturenumber否常用 0~2
top_pnumber否常用 0~1
max_tokensinteger否与 max_completion_tokens 互斥
max_completion_tokensinteger否1~65536
thinking_enabledboolean否深度思考;按模型能力
reasoning_effortstring否none / minimal / low / medium / high 等
stopstring | string[]否停止词,最多 4 个
response_formatobject | string否text / json_object / json_schema
frequency_penaltynumber否按模型能力
presence_penaltynumber否按模型能力
logprobsboolean否按模型能力
top_logprobsinteger否需 logprobs=true
toolsarray否type: function + function.name
parallel_tool_callsboolean否默认 true
tool_choicestring | object否none / auto / required 或指定 function
modalitiesarray否生文建议省略或 ["text"]

messages[] ​

字段类型必填说明
rolestring否system / user / assistant / tool
contentstring | array是string 或 Part 数组
tool_callsarray否仅 role=assistant
tool_call_idstring否仅 role=tool 时必传

Part(content 为数组) ​

type说明
text{ "type": "text", "text": "..." }
image_urlURL 或 data:image/...;base64,...;详见 图片输入
input_audioinput_audio.data(Base64)+ format:mp3 / wav
filefile_url(≤70MB,可传视频);可选 file_name;详见 视频输入

INFO

Part 用于生文看图/听音/读文件。生图参考图用 image_config.reference_images,见 图像生成 · 高级参数。


追踪与结算请求头 ​

请求头说明
X-Request-Id追踪 ID;最长 128 字符
X-Idempotency-Key结算幂等;重试同一笔业务须不变
X-Conversation-Id会话分组;多轮 Agent / Prompt Cache 建议固定传同一值

TIP

不传 X-Idempotency-Key 时每次 HTTP 调用独立计费。网络超时重放应固定结算键。


Prompt Cache ​

适用于支持 Prompt Cache 的生文模型(可用模型见 获取模型 或 模型广场)。网关自动维护会话上下文,客户端无需在 body 中传缓存控制字段。

提升命中率 ​

同一 Agent 或多轮 Chat 内,请固定 X-Conversation-Id(未传时可用 X-Session-Id)。频繁更换会话 ID 会降低缓存命中。

响应 usage ​

字段说明
usage.prompt_tokens_details.cached_tokens从缓存读取的 input token 数(命中时 > 0)
usage.prompt_tokens_details.cache_write_tokens首次写入缓存的 token 数(若上游返回)

流式请求在最后一个 SSE chunk 中附带上述字段(需 stream_options.include_usage),见 流式输出(SSE)。

示例(非流式):

json
{
  "usage": {
    "prompt_tokens": 1500,
    "completion_tokens": 120,
    "total_tokens": 1620,
    "prompt_tokens_details": {
      "cached_tokens": 1200
    }
  }
}

计费 ​

模型已配置 cached input 单价时,input 费用大致为:

  • 未缓存 prompt × input 单价
  • 缓存命中 prompt × cached input 单价(通常低于 input)
  • completion × output 单价

若模型尚未配置 cached input 价目,缓存命中的 token 暂按 input 单价计费。具体单价以控制台与模型说明为准。


思考模式(按模型) ​

模型示例约束摘要
gpt-5.1 / gpt-5.2 / gpt-4o不支持 thinking_enabled / reasoning_effort
gemini-3-pro-preview不允许 thinking_enabled=false;reasoning_effort 为 low / medium / high
gemini-3-flash-preview默认开启思考;reasoning_effort 含 minimal 等

以 获取模型、模型广场 与实际上线能力为准。


完整 JSON 示例 ​

json
{
  "model": "gpt-5.5",
  "messages": [
    { "role": "system", "content": "你是一个专业助手。" },
    { "role": "user", "content": "你好" }
  ],
  "stream": false,
  "temperature": 0.7,
  "max_tokens": 1024,
  "thinking_enabled": true,
  "reasoning_effort": "medium",
  "tools": [],
  "tool_choice": "auto"
}

相关 ​

© Trinity AI