> ## Documentation Index
> Fetch the complete documentation index at: https://docs.modular.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Reasoning

> Enable chain-of-thought reasoning with the chat completions API

Reasoning lets a large language model (LLM) think through a problem step by
step before responding. When reasoning is enabled, the model generates
chain-of-thought text and returns that text separately from the answer.

To view the list of models that support reasoning, see the
[Supported models](/models) page. Reasoning only works for models that support
it.

## The `reasoning` parameter

To enable or disable reasoning, pass a `reasoning` parameter in the request body
of the [chat completions API](/api/inference/create-chat-completion).

Some models reason by default and don't require the `reasoning` parameter. Omit
the `reasoning` parameter in a request to see if the model returns reasoning by
default or not.

<Note>
  The chat completions API also accepts a `thinking` parameter as an
  alternative to `reasoning`. Use whichever format your client or model expects.
</Note>

## Send a reasoning request

Here's an example that shows how to send a request with reasoning
enabled. Be sure to [create an API
key](/administration/api-keys#create-an-api-key) before you run it.

<CodeGroup>
  ```python Python theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(
      base_url="https://api.modular.com/v1",
      api_key=os.environ.get("MODULAR_API_KEY"),
  )

  completion = client.chat.completions.create(
      model="google/gemma-4-31b-it",
      messages=[
          {"role": "user", "content": "How many r's are in the word strawberry?"}
      ],
      extra_body={"reasoning": {"enabled": True}}
  )

  print(completion.to_json(indent=2))
  ```

  ```bash cURL theme={null}
  curl -X POST https://api.modular.com/v1/chat/completions \
      -H "Authorization: Bearer $MODULAR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
          "model": "google/gemma-4-31b-it",
          "messages": [
              {"role": "user", "content": "How many r'\''s are in the word strawberry?"}
          ],
          "reasoning": {"enabled": true}
      }'
  ```
</CodeGroup>

You should receive a response similar to this:

```json theme={null}
{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "content": "There are 3 \"r\"s in strawberry.",
        "role": "assistant",
        "reasoning": "The user is asking for the number of letter 'r's in the word \"strawberry\".\n\n    *   S-T-R-A-W-B-E-R-R-Y\n    *   R (1)\n    *   R (2)\n    *   R (3)\n\nThere are 3 'r's."
      }
    }
  ],
  "model": "google/gemma-4-31b-it",
  "usage": {
    "completion_tokens": 144,
    "prompt_tokens": 27,
    "total_tokens": 171,
    "completion_tokens_details": {
      "reasoning_tokens": 132
    }
  }
}
```

## Understand the response

When reasoning is enabled, the `reasoning` response field contains the model's
chain-of-thought text. When reasoning is disabled or the model doesn't support
it, `reasoning` is null. Some models return a `reasoning_content` field instead;
this is equivalent to `reasoning` and contains the same information.

The `usage` field in the response reports `reasoning_tokens`, which counts the
tokens used for chain-of-thought. This way, you know how many additional tokens
the model uses when reasoning is enabled. When `reasoning` is disabled or not
supported, the request returns `0` on this field.
