POST /v1/chat/completions for most use cases, and switch to POST /v1/messages only when your application explicitly depends on the Anthropic Messages protocol.
Environment setup
Available models
| Model | Notes |
|---|---|
glm-5.1 | Latest generation general-purpose model |
glm-5 | New-generation general model |
glm-4.7 | General text; natively supports the web_search tool |
glm-4.6 | Earlier text model |
Interface options
OpenAI Compatible
POST /v1/chat/completions — recommended for most use cases, preserves GLM’s native thinking and web_search fields.Anthropic Compatible
POST /v1/messages — use this only when your app or SDK explicitly requires the Anthropic Messages protocol.OpenAI-compatible chat completions
Send a standardPOST /v1/chat/completions request using any OpenAI SDK or HTTP client:
GLM-specific extensions
The OpenAI-compatible entry point transparently passes through two GLM-native fields:thinking object — control chain-of-thought reasoning:
tools.type=web_search — enable native web search (see Web search below).
Response structure
A standard chat call returns the familiar OpenAI response shape:web_search tool was active and the upstream returns evidence, a top-level web_search array is appended to the response:
Web search
GLM’s web search capability usestools.type=web_search, but it requires a full web_search sub-object — not just a bare type field.
Correct request shape
web_search sub-object fields
| Field | Description | Recommendation |
|---|---|---|
enable | Activate web search | Always pass true |
search_engine | Search engine identifier | Use search_pro_jina for best results |
search_result | Include search evidence in response | Pass true to receive the web_search array |
search_query | Explicit search query string | Supply this for time-sensitive queries |
count | Number of search results to retrieve | Typically 3–5 |
When to use explicit search_query
General questions — let the model decide
General questions — let the model decide
For broad or timeless questions (e.g. “Summarise recent AI trends”), pass only
enable: true and let GLM choose its own search terms.Time-sensitive questions — provide an explicit query
Time-sensitive questions — provide an explicit query
For questions about today’s date, current weather, recent news, or latest announcements, explicitly provide
search_query and set search_result: true. Then read the top-level web_search array in the response instead of relying solely on the model’s natural-language answer for source verification.Anthropic-compatible messages
UsePOST /v1/messages when your application or SDK explicitly targets the Anthropic Messages API protocol:
Verify tool and
thinking extension support per channel when using the Anthropic-compatible entry point. Not all GLM-native extensions are guaranteed to round-trip through the Anthropic protocol layer.Compatibility boundaries
| Feature | OpenAI entry (/v1/chat/completions) | Anthropic entry (/v1/messages) |
|---|---|---|
GLM thinking field | ✅ Passed through | Verify per channel |
GLM web_search native tool | ✅ Supported | Verify per channel |
web_search evidence array in response | ✅ Returned at top level | Verify per channel |
| OpenAI SDK compatibility | ✅ Full | ❌ Not applicable |
| Anthropic SDK compatibility | ❌ Not applicable | ✅ Full |
Troubleshooting
invalid_tool — web_search tool requires web_search object
invalid_tool — web_search tool requires web_search object
Cause: You sent
{"tools": [{"type": "web_search"}]} without the required web_search sub-object.Fix: Always include the full sub-object:Channel unavailable / upstream error
Channel unavailable / upstream error
Search results are stale or missing today's information
Search results are stale or missing today's information
Cause: GLM performed an autonomous search with weak query terms, or
search_result was not set to true.Fix:- Add
"search_result": trueto theweb_searchsub-object. - Pass an explicit
search_querythat includes date-anchoring keywords (e.g."today 2026","current date"). - Read the top-level
web_searchevidence array in the response to verify sources rather than trusting only the model’s prose answer.
reasoning_content is empty or missing
reasoning_content is empty or missing
Cause: Thinking/reasoning is disabled for the selected model, or
"thinking": {"type": "disabled"} was set explicitly.Fix: Remove the thinking field or set "type": "enabled" for models that support it (e.g. glm-5.1).