Chat Completion
POSThttps://api.knox.chat/v1/chat/completions
向选定的模型发送聊天生成/补全请求。请求中必须包含一个 "messages" 数组。同时支持基础请求中的所有高级选项。
请求
此端点需要一个对象。
请求头
| Name | Type | Required | Description |
|---|---|---|---|
| Authorization | String | Yes | Bearer 认证,格式为 Bearer <token>,其中 token 是您的认证令牌。 |
请求体
| Name | Type | Required | Description |
|---|---|---|---|
| model | String | Yes | 要使用的模型 ID。如果未指定,将使用用户的默认设置。 |
| messages | List of Objects | Yes | 包含 "role" 和 "content" 属性的消息对象列表。 |
| models | List of Strings | No | 用于路由覆盖的备选模型列表。 |
| provider | Object | No | 供应商路由偏好设置。 |
| reasoning | Object | No | 模型推理/思考 token 的配置。 |
| usage | Object | No | 是否在响应中包含用量信息。 |
| transforms | List of Strings | No | 提示词转换列表(仅限 Knox Chat)。 |
| stream | Boolean | No | 启用结果流式传输。默认为 false。 |
| max_tokens | Integer | No | 最大 token 数量(范围:[1, context_length))。 |
| temperature | Double | No | 采样温度(范围:[0, 2])。 |
| seed | Integer | No | 用于确定性输出的种子值。 |
| top_p | Double | No | Top-p 采样值(范围:(0, 1])。 |
| top_k | Integer | No | Top-k 采样值(范围:[1, Infinity))。 |
| frequency_penalty | Double | No | 频率惩罚(范围:[-2, 2])。 |
| presence_penalty | Double | No | 存在惩罚(范围:[-2, 2])。 |
| repetition_penalty | Double | No | 重复惩罚(范围:(0, 2])。 |
| logit_bias | Map of String to Double | No | 从 token ID 到偏置值的映射。 |
| top_logprobs | Integer | No | 要返回的最高对数概率数量。 |
| min_p | Double | No | 最小概率阈值(范围:[0, 1])。 |
| top_a | Double | No | 备选 top 采样参数(范围:[0, 1])。 |
cURL 示例
curl -X POST https://api.knox.chat/v1/chat/completions \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-sonnet-4.6",
"messages": [
{
"role": "user",
"content": "Howdy Cowboy!"
}
]
}'
响应
成功响应 (200)
{
"id": "gen-12345",
"choices": [
{
"message": {
"role": "assistant",
"content": "Well howdy, partner! What can I rustle up for you today? Need help with a problem, a plan, a story, or just some trail talk?"
}
}
]
}
响应结构
| Name | Type | Description |
|---|---|---|
| id | string | 补全的唯一标识符 |
| choices | array | 补全选项数组 |
| choices[].message | object | 生成的消息 |
| choices[].message.role | string | 消息的角色(通常为 "assistant") |
| choices[].message.content | string | 生成的消息内容 |