> ## 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.

# Control GLM-5.2 Reasoning

> Control GLM-5.2 reasoning on FriendliAI. Turn thinking on or off, set the reasoning effort and budget, and parse reasoning from responses.

GLM-5.2 is a controllable reasoning model. You can control its reasoning with the following parameters:

| Parameter           | Type                 | Default |
| ------------------- | -------------------- | ------- |
| `enable_thinking`   | boolean              | `true`  |
| `include_reasoning` | boolean              | `true`  |
| `parse_reasoning`   | boolean              | `true`  |
| `reasoning_effort`  | enum (`high`, `max`) | `max`   |
| `reasoning_budget`  | integer              | `null`  |
| `clear_thinking`    | boolean              | `true`  |

If you don't set a parameter, the model uses its default. You can edit a parameter to control how the model reasons.

## Control Reasoning

To learn how to control the model's reasoning, see the following sections:

<Steps>
  <Step title="Turn Reasoning On" icon="dot">
    The `enable_thinking` parameter controls whether the model reasons before it generates a response. By default, reasoning's on.

    For complex tasks, where response quality matters, leave reasoning on. For simpler tasks, you can try turning it off, save tokens, and reduce the response time.

    You can turn reasoning on or off by setting `enable_thinking` to `true` or `false`, respectively. For example, to turn reasoning off, 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": False,
          },
        },
      )

      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": false,
        },
      })

      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": false
          }
      }'
      ```
    </CodeGroup>
  </Step>

  <Step title="Include Reasoning" icon="dot">
    The `include_reasoning` parameter controls whether reasoning's included in the response. By default, reasoning's included.

    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 used to generate a response. It's the same, whether or not you include reasoning.

    You can include or exclude reasoning by setting `include_reasoning` to `true` or `false`, respectively. For example, to exclude reasoning, 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": False,
        },
      )

      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": false,
      })

      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": false
      }'
      ```
    </CodeGroup>
  </Step>

  <Step title="Parse Reasoning" icon="dot">
    The `parse_reasoning` parameter controls whether reasoning's parsed in the response. By default, reasoning's parsed.

    If you want to turn parsing off (for example, you use your own parser), you can turn it off. Otherwise, reasoning's parsed into `reasoning` and `reasoning_content`, separate from `content`.

    You can parse reasoning or turn it off by setting `parse_reasoning` to `true` or `false`, respectively. For example, to turn parsing off, 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": False,
        },
      )

      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": false,
      })

      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": false
      }'
      ```
    </CodeGroup>
  </Step>

  <Step title="Set the Reasoning Effort" icon="dot">
    The `reasoning_effort` parameter controls the model's reasoning effort for each response. By default, reasoning's set to `max`.

    When you set a greater reasoning effort (`max` > `high`), the model generates longer chains of thought. That thinking improves response quality on complex tasks. Note that it also increases completion tokens and response times.

    You can set the effort by setting `reasoning_effort` to `high` or `max`. For example, to set it to `high`, 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>
  </Step>

  <Step title="Set a Reasoning Budget" icon="dot">
    The `reasoning_budget` parameter sets a reasoning budget for each response. By default, there's no budget.

    When you set a reasoning budget, you set the maximum number of reasoning tokens the model can use to generate a response. When the model reaches the budget, it'll stop thinking, sometimes mid-thought. For that reason, choose your budget amount carefully.

    You can set a budget by setting `reasoning_budget` to an integer. For example, to set it to 1,000 tokens, 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": 1000,
        },
      )

      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": 1000,
      })

      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": 1000
      }'
      ```
    </CodeGroup>
  </Step>

  <Step title="Clear Reasoning" icon="dot">
    The `clear_thinking` parameter controls whether reasoning's cleared after each response. By default, reasoning's cleared.

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

    You can clear or preserve reasoning by setting `clear_thinking` to `true` or `false`, respectively. For example, to preserve it, 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": False,
          },
        },
      )

      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": false,
        },
      })

      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": false
          }
      }'
      ```
    </CodeGroup>
  </Step>
</Steps>

To learn more, see [Reasoning](/docs/guides/reasoning).
