---
title: "Generate a response"
method: POST
path: "/api/generate"
---

# Generate a response

`POST /api/generate`

Generates a response for the provided prompt

## Request body

- GenerateRequest
  - `model` string, required — Model name
  - `prompt` string — Text for the model to generate a response from
  - `suffix` string — Used for fill-in-the-middle models, text that appears after the user prompt and before the model response
  - `images` string[]
  - `format` union — Structured output format for the model to generate a response from. Supports either the string `"json"` or a JSON schema object.
    - string
    - object
  - `system` string — System prompt for the model to generate a response from
  - `stream` boolean — When true, returns a stream of partial responses
  - `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'
  - `raw` boolean — When true, returns the raw response from the model without any prompt templating
  - `keep_alive` union — Model keep-alive duration (for example `5m` or `0` to unload immediately)
    - string
    - number
  - `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
  - `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`

Generation responses

- GenerateResponse
  - `model` string — Model name
  - `created_at` string — ISO 8601 timestamp of response creation
  - `response` string — The model's generated text response
  - `thinking` string — The model's generated thinking output
  - `done` boolean — Indicates whether generation has finished
  - `done_reason` string — Reason the generation stopped
  - `total_duration` integer — Time spent generating the response in nanoseconds
  - `load_duration` integer — Time spent loading the model in nanoseconds
  - `prompt_eval_count` integer — Number of input tokens in the prompt
  - `prompt_eval_duration` integer — Time spent evaluating the prompt in nanoseconds
  - `eval_count` integer — Number of output 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

## Changes

- **2026-06-23** `d54e2ef5c24a` — 1 info
  - added the new `max` enum value to the request property `think/oneOf[subschema #2]/`
- **2025-11-14** `3e72f42e8aa6` — 3 info
  - added the new optional request property `logprobs`
  - added the new optional request property `top_logprobs`
  - added the optional property `logprobs` to the response with the `200` status
- **2025-11-11** `c99d500c9ea4` — 1 info
  - request property `think` list-of-types was widened by adding types `string` to media type `application/json`

[Change history](https://skmtc.dev/ollama/apis/ollama-api/changes/api/generate/post.md)

---

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