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

# Reasoning

> Control how a model reasons on FriendliAI. Compare controllable and always-on reasoning models, then set the reasoning effort, budget, and parsing behavior.

Some models can generate a chain of thought before they respond. These models use this intermediate step to split a prompt into more manageable parts, test different approaches, and arrive at a conclusion with more rigor.

This *reasoning* -- sometimes called *thinking* -- improves response quality, especially for complex tasks. However, it also increases the model's token usage and its response times.

Depending on the model, you may be able to control whether and how the model reasons. If the model supports it, FriendliAI can also parse reasoning content for you, such that you can clearly distinguish reasoning from the rest of the response.

## Reasoning Model Types

There are two types of reasoning models:

* **Controllable reasoning model**: With a controllable reasoning model, you use a parameter to control whether the model reasons. If you turn reasoning on, the model generates a chain of thought before it responds. If you turn it off, the model responds without generating one.

  To learn more, see [`enable_thinking`](#enable_thinking).

* **Always-on reasoning model**: An always-on reasoning model always reasons, meaning it generates a chain of thought before every response. You can't turn reasoning off.

By contrast, non-reasoning models can't generate chains of thought, meaning they always respond without generating them.

## Reasoning Parameters

You can control whether and how a model reasons with reasoning parameters, which you pass as either chat template keyword arguments or request body parameters. How you pass each depends on the parameter.

To learn more, see [Control a Capability](/docs/guides/introduction/get-started#control-a-capability).

Depending on the model, you can control reasoning with some or all of the following parameters:

| Parameter           | Data Type | Pass As                        |
| ------------------- | --------- | ------------------------------ |
| `enable_thinking`   | boolean   | Chat template keyword argument |
| `parse_reasoning`   | boolean   | Request body parameter         |
| `include_reasoning` | boolean   | Request body parameter         |
| `reasoning_effort`  | string    | Request body parameter         |
| `reasoning_budget`  | integer   | Request body parameter         |
| `clear_thinking`    | boolean   | Chat template keyword argument |

To see some specific examples, see [Choose a Model](/docs/examples/models/overview#choose-a-model), choose one, and see its Control Reasoning page.

### `enable_thinking`

If the model's controllable, you can turn reasoning on and off by setting the `enable_thinking` parameter to `true` or `false`, respectively. It controls whether the model reasons before it generates a response.

For complex tasks, where response quality matters, turn reasoning on. For simpler tasks, you can try turning it off to reduce token usage and response times.

To turn reasoning on, you can use the following code:

<CodeGroup>
  ```python OpenAI Python SDK wrap highlight={15-19} theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(
    base_url="https://api.friendli.ai/serverless/v1",
    api_key=os.environ["FRIENDLIAI_API_KEY"],
  )

  completion = client.chat.completions.create(
    model="zai-org/GLM-5.2",
    messages=[
      {"role": "system", "content": "You are a friendly assistant."},
      {"role": "user", "content": "Describe FriendliAI in one sentence."},
    ],
    extra_body={
      "chat_template_kwargs": {
        "enable_thinking": True,
      },
    },
  )

  print(completion.choices[0].message)
  ```

  ```javascript OpenAI JavaScript SDK wrap highlight={14-16} theme={null}
  import OpenAI from "openai"

  const client = new OpenAI({
    baseURL: "https://api.friendli.ai/serverless/v1",
    apiKey: process.env.FRIENDLIAI_API_KEY,
  })

  const completion = await client.chat.completions.create({
    model: "zai-org/GLM-5.2",
    messages: [
      { role: "system", content: "You are a friendly assistant." },
      { role: "user", content: "Describe FriendliAI in one sentence." },
    ],
    "chat_template_kwargs": {
      "enable_thinking": true,
    },
  })

  console.log(completion.choices[0].message)
  ```

  ```bash cURL wrap highlight={10-12} theme={null}
  curl -X POST https://api.friendli.ai/serverless/v1/chat/completions \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $FRIENDLIAI_API_KEY" \
    -d '{
      "model": "zai-org/GLM-5.2",
      "messages": [
        {"role": "system", "content": "You are a friendly assistant."},
        {"role": "user", "content": "Describe FriendliAI in one sentence."}
      ],
      "chat_template_kwargs": {
        "enable_thinking": true
      }
  }'
  ```
</CodeGroup>

### `parse_reasoning`

If the model supports it, you can turn parsing on and off by setting the `parse_reasoning` parameter to `true` or `false`, respectively. It controls whether reasoning's parsed in the response.

Without parsing, a reasoning model returns its chain of thought alongside the rest of the response, and usually separates the two with some kind of delimiter. FriendliAI's parser uses this delimiter to separate them; if there's no delimiter, the parser can't separate the two. If you turn parsing on, reasoning's parsed into both `reasoning` and `reasoning_content`, separate from `content`.

To turn parsing on, you can use the following code:

<CodeGroup>
  ```python OpenAI Python SDK wrap highlight={15-17} theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(
    base_url="https://api.friendli.ai/serverless/v1",
    api_key=os.environ["FRIENDLIAI_API_KEY"],
  )

  completion = client.chat.completions.create(
    model="zai-org/GLM-5.2",
    messages=[
      {"role": "system", "content": "You are a friendly assistant."},
      {"role": "user", "content": "Describe FriendliAI in one sentence."},
    ],
    extra_body={
      "parse_reasoning": True,
    },
  )

  print(completion.choices[0].message)
  ```

  ```javascript OpenAI JavaScript SDK wrap highlight={14} theme={null}
  import OpenAI from "openai"

  const client = new OpenAI({
    baseURL: "https://api.friendli.ai/serverless/v1",
    apiKey: process.env.FRIENDLIAI_API_KEY,
  })

  const completion = await client.chat.completions.create({
    model: "zai-org/GLM-5.2",
    messages: [
      { role: "system", content: "You are a friendly assistant." },
      { role: "user", content: "Describe FriendliAI in one sentence." },
    ],
    "parse_reasoning": true,
  })

  console.log(completion.choices[0].message)
  ```

  ```bash cURL wrap highlight={10} theme={null}
  curl -X POST https://api.friendli.ai/serverless/v1/chat/completions \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $FRIENDLIAI_API_KEY" \
    -d '{
      "model": "zai-org/GLM-5.2",
      "messages": [
        {"role": "system", "content": "You are a friendly assistant."},
        {"role": "user", "content": "Describe FriendliAI in one sentence."}
      ],
      "parse_reasoning": true
  }'
  ```
</CodeGroup>

### `include_reasoning`

If you turn parsing on, you can include or exclude reasoning by setting the `include_reasoning` parameter to `true` or `false`, respectively. It controls whether the reasoning's included in the response.

If you need reasoning content (for example, to display to users), include it in the response. If you don't, exclude it. Note that your choice doesn't change the number of tokens the model uses to generate a response. It's the same, whether or not you include reasoning.

To include reasoning, you can use the following code:

<CodeGroup>
  ```python OpenAI Python SDK wrap highlight={15-17} theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(
    base_url="https://api.friendli.ai/serverless/v1",
    api_key=os.environ["FRIENDLIAI_API_KEY"],
  )

  completion = client.chat.completions.create(
    model="zai-org/GLM-5.2",
    messages=[
      {"role": "system", "content": "You are a friendly assistant."},
      {"role": "user", "content": "Describe FriendliAI in one sentence."},
    ],
    extra_body={
      "include_reasoning": True,
    },
  )

  print(completion.choices[0].message)
  ```

  ```javascript OpenAI JavaScript SDK wrap highlight={14} theme={null}
  import OpenAI from "openai"

  const client = new OpenAI({
    baseURL: "https://api.friendli.ai/serverless/v1",
    apiKey: process.env.FRIENDLIAI_API_KEY,
  })

  const completion = await client.chat.completions.create({
    model: "zai-org/GLM-5.2",
    messages: [
      { role: "system", content: "You are a friendly assistant." },
      { role: "user", content: "Describe FriendliAI in one sentence." },
    ],
    "include_reasoning": true,
  })

  console.log(completion.choices[0].message)
  ```

  ```bash cURL wrap highlight={10} theme={null}
  curl -X POST https://api.friendli.ai/serverless/v1/chat/completions \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $FRIENDLIAI_API_KEY" \
    -d '{
      "model": "zai-org/GLM-5.2",
      "messages": [
        {"role": "system", "content": "You are a friendly assistant."},
        {"role": "user", "content": "Describe FriendliAI in one sentence."}
      ],
      "include_reasoning": true
  }'
  ```
</CodeGroup>

### `reasoning_effort`

If the model supports it, you can set the model's reasoning effort by setting the `reasoning_effort` parameter to a value the model supports. It controls the model's reasoning effort for each response.

The greater the reasoning effort, the longer the chain of thought. On complex tasks, these longer chains of thought improve response quality. Note that it also increases the number of completion tokens and response times.

To set the reasoning effort to a supported value, such as `high`, you can use the following code:

<CodeGroup>
  ```python OpenAI Python SDK wrap highlight={15-17} theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(
    base_url="https://api.friendli.ai/serverless/v1",
    api_key=os.environ["FRIENDLIAI_API_KEY"],
  )

  completion = client.chat.completions.create(
    model="zai-org/GLM-5.2",
    messages=[
      {"role": "system", "content": "You are a friendly assistant."},
      {"role": "user", "content": "Describe FriendliAI in one sentence."},
    ],
    extra_body={
      "reasoning_effort": "high",
    },
  )

  print(completion.choices[0].message)
  ```

  ```javascript OpenAI JavaScript SDK wrap highlight={14} theme={null}
  import OpenAI from "openai"

  const client = new OpenAI({
    baseURL: "https://api.friendli.ai/serverless/v1",
    apiKey: process.env.FRIENDLIAI_API_KEY,
  })

  const completion = await client.chat.completions.create({
    model: "zai-org/GLM-5.2",
    messages: [
      { role: "system", content: "You are a friendly assistant." },
      { role: "user", content: "Describe FriendliAI in one sentence." },
    ],
    "reasoning_effort": "high",
  })

  console.log(completion.choices[0].message)
  ```

  ```bash cURL wrap highlight={10} theme={null}
  curl -X POST https://api.friendli.ai/serverless/v1/chat/completions \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $FRIENDLIAI_API_KEY" \
    -d '{
      "model": "zai-org/GLM-5.2",
      "messages": [
        {"role": "system", "content": "You are a friendly assistant."},
        {"role": "user", "content": "Describe FriendliAI in one sentence."}
      ],
      "reasoning_effort": "high"
  }'
  ```
</CodeGroup>

### `reasoning_budget`

If the model supports it, you can set the model's reasoning budget by setting the `reasoning_budget` parameter to an integer. It controls the model's reasoning budget for each response.

The reasoning budget is the maximum number of reasoning tokens the model can use to generate a response. When the model reaches the budget, it stops thinking -- sometimes mid-thought. For this reason, choose a budget thoughtfully.

To set the reasoning budget to 10,000 tokens, you can use the following code:

<CodeGroup>
  ```python OpenAI Python SDK wrap highlight={15-17} theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(
    base_url="https://api.friendli.ai/serverless/v1",
    api_key=os.environ["FRIENDLIAI_API_KEY"],
  )

  completion = client.chat.completions.create(
    model="zai-org/GLM-5.2",
    messages=[
      {"role": "system", "content": "You are a friendly assistant."},
      {"role": "user", "content": "Describe FriendliAI in one sentence."},
    ],
    extra_body={
      "reasoning_budget": 10000,
    },
  )

  print(completion.choices[0].message)
  ```

  ```javascript OpenAI JavaScript SDK wrap highlight={14} theme={null}
  import OpenAI from "openai"

  const client = new OpenAI({
    baseURL: "https://api.friendli.ai/serverless/v1",
    apiKey: process.env.FRIENDLIAI_API_KEY,
  })

  const completion = await client.chat.completions.create({
    model: "zai-org/GLM-5.2",
    messages: [
      { role: "system", content: "You are a friendly assistant." },
      { role: "user", content: "Describe FriendliAI in one sentence." },
    ],
    "reasoning_budget": 10000,
  })

  console.log(completion.choices[0].message)
  ```

  ```bash cURL wrap highlight={10} theme={null}
  curl -X POST https://api.friendli.ai/serverless/v1/chat/completions \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $FRIENDLIAI_API_KEY" \
    -d '{
      "model": "zai-org/GLM-5.2",
      "messages": [
        {"role": "system", "content": "You are a friendly assistant."},
        {"role": "user", "content": "Describe FriendliAI in one sentence."}
      ],
      "reasoning_budget": 10000
  }'
  ```
</CodeGroup>

### `clear_thinking`

If the model supports it, you can clear or preserve reasoning by setting the `clear_thinking` parameter to `true` or `false`, respectively. It controls whether reasoning's cleared from the model's context window.

If reasoning matters to your workflow or use case, you can preserve it and add it to the model's context window. Otherwise, you can clear it. Note that preserving reasoning increases token usage.

To clear reasoning, you can use the following code:

<CodeGroup>
  ```python OpenAI Python SDK wrap highlight={15-19} theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(
    base_url="https://api.friendli.ai/serverless/v1",
    api_key=os.environ["FRIENDLIAI_API_KEY"],
  )

  completion = client.chat.completions.create(
    model="zai-org/GLM-5.2",
    messages=[
      {"role": "system", "content": "You are a friendly assistant."},
      {"role": "user", "content": "Describe FriendliAI in one sentence."},
    ],
    extra_body={
      "chat_template_kwargs": {
        "clear_thinking": True,
      },
    },
  )

  print(completion.choices[0].message)
  ```

  ```javascript OpenAI JavaScript SDK wrap highlight={14-16} theme={null}
  import OpenAI from "openai"

  const client = new OpenAI({
    baseURL: "https://api.friendli.ai/serverless/v1",
    apiKey: process.env.FRIENDLIAI_API_KEY,
  })

  const completion = await client.chat.completions.create({
    model: "zai-org/GLM-5.2",
    messages: [
      { role: "system", content: "You are a friendly assistant." },
      { role: "user", content: "Describe FriendliAI in one sentence." },
    ],
    "chat_template_kwargs": {
      "clear_thinking": true,
    },
  })

  console.log(completion.choices[0].message)
  ```

  ```bash cURL wrap highlight={10-12} theme={null}
  curl -X POST https://api.friendli.ai/serverless/v1/chat/completions \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $FRIENDLIAI_API_KEY" \
    -d '{
      "model": "zai-org/GLM-5.2",
      "messages": [
        {"role": "system", "content": "You are a friendly assistant."},
        {"role": "user", "content": "Describe FriendliAI in one sentence."}
      ],
      "chat_template_kwargs": {
        "clear_thinking": true
      }
  }'
  ```
</CodeGroup>
