# GLM 5.2 API Complete API reference for GLM 5.2 LLM models powered by Z.ai. ## Model Variants This API supports one model variant: | Model | ID | Description | |-------|----|-------------| | **GLM 5.2 Text to Text** | `glm-5.2-text-to-text` | General text reasoning and writing | ## Quick Comparison | Feature | Text to Text | |---------|--------------| | Text input | Required ✅ | | Image input | Not supported ❌ | | File input | Not supported ❌ | | Streaming response | SSE | | `max_tokens` | Optional | | `top_p` | Optional | | `top_k` | Optional | ## GLM 5.2 Text to Text ### Endpoint ```http POST /api/v1/chat/completions ``` ### Request Parameters #### Required | Parameter | Type | Description | |-----------|------|-------------| | `model` | string | Must be `"glm-5.2-text-to-text"` | | `messages` | array | Ordered messages. See LLM API for the message structure. | | `stream` | boolean | `true` for SSE, `false` for a single JSON response. | #### Message Support | Field | Text | File | Image | |-------|------|------|-------| | `messages` | Required ✅ | Not supported ❌ | Not supported ❌ | #### Optional | Parameter | Type | Range | Description | |-----------|------|-------|-------------| | `max_tokens` | integer | `> 0` | Maximum output tokens. | | `top_p` | number | `0.0` - `1.0` | Limits cumulative probability mass for candidate tokens. | | `top_k` | integer | `0` - `100` | Limits the number of candidate tokens. | ### Example Request ```javascript const response = await fetch('https://api.flaq.ai/api/v1/chat/completions', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Accept': 'text/event-stream', 'Content-Type': 'application/json' }, body: JSON.stringify({ model: 'glm-5.2-text-to-text', messages: [ { role: 'user', content: 'Write a four-line modern poem about a programmer drinking coffee.' } ], stream: true, max_tokens: 500, top_p: 0.5, top_k: 1 }) }); ``` ## Response Format GLM 5.2 returns OpenAI-compatible completion responses. With `stream: true`, the response is Server-Sent Events; with `stream: false`, the response is a single JSON object. ## Best Practices - GLM 5.2 currently supports text-only input through this route. - Use `top_p` and `top_k` together when you need tighter control over output diversity. - Keep prompts structured when generating long-form content or code.