---
title: "Generate a chat message"
method: POST
path: "/api/chat"
---

# Generate a chat message

`POST /api/chat`

Generate the next chat message in a conversation between a user and an assistant.

## Request body

- ChatRequest
  - `model` string, required — Model name
  - `messages` ChatMessage[], required — Chat history as an array of message objects (each with a role and content)
    - `role` 'system' | 'user' | 'assistant' | 'tool', required — Author of the message.
    - `content` string, required — Message text content
    - `images` string[] — Optional list of inline images for multimodal models
    - `tool_calls` ToolCall[] — Tool call requests produced by the model
      - `function` object
        - `name` string, required — Name of the function to call
        - `description` string — What the function does
        - `arguments` object — JSON object of arguments to pass to the function
  - `tools` ToolDefinition[] — Optional list of function tools the model may call during the chat
    - `type` 'function', required — Type of tool (always `function`)
    - `function` object, required
      - `name` string, required — Function name exposed to the model
      - `description` string — Human-readable description of the function
      - `parameters` object, required — JSON Schema for the function parameters
  - `format` union — Format to return a response in. Can be `json` or a JSON schema
    - 'json'
    - object
  - `options` ModelOptions — Runtime options that control text generation
    - `seed` integer — Random seed used for reproducible outputs
    - `temperature` number, float — Controls randomness in generation (higher = more random)
    - `top_k` integer — Limits next token selection to the K most likely
    - `top_p` number, float — Cumulative probability threshold for nucleus sampling
    - `min_p` number, float — Minimum probability threshold for token selection
    - `stop` union — Stop sequences that will halt generation
      - string
      - string[]
    - `num_ctx` integer — Context length size (number of tokens)
    - `num_predict` integer — Maximum number of tokens to generate
  - `stream` boolean
  - `think` union — When true, returns separate thinking output in addition to content. Can be a boolean (true/false) or a string ("high", "medium", "low", "max") for supported models, with "max" requesting the highest thinking level.
    - boolean
    - 'high' | 'medium' | 'low' | 'max'
  - `keep_alive` union — Model keep-alive duration (for example `5m` or `0` to unload immediately)
    - string
    - number
  - `logprobs` boolean — Whether to return log probabilities of the output tokens
  - `top_logprobs` integer — Number of most likely tokens to return at each token position when logprobs are enabled

## Response `200`

Chat response

- ChatResponse
  - `model` string — Model name used to generate this message
  - `created_at` string, date-time — Timestamp of response creation (ISO 8601)
  - `message` object
    - `role` 'assistant' — Always `assistant` for model responses
    - `content` string — Assistant message text
    - `thinking` string — Optional deliberate thinking trace when `think` is enabled
    - `tool_calls` ToolCall[] — Tool calls requested by the assistant
      - `function` object
        - `name` string, required — Name of the function to call
        - `description` string — What the function does
        - `arguments` object — JSON object of arguments to pass to the function
    - `images` string[] — Optional base64-encoded images in the response
  - `done` boolean — Indicates whether the chat response has finished
  - `done_reason` string — Reason the response finished
  - `total_duration` integer — Total time spent generating in nanoseconds
  - `load_duration` integer — Time spent loading the model in nanoseconds
  - `prompt_eval_count` integer — Number of tokens in the prompt
  - `prompt_eval_duration` integer — Time spent evaluating the prompt in nanoseconds
  - `eval_count` integer — Number of tokens generated in the response
  - `eval_duration` integer — Time spent generating tokens in nanoseconds
  - `logprobs` Logprob[] — Log probability information for the generated tokens when logprobs are enabled
    - `token` string — The text representation of the token
    - `logprob` number — The log probability of this token
    - `bytes` integer[] — The raw byte representation of the token
    - `top_logprobs` TokenLogprob[] — Most likely tokens and their log probabilities at this position
      - `token` string — The text representation of the token
      - `logprob` number — The log probability of this token
      - `bytes` integer[] — The raw byte representation of the token

---

[API](https://skmtc.net/ollama/apis/ollama-api.md) · [All operations](https://skmtc.net/ollama/apis/ollama-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/ollama/ollama-api/versions/9c660bb9a714/schema)
