AI 模型接口聊天(Chat)
原生 OpenAI 格式
OpenAI 原生格式,支持 Chat Completions 与 Responses。
Chat Completions 格式
基于对话历史创建模型响应,支持流式和非流式响应。
端点
POST https://llm.inhabbit.com/v1/chat/completions请求体(application/json)
| 参数 | 类型 | 必需 | 默认值 | 说明 |
|---|---|---|---|---|
| model | string | 是 | — | 模型 ID |
| messages | array<object> | 是 | — | 对话消息列表 |
| temperature | number | 否 | 1 | 采样温度,范围 0-2 |
| top_p | number | 否 | 1 | 核采样参数,范围 0-1 |
| n | integer | 否 | 1 | 生成的补全数量 |
| stream | boolean | 否 | false | 是否启用流式响应 |
| stream_options | object | 否 | — | 流式选项 |
| stop | string | array<string> | 否 | — | 停止序列 |
| max_tokens | integer | 否 | — | 最大生成 Token 数 |
| max_completion_tokens | integer | 否 | — | 最大补全 Token 数 |
| presence_penalty | number | 否 | 0 | 存在惩罚,范围 -2 到 2 |
| frequency_penalty | number | 否 | 0 | 频率惩罚,范围 -2 到 2 |
| logit_bias | object | 否 | — | Logit 偏置映射 |
| user | string | 否 | — | 终端用户标识 |
| tools | array<object> | 否 | — | 工具定义 |
| tool_choice | string | object | 否 | — | 工具选择策略 |
| response_format | object | 否 | — | 响应格式规范 |
| seed | integer | 否 | — | 随机种子 |
| reasoning_effort | string | 否 | — | 推理强度:low、medium、high |
| modalities | array<string> | 否 | — | 支持的模态 |
| audio | object | 否 | — | 音频配置 |
响应(200 OK)
{
"id": "string",
"object": "chat.completion",
"created": 0,
"model": "string",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "string",
"name": "string",
"tool_calls": [
{
"id": "string",
"type": "function",
"function": {
"name": "string",
"arguments": "string"
}
}
],
"tool_call_id": "string",
"reasoning_content": "string"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0,
"prompt_tokens_details": {
"cached_tokens": 0,
"text_tokens": 0,
"audio_tokens": 0,
"image_tokens": 0
},
"completion_tokens_details": {
"text_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 0
}
},
"system_fingerprint": "string"
}错误响应
400 Bad Request / 429 Too Many Requests:
{
"error": {
"message": "string",
"type": "string",
"param": "string",
"code": "string"
}
}示例
curl -X POST "https://llm.inhabbit.com/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-xxxxxx" \
-d '{
"model": "gpt-4o",
"messages": [
{
"role": "system",
"content": "你是一个有帮助的助手。"
},
{
"role": "user",
"content": "你好!"
}
]
}'Responses 格式
支持多轮对话、工具调用和推理能力的响应接口(OpenAI Responses API 格式)。
端点
POST https://llm.inhabbit.com/v1/responses请求体(application/json)
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
| model | string | 是 | 模型标识 |
| input | string | array<object> | 否 | 输入内容,可以是字符串或消息数组 |
| instructions | string | 否 | 模型的系统指令 |
| max_output_tokens | integer | 否 | 最大输出 Token 数 |
| temperature | number | 否 | 采样温度,范围 0-2 |
| top_p | number | 否 | 核采样参数 |
| stream | boolean | 否 | 是否启用流式响应 |
| tools | array<object> | 否 | 可用的函数调用工具 |
| tool_choice | string | object | 否 | 工具选择策略 |
| reasoning | object | 否 | 推理配置 |
| previous_response_id | string | 否 | 引用的上一次响应 ID |
| truncation | string | 否 | 截断选项:auto 或 disabled |
响应(200 OK)
{
"id": "string",
"object": "response",
"created_at": 0,
"status": "completed",
"model": "string",
"output": [
{
"type": "string",
"id": "string",
"status": "string",
"role": "string",
"content": [
{
"type": "string",
"text": "string"
}
]
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0,
"prompt_tokens_details": {
"cached_tokens": 0,
"text_tokens": 0,
"audio_tokens": 0,
"image_tokens": 0
},
"completion_tokens_details": {
"text_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 0
}
}
}示例
curl -X POST "https://llm.inhabbit.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-xxxxxx" \
-d '{
"model": "gpt-4o",
"input": "请解释量子纠缠的概念。"
}'