跳转至

ChatCompletions格式

根据对话历史创建模型响应。支持流式和非流式响应。

兼容 OpenAI Chat Completions API。

OpenAPI 摘要

ChatCompletions格式

项目
方法 POST
路径 /v1/chat/completions
Operation ID createchatcompletion
标签 聊天(Chat)/原生OpenAI格式

根据对话历史创建模型响应。支持流式和非流式响应。

兼容 OpenAI Chat Completions API。

认证

名称 类型 方案 说明
BearerAuth http bearer 使用 Bearer Token 认证。
格式: Authorization: Bearer sk-xxxxxx

请求体

必填: 是

application/json
字段 类型 必填 说明
model string 模型 ID
示例: gpt-4
messages array 对话消息列表
messages[].role string 消息角色
可选值: system, user, assistant, tool, developer
messages[].content oneOf(string, array) 消息内容
messages[].name string 发送者名称
messages[].tool_calls array
messages[].tool_calls[].id string
messages[].tool_calls[].type string 示例: function
messages[].tool_calls[].function object
messages[].tool_calls[].function.name string
messages[].tool_calls[].function.arguments string
messages[].tool_call_id string 工具调用 ID(用于 tool 角色消息)
messages[].reasoning_content string 推理内容
temperature number 采样温度
默认值: 1
最小值: 0
最大值: 2
top_p number 核采样参数
默认值: 1
最小值: 0
最大值: 1
n integer 生成数量
默认值: 1
最小值: 1
stream boolean 是否流式响应
默认值: False
stream_options object
stream_options.include_usage boolean
stop oneOf(string, array) 停止序列
max_tokens integer 最大生成 Token 数
max_completion_tokens integer 最大补全 Token 数
presence_penalty number 默认值: 0
最小值: -2
最大值: 2
frequency_penalty number 默认值: 0
最小值: -2
最大值: 2
logit_bias object
user string
tools array
tools[].type string 示例: function
tools[].function object
tools[].function.name string
tools[].function.description string
tools[].function.parameters object JSON Schema 格式的参数定义
tool_choice oneOf(string, object)
response_format object
response_format.type string 可选值: text, json_object, json_schema
response_format.json_schema object JSON Schema 定义
seed integer
reasoning_effort string 推理强度 (用于支持推理的模型)
可选值: low, medium, high
modalities array
audio object
audio.voice string
audio.format string

调用案例

curl -X POST "https://你的newapi服务器地址/v1/chat/completions" \
  -H "Authorization: Bearer $NEWAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "gpt-4o",
  "messages": [
    {
      "role": "user",
      "content": "你好,请介绍一下 New API。"
    }
  ]
}'

成功响应示例

{
  "id": "task_123456",
  "object": "chat.completion",
  "created": 1,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 1,
      "message": {
        "role": "assistant",
        "content": "你好,请介绍一下 New API。"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 1,
    "completion_tokens": 1,
    "total_tokens": 1,
    "prompt_tokens_details": {
      "cached_tokens": 1,
      "text_tokens": 1,
      "audio_tokens": 1,
      "image_tokens": 1
    },
    "completion_tokens_details": {
      "text_tokens": 1,
      "audio_tokens": 1,
      "reasoning_tokens": 1
    }
  }
}

响应

HTTP 200

成功创建响应

application/json
字段 类型 必填 说明
id string
object string 示例: chat.completion
created integer
model string
choices array
choices[].index integer
choices[].message object
choices[].message.role string 消息角色
可选值: system, user, assistant, tool, developer
choices[].message.content oneOf(string, array) 消息内容
choices[].message.name string 发送者名称
choices[].message.tool_calls array
choices[].message.tool_calls[].id string
choices[].message.tool_calls[].type string 示例: function
choices[].message.tool_calls[].function object
choices[].message.tool_calls[].function.name string
choices[].message.tool_calls[].function.arguments string
choices[].message.tool_call_id string 工具调用 ID(用于 tool 角色消息)
choices[].message.reasoning_content string 推理内容
choices[].finish_reason string 可选值: stop, length, tool_calls, content_filter
usage object
usage.prompt_tokens integer 提示词 Token 数
usage.completion_tokens integer 补全 Token 数
usage.total_tokens integer 总 Token 数
usage.prompt_tokens_details object
usage.prompt_tokens_details.cached_tokens integer
usage.prompt_tokens_details.text_tokens integer
usage.prompt_tokens_details.audio_tokens integer
usage.prompt_tokens_details.image_tokens integer
usage.completion_tokens_details object
usage.completion_tokens_details.text_tokens integer
usage.completion_tokens_details.audio_tokens integer
usage.completion_tokens_details.reasoning_tokens integer
system_fingerprint string
HTTP 400

请求参数错误

application/json
字段 类型 必填 说明
error object
error.message string 错误信息
error.type string 错误类型
error.param string | null 相关参数
error.code string | null 错误代码
HTTP 429

请求频率限制

application/json
字段 类型 必填 说明
error object
error.message string 错误信息
error.type string 错误类型
error.param string | null 相关参数
error.code string | null 错误代码

OpenAPI 源文件

openapi/generated/ai-model/聊天(Chat)/原生OpenAI格式/post-v1-chat-completions-createchatcompletion-383826473.json