指南
Chat Completions API Reference

Chat Completions API

Endpoint: POST /v1/chat/completions
Base URL: https://api.floxai.io
鉴权: Authorization: Bearer <your-api-key>

文档有滞后性,最新文档见:https://platform.openai.com/docs/api-reference/chat/create (opens in a new tab)


请求参数

必需参数

参数类型说明
modelstring模型 ID,如 gpt-4oo3
messagesarray对话消息列表,至少 1 条。支持 developer / system / user / assistant / tool / function 角色

常用可选参数

参数类型默认值说明
temperaturenumber1采样温度,范围 0~2。值越高输出越随机,建议与 top_p 二选一调整
top_pnumber1核采样概率,范围 0~1,建议与 temperature 二选一调整
streambooleanfalse设为 true 时以 SSE 流式返回响应
max_completion_tokensinteger最大生成 token 数,含推理 token(推荐使用此参数替代 max_tokens
max_tokensinteger已废弃,建议使用 max_completion_tokens,与 o 系列模型不兼容
ninteger1每条消息生成的候选回复数,范围 1~128
stopstring / array最多 4 个停止序列,不支持最新 o3 / o4-mini
frequency_penaltynumber0频率惩罚,范围 -2~2,正值降低重复
presence_penaltynumber0存在惩罚,范围 -2~2,正值鼓励新话题
seedinteger指定后尽量返回确定性结果(Beta)
userstring终端用户唯一标识符
storebooleanfalse是否存储本次请求输出

工具调用

参数类型说明
toolsarray模型可调用的工具列表,最多 128 个,目前仅支持 function 类型
tool_choicestring / objectnone / auto / required 或指定函数 {"type": "function", "function": {"name": "..."}}
parallel_tool_callsboolean是否启用并行工具调用,默认 true

推理参数(o 系列模型)

参数类型默认值说明
reasoning_effortenummedium推理努力程度:low / medium / high

输出格式

参数类型说明
response_formatobject指定输出格式:{"type": "text"} / {"type": "json_object"} / {"type": "json_schema", "json_schema": {...}}
modalitiesarray输出模态:["text"]["text", "audio"]
audioobject音频输出参数,需配合 modalities: ["audio"] 使用
logprobsboolean是否返回 token 对数概率,默认 false
top_logprobsinteger每个位置返回的最可能 token 数,范围 0~20,需 logprobs: true

其他参数

参数类型默认值说明
service_tierenumauto延迟层:auto / default / flex
stream_optionsobject流式选项,仅 stream: true 时有效
web_search_optionsobject启用网络搜索,可配置 search_context_sizelow / medium / high
metadataobject最多 16 个键值对,键 ≤ 64 字符,值 ≤ 512 字符
predictionobject预测输出配置,适用于对已知内容做少量修改的场景

请求示例

curl --location --request POST 'https://api.uniapi.io/v1/chat/completions' \
  --header 'Authorization: Bearer <your-api-key>' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "model": "gpt-4.1",
    "messages": [
      {"role": "developer", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Hello!"}
    ]
  }'

响应示例

{
  "id": "chatcmpl-B9MBs8CjcvOU2jLn4n570S5qMJKcT",
  "object": "chat.completion",
  "created": 1741569952,
  "model": "gpt-4.1-2025-04-14",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I assist you today?",
        "refusal": null,
        "annotations": []
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 19,
    "completion_tokens": 10,
    "total_tokens": 29,
    "prompt_tokens_details": {
      "cached_tokens": 0,
      "audio_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0,
      "audio_tokens": 0,
      "accepted_prediction_tokens": 0,
      "rejected_prediction_tokens": 0
    }
  },
  "service_tier": "default"
}

响应字段说明

字段类型说明
idstring本次请求的唯一标识符
objectstring固定为 chat.completion
createdinteger创建时间(Unix 时间戳)
modelstring实际使用的模型
choicesarray生成结果列表
choices[].finish_reasonenum停止原因:stop / length / tool_calls / content_filter / function_call
choices[].messageobject模型生成的消息内容
usage.prompt_tokensinteger输入 token 数
usage.completion_tokensinteger输出 token 数
usage.total_tokensinteger总 token 数
system_fingerprintstring后端配置指纹,可配合 seed 监控后端变更
service_tierstring实际使用的延迟层