POST
/
v1
/
chat
/
completions
curl --request POST \
  --url https://vip.xmsmartlink.com/v1/chat/completions \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "gpt-4o-mini",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant."
    },
    {
      "role": "user",
      "content": "Hello!"
    }
  ]
}
'
{
  "id": "chatcmpl_xxx",
  "object": "chat.completion",
  "created": 1730000000,
  "model": "gpt-4o-mini",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "反向代理是在服务器端代替客户端向后端服务发起请求,并将结果返回给客户端的代理模式。"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 32,
    "completion_tokens": 28,
    "total_tokens": 60
  }
}

Authorizations

Authorization
string
header
required

使用 Authorization: Bearer <YOUR_API_KEY> 进行认证。

Headers

X-Trace-ID
string

请求跟踪 ID,建议每次请求唯一,便于排查问题。

Body

application/json
model
string
required

模型名称,与控制台可用模型一致。

Example:

"gpt-4o-mini"

messages
object[]
required

对话消息数组。每个元素支持 role/content,并支持 OpenAI 兼容的可选 name 字段、role=tool 时的 tool_call_id,以及 assistant 消息中的 tool_calls,用于函数/工具调用流程。

Minimum array length: 1
temperature
number

采样温度,范围通常为 0-2。

Required range: 0 <= x <= 2
Example:

1

top_p
number

Nucleus sampling 参数。

Required range: 0 <= x <= 1
Example:

1

max_tokens
integer

最大输出 token 数。

Required range: x >= 1
Example:

1024

max_completion_tokens
integer

最大补全 token 数,优先于 max_tokens。

Required range: x >= 1
Example:

1024

stream
boolean
default:false

是否以 SSE 流式返回。

stream_options
object

流式附加参数。

n
integer

返回候选条数。

Required range: x >= 1
Example:

1

stop

停止词。

presence_penalty
number

主题新颖度惩罚。

Required range: -2 <= x <= 2
Example:

0

frequency_penalty
number

频率惩罚。

Required range: -2 <= x <= 2
Example:

0

tools
object[]

工具调用(函数调用)定义。

tool_choice

工具选择策略。

Available options:
none,
auto,
required
parallel_tool_calls
boolean

是否允许并行工具调用。

response_format
object

响应格式,如 JSON mode 或 JSON schema。

user
string

终端用户标识。

Response

聊天补全响应。stream=true 时返回 text/event-stream,并以 data: [DONE] 结束。

id
string
required
Example:

"chatcmpl_xxx"

object
string
required
Example:

"chat.completion"

created
integer<int64>
required
Example:

1730000000

model
string
required
Example:

"gpt-4o-mini"

choices
object[]
required
usage
object