Skip to main content
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. Reasoning only works for models that support it.

Requirements

To run the examples on this page, you need the following:
  • An API key. The following examples assume you set it in an environment variable:
  • The openai package for Python or TypeScript. Install it with one of these commands:

The reasoning parameter

To enable or disable reasoning, pass a reasoning parameter in the request body of the chat completions API. 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.
The chat completions API also accepts a thinking parameter as an alternative to reasoning. Use whichever format your client or model expects.

Send a reasoning request

The following example sends a request with reasoning enabled.
You should receive a response similar to this:

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.