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

# GLM Models Guide

> Use Zhipu AI's GLM-5.1, GLM-5, and GLM-4.7 models via the Runcrate API for chat completions and reasoning.

export const RuncrateStyles = () => {
  if (typeof document !== 'undefined' && !document.getElementById('runcrate-overrides')) {
    const s = document.createElement('style');
    s.id = 'runcrate-overrides';
    s.textContent = `
      /* Match Runcrate's rounding scale (--radius: 0.75rem) */
      .rounded-sm { border-radius: 0.5rem !important; }   /* 8px */
      .rounded-md { border-radius: 0.625rem !important; } /* 10px */
      .rounded-lg { border-radius: 0.75rem !important; }  /* 12px */
      .rounded-l-sm { border-top-left-radius: 0.5rem !important; border-bottom-left-radius: 0.5rem !important; }
      .rounded-r-sm { border-top-right-radius: 0.5rem !important; border-bottom-right-radius: 0.5rem !important; }
      .rounded-l-md { border-top-left-radius: 0.625rem !important; border-bottom-left-radius: 0.625rem !important; }
      .rounded-r-md { border-top-right-radius: 0.625rem !important; border-bottom-right-radius: 0.625rem !important; }
      .rounded-l-lg { border-top-left-radius: 0.75rem !important; border-bottom-left-radius: 0.75rem !important; }
      .rounded-r-lg { border-top-right-radius: 0.75rem !important; border-bottom-right-radius: 0.75rem !important; }

      /* Cards: never pure white in light mode */
      .card { background-color: #fcfcfc !important; border-radius: 0.75rem !important; }
      html.dark .card { background-color: #141414 !important; }

      /* Docs hero box */
      .rc-hero { background-color: #fcfcfc; border: 1px solid #e0e0e0; }
      html.dark .rc-hero { background-color: #141414; border-color: #242424; }
      html.dark .rc-hero h1 { color: #f5f5f5; }

      /* Runcrate scrollbar — thin, transparent track, hide-until-hover thumb */
      ::-webkit-scrollbar { width: 6px; height: 6px; background-color: transparent; }
      ::-webkit-scrollbar-track { background-color: transparent; }
      ::-webkit-scrollbar-thumb { background-color: rgba(155, 155, 155, 0.5); border-radius: 10px; transition: opacity 0.3s ease; opacity: 0; }
      ::-webkit-scrollbar-thumb:hover { background-color: rgba(155, 155, 155, 0.7); }
      *:hover::-webkit-scrollbar-thumb,
      *:focus::-webkit-scrollbar-thumb,
      *:active::-webkit-scrollbar-thumb { opacity: 1; }
      * { scrollbar-width: thin; scrollbar-color: rgba(155, 155, 155, 0.5) transparent; }
    `;
    document.head.appendChild(s);
  }
  return null;
};

<RuncrateStyles />

Zhipu AI's GLM family offers strong multilingual chat models with competitive reasoning. All three generations are available through the Runcrate API.

## Available GLM models

| Model       | Context | Strengths                              |
| ----------- | ------- | -------------------------------------- |
| **GLM-5.1** | 128K    | Latest generation, strongest reasoning |
| **GLM-5**   | 128K    | Strong general-purpose chat            |
| **GLM-4.7** | 128K    | Cost-effective, fast inference         |

***

## Basic chat completion

<CodeGroup>
  ```python Python theme={"theme":"github-dark"}
  from runcrate import Runcrate

  client = Runcrate(api_key="rc_live_YOUR_API_KEY")

  response = client.models.chat_completion(
      model="zai-org/GLM-5.1",
      messages=[
          {"role": "system", "content": "You are a helpful assistant."},
          {"role": "user", "content": "Explain the difference between TCP and UDP for a beginner."},
      ],
      max_tokens=512,
  )

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

  ```typescript TypeScript theme={"theme":"github-dark"}
  import Runcrate from '@runcrate/sdk';

  const rc = new Runcrate({ apiKey: 'rc_live_YOUR_API_KEY' });

  const response = await rc.models.chatCompletion({
    model: 'zai-org/GLM-5.1',
    messages: [
      { role: 'system', content: 'You are a helpful assistant.' },
      { role: 'user', content: 'Explain the difference between TCP and UDP for a beginner.' },
    ],
  });

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

  ```bash curl theme={"theme":"github-dark"}
  curl https://api.runcrate.ai/v1/chat/completions \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer rc_live_YOUR_API_KEY" \
    -d '{
      "model": "zai-org/GLM-5.1",
      "messages": [
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain the difference between TCP and UDP for a beginner."}
      ]
    }'
  ```
</CodeGroup>

***

## Streaming with Vercel AI SDK

```typescript theme={"theme":"github-dark"}
// app/api/chat/route.ts
import { runcrate } from '@runcrate/ai';
import { streamText } from 'ai';

export async function POST(req: Request) {
  const { messages } = await req.json();

  const result = streamText({
    model: runcrate('zai-org/GLM-5.1'),
    system: 'You are a helpful assistant specializing in technical explanations.',
    messages,
  });

  return result.toDataStreamResponse();
}
```

***

## Structured output

```typescript theme={"theme":"github-dark"}
import { runcrate } from '@runcrate/ai';
import { generateText, Output } from 'ai';
import { z } from 'zod';

const AnalysisSchema = z.object({
  topic: z.string(),
  keyPoints: z.array(z.string()).describe('3–5 main arguments'),
  conclusion: z.string(),
  confidence: z.number().min(0).max(1),
});

const { output } = await generateText({
  model: runcrate('zai-org/GLM-5.1'),
  output: Output.object({ schema: AnalysisSchema }),
  prompt: 'Analyze the impact of remote work on software engineering productivity.',
});
```

***

## Comparing GLM generations

```python theme={"theme":"github-dark"}
from runcrate import Runcrate

client = Runcrate(api_key="rc_live_YOUR_API_KEY")

models = ["zai-org/GLM-5.1", "zai-org/GLM-5", "zai-org/GLM-4.7"]
prompt = "Write a SQL query for the top 10 customers by order value in the last 30 days."

for model in models:
    response = client.models.chat_completion(
        model=model,
        messages=[{"role": "user", "content": prompt}],
        max_tokens=512,
        temperature=0.3,
    )
    print(f"\n--- {model} ---")
    print(response.choices[0].message.content)
```

***

## Choosing the right GLM model

| Use case                    | Model   | Reason                            |
| --------------------------- | ------- | --------------------------------- |
| Complex reasoning           | GLM-5.1 | Strongest in the family           |
| General chat                | GLM-5   | Good balance of quality and speed |
| High-volume, cost-sensitive | GLM-4.7 | Fastest, lowest cost per token    |

***

## Tips

* **GLM-5.1** is the recommended default unless you need cost savings.
* **Multilingual**: GLM models handle Chinese and English equally well.
* **Temperature 0.3–0.5** works best for factual tasks; 0.7–0.9 for creative writing.

## Next steps

* [Chat completions reference](/models/chat-completions)
* [Model catalog](/models/model-catalog)
* [AI Chatbot with Next.js](/examples/ai-chatbot-nextjs) — build a chat UI with GLM
