Thinking-capable Ollama models can return a reasoning trace separately from the final answer. That separation matters for user interfaces, audits, and logs because the trace is not the same field as the answer.

The think request field can be a boolean for many models or a level for models such as gpt-oss. The chat endpoint returns reasoning under message.thinking while final text stays under message.content.

Keep token limits high enough for the model to produce both reasoning and answer. A short num_predict or compatibility max_tokens value can stop a thinking model before final content appears.

Steps to use thinking with the Ollama API:

  1. Send a chat request with thinking enabled or set to a model-specific level.
    $ curl -s http://localhost:11434/api/chat -d '{
      "model":"gpt-oss:20b",
      "messages":[{"role":"user","content":"Reply with OK."}],
      "think":"low",
      "stream":false,
      "options":{"num_predict":24}
    }'
    {"message":{"content":"OK","thinking":"User wants \"OK\"."},"done":true}
  2. Verify the final answer is read from message.content.
    $ python3 - <<'PY'
    payload = {"message": {"content": "OK", "thinking": "User wants OK."}}
    print(payload["message"]["content"])
    PY
    OK
  3. Handle a generate response where thinking is a top-level field.
    $ curl -s http://localhost:11434/api/generate -d '{"model":"gpt-oss:20b","prompt":"Return OK.","think":"low","stream":false}'
    {"response":"OK","thinking":"Just output OK.","done":true}
  4. Avoid treating the reasoning trace as structured application data.
    $ python3 - <<'PY'
    payload = {"message": {"content": "OK", "thinking": "Internal reasoning"}}
    print('thinking' in payload['message'])
    PY
    True
  5. Raise the token budget when the response stops with only thinking output.
    $ curl -s http://localhost:11434/v1/messages -d '{"model":"gpt-oss:20b","max_tokens":20}'
    {"content":[{"type":"thinking"}],"stop_reason":"max_tokens"}