跳转到主要内容
POST
/
openai
/
v1
/
chat
/
completions
创建聊天对话请求
curl --request POST \
  --url https://api.jiekou.ai/openai/v1/chat/completions \
  --header 'Authorization: <authorization>' \
  --header 'Content-Type: <content-type>' \
  --data '{
  "model": "<string>",
  "messages": [
    {
      "content": {
        "type": "<string>",
        "text": "<string>",
        "image_url": "<string>",
        "video_url": "<string>"
      },
      "role": "<string>",
      "name": "<string>"
    }
  ],
  "max_tokens": 123,
  "stream": {},
  "stream_options": {
    "include_usage": true
  },
  "n": {},
  "seed": {},
  "frequency_penalty": {},
  "presence_penalty": {},
  "repetition_penalty": {},
  "stop": {},
  "temperature": {},
  "top_p": {},
  "top_k": {},
  "min_p": {},
  "logit_bias": {},
  "logprobs": {},
  "top_logprobs": {},
  "tools": {
    "type": "<string>",
    "function": {
      "name": "<string>",
      "description": {},
      "parameters": {},
      "strict": true
    }
  },
  "response_format": {
    "type": "<string>",
    "json_schema": {
      "name": "<string>",
      "description": {},
      "schema": {},
      "strict": true
    }
  },
  "separate_reasoning": {},
  "enable_thinking": {}
}'
{
  "choices": [
    {
      "finish_reason": "<string>",
      "index": 123,
      "message": {
        "role": "<string>",
        "content": {},
        "reasoning_content": {}
      }
    }
  ],
  "created": 123,
  "id": "<string>",
  "model": "<string>",
  "object": "<string>",
  "usage": {
    "completion_tokens": 123,
    "prompt_tokens": 123,
    "total_tokens": 123
  }
}
根据指定的聊天对话生成模型回复

请求头

Content-Type
string
required
枚举值: application/json
Authorization
string
required
Bearer 身份验证格式: Bearer {{API 秘钥}}。

请求体

model
string
required
要使用的模型名称。
messages
object[]
required
组成当前对话的消息列表。
max_tokens
integer
required
在完成中生成的最大 tokens 数量。如果您的提示(先前的消息)加上 max_tokens 的 tokens 数超过模型的上下文长度,则行为取决于 context_length_exceeded_behavior。默认情况下,max_tokens 将被降低以适应上下文窗口,而不是返回错误。
stream
boolean | null
default:false
是否流式返回部分进度。如果设置,tokens 将作为数据专用的服务器发送事件 (SSE) 发送,当它们可用时,流将以 data: [DONE] 消息终止。
stream_options
object | null
流响应的选项。仅在设置 stream 为 true 时设置此项。
n
integer | null
default:1
为每个提示生成的完成数量。注意:由于此参数会生成许多完成,因此可能会快速消耗您的 tokens 配额。请谨慎使用,并确保您对 max_tokens 和 stop 有合理的设置。必需范围:1 < x < 128
seed
integer | null
如果指定,我们的系统将尽力以确定性的方式进行采样,以便使用相同的 seed 和参数重复请求应返回相同的结果。
frequency_penalty
number | null
default:0
正值会根据新 tokens 在文本中现有的频率进行惩罚,降低模型逐字重复相同行的可能性。如果目标只是稍微减少重复样本,合理的值在 0.1 到 1 之间。如果目标是强烈抑制重复,则可以将系数增加到 2,但这可能会显著降低样本质量。负值可用于增加重复的可能性。另请参见 presence_penalty,用于以固定速率惩罚至少出现一次的 tokens。必需范围:-2 < x < 2
presence_penalty
number | null
default:0
正值会根据新 tokens 是否出现在文本中进行惩罚,增加模型谈论新主题的可能性。如果目标只是稍微减少重复样本,合理的值在 0.1 到 1 之间。如果目标是强烈抑制重复,则可以将系数增加到 2,但这可能会显著降低样本质量。负值可用于增加重复的可能性。另请参见 frequency_penalty,用于根据 tokens 出现的频率以递增速率惩罚 tokens。必需范围:-2 < x < 2
repetition_penalty
number | null
对重复的 tokens 应用惩罚以阻止或鼓励重复。值为 1.0 表示没有惩罚,允许自由重复。值高于 1.0 会惩罚重复,降低重复 tokens 的可能性。值在 0.0 和 1.0 之间会奖励重复,增加重复 tokens 的机会。为了获得良好的平衡,通常建议使用 1.2 的值。请注意,惩罚适用于生成的输出和仅解码器模型中的提示。必需范围:0 < x < 2
stop
string | null
API 将停止生成进一步 tokens 的最多 4 个序列。返回的文本将包含停止序列。
temperature
number | null
default:1
使用的采样温度,介于 0 和 2 之间。较高的值如 0.8 会使输出更随机,而较低的值如 0.2 会使其更集中和确定性。我们通常建议更改此项或 top_p,但不要同时更改。必需范围:0 < x < 2
top_p
number | null
一种替代采样温度的方法,称为核采样,其中模型考虑具有 top_p 概率质量的 tokens 结果。因此,0.1 表示仅考虑构成前 10% 概率质量的 tokens。我们通常建议更改此项或温度,但不要同时更改。必需范围:0 < x <= 1
top_k
integer | null
Top-k 采样是另一种采样方法,其中最可能的 k 个下一个 tokens 被过滤,并且概率质量仅在这 k 个下一个 tokens 之间重新分配。k 的值控制文本生成期间每个步骤下一个 tokens 的候选数量。必需范围:1 < x < 128
min_p
number | null
表示 tokens 被考虑的最小概率,相对于最可能 tokens 的概率。必需范围:0 <= x <= 1
logit_bias
map[string, integer] | null
修改指定 tokens 在完成中出现的可能性。接受一个 JSON 对象,将 tokens 映射到 -100 到 100 之间的关联偏差值。 数学上,偏差被添加到模型在采样之前生成的 logits 中。确切的效果会因模型而异。例如,通过设置 "logit_bias":{"1024": 6} 将增加 token ID 为 1024 的 tokens 的可能性。
logprobs
boolean | null
default:false
是否返回输出 tokens 的对数概率。如果为 true,则返回消息内容中每个输出 tokens 的对数概率。
top_logprobs
integer | null
一个介于 0 和 20 之间的整数,指定在每个 tokens 位置返回的最可能 tokens 的数量,每个 tokens 都有一个关联的对数概率。如果使用此参数,则必须将 logprobs 设置为 true。必需范围:0 <= x <= 20
tools
object[] | null
模型可以调用的工具列表。目前,仅支持函数作为工具。使用此项提供模型可以为其生成 JSON 输入的函数列表。函数调用指南中了解有关函数调用的更多信息。
response_format
object | null
允许强制模型生成特定的输出格式。设置为 { "type": "json_schema", "json_schema": {...} } 启用结构化输出,确保模型将匹配您提供的 JSON schema。设置为 { "type": "json_object" } 启用旧的 JSON 模式,确保模型生成的消息是有效的 JSON。对于支持它的模型,建议使用 json_schema
separate_reasoning
boolean | null
default:false
是否将推理与 “content” 分开到 “reasoning_content” 字段中。支持的模型:
  • deepseek/deepseek-r1-turbo
enable_thinking
boolean | null
default:true
控制在思考和非思考模式之间的切换。支持的模型:
  • zai-org/glm-4.5

响应

choices
object[]
required
聊天完成选项的列表。
created
integer
required
响应生成时的 Unix 时间(以秒为单位)。
id
string
required
响应的唯一标识符。
model
string
required
用于聊天完成的模型。
object
string
required
对象类型,始终为 chat.completion
usage
object
使用统计信息。对于流式响应,使用字段包含在返回的最后一个响应块中。
I