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
openaipackage 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.Understand the response
When reasoning is enabled, thereasoning 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.