InhabbitInhabbit Docs
AI 模型接口聊天(Chat)

原生 OpenAI 格式

OpenAI 原生格式,支持 Chat Completions 与 Responses。

Chat Completions 格式

基于对话历史创建模型响应,支持流式和非流式响应。

端点

POST https://llm.inhabbit.com/v1/chat/completions

请求体(application/json)

参数类型必需默认值说明
modelstring模型 ID
messagesarray<object>对话消息列表
temperaturenumber1采样温度,范围 0-2
top_pnumber1核采样参数,范围 0-1
ninteger1生成的补全数量
streambooleanfalse是否启用流式响应
stream_optionsobject流式选项
stopstring | array<string>停止序列
max_tokensinteger最大生成 Token 数
max_completion_tokensinteger最大补全 Token 数
presence_penaltynumber0存在惩罚,范围 -2 到 2
frequency_penaltynumber0频率惩罚,范围 -2 到 2
logit_biasobjectLogit 偏置映射
userstring终端用户标识
toolsarray<object>工具定义
tool_choicestring | object工具选择策略
response_formatobject响应格式规范
seedinteger随机种子
reasoning_effortstring推理强度:lowmediumhigh
modalitiesarray<string>支持的模态
audioobject音频配置

响应(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)

参数类型必需说明
modelstring模型标识
inputstring | array<object>输入内容,可以是字符串或消息数组
instructionsstring模型的系统指令
max_output_tokensinteger最大输出 Token 数
temperaturenumber采样温度,范围 0-2
top_pnumber核采样参数
streamboolean是否启用流式响应
toolsarray<object>可用的函数调用工具
tool_choicestring | object工具选择策略
reasoningobject推理配置
previous_response_idstring引用的上一次响应 ID
truncationstring截断选项:autodisabled

响应(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": "请解释量子纠缠的概念。"
  }'

本页目录