跳过至正文
POST
/
api
/
聊天 (chat)
curl https://:11434/api/chat -d '{
  "model": "gemma3",
  "messages": [
    {
      "role": "user",
      "content": "why is the sky blue?"
    }
  ]
}'
{
  "model": "<string>",
  "created_at": "2023-11-07T05:31:56Z",
  "message": {
    "role": "assistant",
    "content": "<string>",
    "thinking": "<string>",
    "tool_calls": [
      {
        "function": {
          "name": "<string>",
          "description": "<string>",
          "arguments": {}
        }
      }
    ],
    "images": [
      "<string>"
    ]
  },
  "done": true,
  "done_reason": "<string>",
  "total_duration": 123,
  "load_duration": 123,
  "prompt_eval_count": 123,
  "prompt_eval_duration": 123,
  "eval_count": 123,
  "eval_duration": 123,
  "logprobs": [
    {
      "token": "<string>",
      "logprob": 123,
      "bytes": [
        123
      ],
      "top_logprobs": [
        {
          "token": "<string>",
          "logprob": 123,
          "bytes": [
            123
          ]
        }
      ]
    }
  ]
}

主体 (Body)

application/json
model
string
必填

模型名称

messages
object[]
必填

聊天历史记录,为消息对象数组(每个对象包含 role 和 content)

tools
object[]

模型在聊天过程中可能调用的可选函数工具列表

format

返回响应的格式。可以是 json 或 JSON 模式 (JSON schema)

可用选项:
json
options
object

控制文本生成的运行时选项

stream
boolean
默认:true
think

当为 true 时,除内容外还返回单独的思考过程输出。对于支持的模型,可以是布尔值 (true/false) 或字符串 ("high"、"medium"、"low")。

keep_alive

模型保持活跃时长(例如 5m0 表示立即卸载)

logprobs
boolean

是否返回输出 token 的对数概率 (log probabilities)

top_logprobs
integer

启用对数概率时,在每个 token 位置返回的最有可能的 token 数量

响应

聊天响应

model
string

用于生成此消息的模型名称

created_at
字符串<日期时间>

响应创建的时间戳 (ISO 8601)

message
object
done
boolean

指示聊天响应是否已结束

done_reason
string

响应结束的原因

total_duration
integer

生成总耗时(单位:纳秒)

load_duration
integer

加载模型耗时(单位:纳秒)

prompt_eval_count
integer

提示词 (prompt) 中的 token 数量

prompt_eval_duration
integer

评估提示词耗时(单位:纳秒)

eval_count
integer

响应中生成的 token 数量

eval_duration
integer

生成 token 耗时(单位:纳秒)

logprobs
object[]

启用对数概率时,生成的 token 的对数概率信息