> For clean Markdown of any page, append `.md` to the page URL.
> For a complete documentation index, see https://docs.sarvam.ai/llms.txt.
> For full documentation content in one file, see https://docs.sarvam.ai/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.sarvam.ai/_mcp/server.

# GLM-5.2

> GLM-5.2 is an open-source model served on Sarvam infrastructure. 512K token context window with tool calling and visible reasoning.

GLM-5.2 is an [open-source model](/api/getting-started/models/open-source) served by
Sarvam in **beta**, and is **not tuned for Indian languages**. Beta access is granted per
API key — [contact us](/api/getting-started/help) to request whitelisting. For Indian
language workloads use [Sarvam-105B](/api/getting-started/models/sarvam-105b) instead.

A general-purpose open-source model. Its distinguishing feature on Sarvam is a very large
**512K token context window** — four times the 128K offered by Sarvam's own chat models —
which makes it a reasonable choice for reasoning over long documents or large codebases in
a single request.

## At a Glance

|                  |                                                                                                                                                                                                                                                                   |
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Model ID**     | `glm5.2`                                                                                                                                                                                                                                                          |
| **What it does** | General-purpose chat LLM; very long context and tool calling                                                                                                                                                                                                      |
| **Languages**    | Not tuned for Indian languages by Sarvam                                                                                                                                                                                                                          |
| **APIs**         | [Open-Source Models API Reference](/api-reference/open-source/chat-completions) (`POST /v2/chat/completions`, OpenAI-compatible, streaming supported) — also see [using an open-source model](/api/getting-started/models/open-source#using-an-open-source-model) |
| **Input limits** | 524,288-token context window; 10 MB request cap — [all limits](#limits-and-errors)                                                                                                                                                                                |
| **Benchmarks**   | None published by Sarvam                                                                                                                                                                                                                                          |
| **Pricing**      | ₹128.1 input · ₹23.79 cached input · ₹402.6 output — per 1M tokens; reasoning billed as output ([Pricing](/api/getting-started/pricing))                                                                                                                          |
| **Best for**     | Long-document and large-codebase analysis in a single request                                                                                                                                                                                                     |
| **Not for**      | Indian language workloads — use [Sarvam-105B](/api/getting-started/models/sarvam-105b)                                                                                                                                                                            |

## Why you might use it

#### Very long context

A 524,288 token context window lets you pass entire books, long transcripts, or large
code repositories in one request without chunking or retrieval.

#### Tool calling

Supports the OpenAI-compatible `tools` and `tool_choice` parameters, so it works with
agentic loops and function-calling frameworks.

## Model Specifications

#### Key Considerations

<ul>
  <li>
    Model ID: 

    <code>glm5.2</code>
  </li>

  <li>
    Context window: 524,288 tokens (512K)
  </li>

  <li>
    Tool calling: supported
  </li>

  <li>
    Image input: 

    <strong>not supported</strong>

     — text only
  </li>

  <li>
    Reasoning: 

    <strong>always on</strong>

     — the chain-of-thought arrives in a separate 

    <code>reasoning_content</code>

     field and counts against 

    <code>max_tokens</code>

    ; disable via 

    <code>extra_body</code>

     (see below)
  </li>

  <li>
    Maximum request size: 10 MB
  </li>

  <li>
    Temperature range: 0 to 2 (unset uses the model's own default)
  </li>

  <li>
    Top-p range: greater than 0, up to 1
  </li>

  <li>
    Supports streaming and non-streaming responses
  </li>

  <li>
    OpenAI-compatible chat completions format
  </li>
</ul>

## GLM-5.2 vs Sarvam's chat model

| Feature                    | GLM-5.2                 | Sarvam-105B                                   |
| -------------------------- | ----------------------- | --------------------------------------------- |
| **Context window**         | 524,288                 | 128,000                                       |
| **Tool calling**           | ✅                       | ✅                                             |
| **Image input**            | ❌                       | ❌                                             |
| **Indian language tuning** | None                    | 23 languages                                  |
| **Best for**               | Very long-context tasks | Maximum quality reasoning & agentic workflows |

Pick GLM-5.2 **only** when your task genuinely needs more than 128K of context. For
everything else — and especially for anything touching Indian languages — a Sarvam model
will serve you better and comes with Sarvam's own evaluation behind it.

## Key Capabilities

#### Basic Chat Completion

A single-turn request. Only the `model` field differs from a Sarvam chat completion call.

#### Python

```python
from sarvamai import SarvamAI

client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")

response = client.open_source_models.chat_completions_v2(
    model="glm5.2",
    messages=[
        {"role": "user", "content": "Explain the difference between a B-tree and a B+ tree index."}
    ],
    temperature=0.2,
    top_p=1,
    max_tokens=2000,
)

print(response.choices[0].message.content)
```

#### JavaScript

```javascript
import { SarvamAIClient } from "sarvamai";

const client = new SarvamAIClient({
    apiSubscriptionKey: "YOUR_SARVAM_API_KEY",
});

async function main() {
    const response = await client.openSourceModels.chatCompletionsV2({
        model: "glm5.2",
        messages: [
            {
                role: "user",
                content: "Explain the difference between a B-tree and a B+ tree index.",
            },
        ],
        temperature: 0.2,
        top_p: 1,
        max_tokens: 2000,
    });

    console.log(response.choices[0].message.content);
}

main();
```

#### cURL

```bash
curl -X POST https://api.sarvam.ai/v2/chat/completions \
  -H "api-subscription-key: $SARVAM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {"role": "user", "content": "Explain the difference between a B-tree and a B+ tree index."}
    ],
    "model": "glm5.2",
    "temperature": 0.2,
    "top_p": 1,
    "max_tokens": 2000
  }'
```

The answer is in `message.content`. The model's chain-of-thought arrives separately
in `message.reasoning_content` — see [Reasoning](#reasoning) below for how to budget
for it or turn it off.

#### Long-Context Analysis

GLM-5.2's main advantage. Pass a large document directly in the prompt instead of
chunking it — up to 512K tokens of context, minus whatever you reserve for
`max_tokens`.

#### Python

```python
from sarvamai import SarvamAI

client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")

with open("annual_report.txt", encoding="utf-8") as f:
    document = f.read()

response = client.open_source_models.chat_completions_v2(
    model="glm5.2",
    messages=[
        {"role": "system", "content": "You are a financial analyst. Answer only from the document provided."},
        {"role": "user", "content": f"{document}\n\nList every material risk disclosed, with the page or section it appears in."},
    ],
    temperature=0.1,
    max_tokens=4000,
)

print(response.choices[0].message.content)
```

#### cURL

```bash
# Build the payload with a file so large documents do not hit shell argument limits.
python3 - <<'PY' > payload.json
import json
document = open("annual_report.txt", encoding="utf-8").read()
json.dump({
    "model": "glm5.2",
    "messages": [
        {"role": "system", "content": "You are a financial analyst. Answer only from the document provided."},
        {"role": "user", "content": document + "\n\nList every material risk disclosed."},
    ],
    "temperature": 0.1,
    "max_tokens": 4000,
}, open("payload.json", "w"))
PY

curl -X POST https://api.sarvam.ai/v2/chat/completions \
  -H "api-subscription-key: $SARVAM_API_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @payload.json
```

Requests are capped at **10 MB** regardless of the context window. A document that
fits in 512K tokens can still exceed the byte cap and return `413 Payload Too Large`.

#### Tool Calling

GLM-5.2 supports OpenAI-compatible function calling.

#### Python

```python
from sarvamai import SarvamAI

client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")

response = client.open_source_models.chat_completions_v2(
    model="glm5.2",
    messages=[
        {"role": "user", "content": "What is the weather in Bengaluru right now?"}
    ],
    tools=[
        {
            "type": "function",
            "function": {
                "name": "get_weather",
                "description": "Get the current weather for a city.",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "city": {"type": "string", "description": "City name"}
                    },
                    "required": ["city"],
                },
            },
        }
    ],
    tool_choice="auto",
    max_tokens=1000,
)

print(response.choices[0].message.tool_calls)
```

#### cURL

```bash
curl -X POST https://api.sarvam.ai/v2/chat/completions \
  -H "api-subscription-key: $SARVAM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "glm5.2",
    "messages": [
      {"role": "user", "content": "What is the weather in Bengaluru right now?"}
    ],
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "get_weather",
          "description": "Get the current weather for a city.",
          "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"]
          }
        }
      }
    ],
    "tool_choice": "auto",
    "max_tokens": 1000
  }'
```

#### Streaming

Set `stream` to `true` to receive tokens as server-sent events. Because GLM-5.2
reasons before answering, the stream delivers `delta.reasoning_content` chunks
first and `delta.content` chunks after — read both, or the wait before the first
`content` chunk looks like a stall.

#### Python

```python
from sarvamai import SarvamAI

client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")

stream = client.open_source_models.chat_completions_v2(
    model="glm5.2",
    messages=[
        {"role": "user", "content": "Write a short note on database normalisation."}
    ],
    max_tokens=1000,
    stream=True,
)

for chunk in stream:
    delta = chunk.choices[0].delta
    reasoning = getattr(delta, "reasoning_content", None)
    if reasoning:
        pass  # the chain-of-thought — show it, log it, or skip it
    if delta.content:
        print(delta.content, end="", flush=True)
```

#### cURL

```bash
curl -N -X POST https://api.sarvam.ai/v2/chat/completions \
  -H "api-subscription-key: $SARVAM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "glm5.2",
    "messages": [
      {"role": "user", "content": "Write a short note on database normalisation."}
    ],
    "max_tokens": 1000,
    "stream": true
  }'
```

The `usage` object reported on **streamed** GLM-5.2 responses is currently
unreliable — it can report far fewer completion tokens than were actually
generated and billed. For accurate token accounting, use a non-streaming request
or the usage page on the [dashboard](https://dashboard.sarvam.ai).

## Reasoning

GLM-5.2 thinks before every answer — **by default**, not only when `reasoning_effort`
is set. The chain-of-thought arrives in a separate `reasoning_content` field on the
message (`delta.reasoning_content` when streaming); `content` carries only the final
answer. Two practical consequences:

* **Reasoning tokens are billed and count against `max_tokens`.** A small budget can be
  consumed entirely by reasoning, returning `content: null` with
  `finish_reason: "length"`. If your answers come back empty, raise `max_tokens` or
  turn thinking off.
* **Turn thinking off when you set `response_format`.** With reasoning active, a
  JSON-constrained request returns `content: null` instead of JSON.

The off-switch goes through `extra_body`:

```json
{
  "model": "glm5.2",
  "messages": [{ "role": "user", "content": "..." }],
  "extra_body": {
    "chat_template_kwargs": { "enable_thinking": false }
  }
}
```

With thinking off, responses are faster, the whole `max_tokens` budget goes to the
answer, and Structured Outputs work reliably.

## Parameters

GLM-5.2 accepts the standard OpenAI-compatible parameter set — `temperature`, `top_p`,
`max_tokens`, `stream`, `stop`, `n`, `seed`, `frequency_penalty`, `presence_penalty`,
`reasoning_effort`, `response_format` (Structured Outputs), `tools`, `tool_choice`, and
`extra_body`.
See the [full parameter table](/api/getting-started/models/open-source#supported-parameters)
for types, defaults, and ranges.

Model-specific exceptions:

* **`image_url` content parts are rejected** (`400`) — GLM-5.2 is text only.
* **`response_format` requires thinking off** — see [Reasoning](#reasoning) above.
* **`seed` is not currently reproducible** on this model — identical seeds return
  different completions. Use `temperature: 0` where you need stability.

## Limits and errors

Common errors for every model on `/v2/chat/completions` are documented on the
[Open-Source Models overview](/api/getting-started/models/open-source#errors). GLM-5.2-specific cases:

| Condition                                                              | Status | Code                         | What it means                                                                                                   |
| ---------------------------------------------------------------------- | ------ | ---------------------------- | --------------------------------------------------------------------------------------------------------------- |
| API key lacks beta access                                              | `400`  | `invalid_request_error`      | Request whitelisting — see [Beta APIs](/api-reference/beta-apis).                                               |
| Missing or invalid API key                                             | `403`  | `invalid_api_key_error`      | Check the `api-subscription-key` header.                                                                        |
| No credits remaining                                                   | `402`  | `insufficient_quota_error`   | Top up on the [dashboard](https://dashboard.sarvam.ai).                                                         |
| Unknown or unavailable model id                                        | `404`  | `not_found_error`            | Confirm the id with [`GET /v2/models`](/api-reference/open-source/models).                                      |
| Message contains an image part                                         | `400`  | `invalid_request_error`      | GLM-5.2 is text only. Use [`gemma4`](/api/getting-started/models/open-source/gemma-4-31b) for image input.      |
| `max_tokens` above 524,288                                             | `400`  | `invalid_request_error`      | `max_tokens` cannot exceed the context window.                                                                  |
| Estimated prompt tokens + `max_tokens` above 524,288                   | `422`  | `unprocessable_entity_error` | Shorten the prompt or lower `max_tokens`.                                                                       |
| Request body above the model's size cap                                | `413`  | `invalid_request_error`      | The byte cap is independent of the token window.                                                                |
| `tool_choice` naming a function with no `tools`                        | `422`  | `unprocessable_entity_error` | Provide the `tools` array alongside `tool_choice`.                                                              |
| Invalid tool schema (`$ref`, recursion, size)                          | `400`  | `invalid_request_error`      | See [Tool schemas](/api/getting-started/models/open-source#tool-schemas).                                       |
| Rate limit exceeded                                                    | `429`  | `rate_limit_exceeded_error`  | Back off and retry; see [Rate Limits](/api/getting-started/ratelimits).                                         |
| Model overloaded after retries                                         | `503`  | `model_overloaded`           | Retry later.                                                                                                    |
| `content: null` with `finish_reason: "length"`                         | `200`  | —                            | Reasoning consumed the whole `max_tokens` budget — raise it, or turn thinking off. See [Reasoning](#reasoning). |
| `content: null` with `finish_reason: "stop"` and `response_format` set | `200`  | —                            | Thinking + Structured Outputs conflict — turn thinking off. See [Reasoning](#reasoning).                        |

## Support

Sarvam supports the serving layer — auth, billing, rate limits, availability. Sarvam does
not tune or evaluate this model, so its output quality, reasoning, and language coverage
are properties of the model itself. See
[Open-Source Models](/api/getting-started/models/open-source) for the full support
boundary, and [Talk to us](/api/getting-started/help) for serving issues.