diff --git a/code-rs/common/src/model_presets.rs b/code-rs/common/src/model_presets.rs index dcb7191bde0..5533bbb19b3 100644 --- a/code-rs/common/src/model_presets.rs +++ b/code-rs/common/src/model_presets.rs @@ -117,6 +117,21 @@ static PRESETS: Lazy> = Lazy::new(|| { }), show_in_picker: true, }, + ModelPreset { + id: "glm-4.7".to_string(), + model: "glm-4.7".to_string(), + display_name: "glm-4.7".to_string(), + description: "Z.AI flagship coding model with thinking always enabled.".to_string(), + default_reasoning_effort: ReasoningEffort::Medium, + supported_reasoning_efforts: vec![ReasoningEffortPreset { + effort: ReasoningEffort::Medium, + description: "Thinking is always enabled for GLM-4.7".to_string(), + }], + supported_text_verbosity: &[TextVerbosityConfig::Medium], + is_default: false, + upgrade: None, + show_in_picker: true, + }, ModelPreset { id: "bengalfox".to_string(), model: "bengalfox".to_string(), diff --git a/code-rs/core/src/chat_completions.rs b/code-rs/core/src/chat_completions.rs index 7514074d7ee..41a531d8815 100644 --- a/code-rs/core/src/chat_completions.rs +++ b/code-rs/core/src/chat_completions.rs @@ -169,6 +169,13 @@ pub(crate) async fn stream_chat_completions( for (idx, item) in input.iter().enumerate() { match item { ResponseItem::Message { role, content, .. } => { + let effective_role = if model_slug.eq_ignore_ascii_case("glm-4.7") + && role.eq_ignore_ascii_case("developer") + { + "system" + } else { + role.as_str() + }; // If the message contains any images, we must use the // multi-modal array form supported by Chat Completions: // [{ type: "text", text: "..." }, { type: "image_url", image_url: { url: "data:..." } }] @@ -191,7 +198,7 @@ pub(crate) async fn stream_chat_completions( } } } - messages.push(json!({"role": role, "content": parts})); + messages.push(json!({"role": effective_role, "content": parts})); } else { // Text-only messages can be sent as a single string for // maximal compatibility with providers that only accept @@ -206,7 +213,7 @@ pub(crate) async fn stream_chat_completions( _ => {} } } - messages.push(json!({"role": role, "content": text})); + messages.push(json!({"role": effective_role, "content": text})); } } ResponseItem::CompactionSummary { .. } => { @@ -296,6 +303,13 @@ pub(crate) async fn stream_chat_completions( "tools": tools_json, }); + if model_slug.eq_ignore_ascii_case("glm-4.7") { + if let Some(obj) = payload.as_object_mut() { + obj.insert("temperature".to_string(), json!(1.0)); + obj.insert("thinking".to_string(), json!({ "type": "enabled" })); + } + } + if let Some(openrouter_cfg) = provider.openrouter_config() { if let Some(obj) = payload.as_object_mut() { if let Some(provider_cfg) = &openrouter_cfg.provider { diff --git a/code-rs/core/src/codex/streaming.rs b/code-rs/core/src/codex/streaming.rs index f9127ed79e2..57697d6b15d 100644 --- a/code-rs/core/src/codex/streaming.rs +++ b/code-rs/core/src/codex/streaming.rs @@ -377,6 +377,7 @@ pub(super) async fn submission_loop( &new_config.model, Some(new_config.model_reasoning_effort), new_config.preferred_model_reasoning_effort, + Some(&new_config.model_provider_id), ) .await { diff --git a/code-rs/core/src/config.rs b/code-rs/core/src/config.rs index ec65a1ceef0..38c362fe534 100644 --- a/code-rs/core/src/config.rs +++ b/code-rs/core/src/config.rs @@ -917,11 +917,11 @@ impl Config { model_providers.entry(key).or_insert(provider); } - let model_provider_id = model_provider + let mut model_provider_id = model_provider .or(config_profile.model_provider) .or(cfg.model_provider) .unwrap_or_else(|| "openai".to_string()); - let model_provider = model_providers + let mut model_provider = model_providers .get(&model_provider_id) .ok_or_else(|| { std::io::Error::new( @@ -1082,6 +1082,32 @@ impl Config { let model_family = find_family_for_model(&model).unwrap_or_else(|| derive_default_model_family(&model)); + if model.eq_ignore_ascii_case("glm-4.7") { + if !model_provider_id.eq_ignore_ascii_case("zai") { + model_provider = model_providers + .get("zai") + .ok_or_else(|| { + std::io::Error::new( + std::io::ErrorKind::NotFound, + "Model provider `zai` not found", + ) + })? + .clone(); + model_provider_id = "zai".to_string(); + } + } else if model_provider_id.eq_ignore_ascii_case("zai") { + model_provider = model_providers + .get("openai") + .ok_or_else(|| { + std::io::Error::new( + std::io::ErrorKind::NotFound, + "Model provider `openai` not found", + ) + })? + .clone(); + model_provider_id = "openai".to_string(); + } + // Chat model reasoning effort (used when other flows follow the chat model). let preferred_model_reasoning_effort = config_profile .preferred_model_reasoning_effort @@ -1870,6 +1896,7 @@ args = ["-y", "@upstash/context7-mcp"] "gpt-5.1-codex", Some(ReasoningEffort::High), None, + None, ) .await?; @@ -1906,6 +1933,7 @@ model = "gpt-4.1" "o4-mini", Some(ReasoningEffort::High), None, + None, ) .await?; @@ -1935,6 +1963,7 @@ model = "gpt-4.1" "gpt-5.1-codex", Some(ReasoningEffort::Medium), None, + None, ) .await?; @@ -1979,6 +2008,7 @@ model = "gpt-5.1-codex" "o4-high", Some(ReasoningEffort::Medium), None, + None, ) .await?; diff --git a/code-rs/core/src/config/sources.rs b/code-rs/core/src/config/sources.rs index 9d0175d855f..bb7680c7628 100644 --- a/code-rs/core/src/config/sources.rs +++ b/code-rs/core/src/config/sources.rs @@ -147,6 +147,7 @@ pub async fn persist_model_selection( model: &str, effort: Option, preferred_effort: Option, + model_provider_id: Option<&str>, ) -> anyhow::Result<()> { use tokio::fs; @@ -208,6 +209,12 @@ pub async fn persist_model_selection( } else { profile_table.remove("preferred_model_reasoning_effort"); } + + if let Some(provider_id) = model_provider_id { + profile_table["model_provider"] = toml_edit::value(provider_id.to_string()); + } else { + profile_table.remove("model_provider"); + } } else { root["model"] = toml_edit::value(model.to_string()); match effort { @@ -229,6 +236,11 @@ pub async fn persist_model_selection( root.remove("preferred_model_reasoning_effort"); } } + if let Some(provider_id) = model_provider_id { + root["model_provider"] = toml_edit::value(provider_id.to_string()); + } else { + root.remove("model_provider"); + } } } diff --git a/code-rs/core/src/model_family.rs b/code-rs/core/src/model_family.rs index 84b8de08007..c8698d674a3 100644 --- a/code-rs/core/src/model_family.rs +++ b/code-rs/core/src/model_family.rs @@ -129,6 +129,12 @@ pub fn find_family_for_model(slug: &str) -> Option { context_window: Some(CONTEXT_WINDOW_1M), max_output_tokens: Some(32_768), ) + } else if slug.starts_with("glm-4.7") { + model_family!( + slug, "glm-4.7", + context_window: Some(CONTEXT_WINDOW_200K), + max_output_tokens: Some(128_000), + ) } else if slug.starts_with("gpt-oss") || slug.starts_with("openai/gpt-oss") { model_family!(slug, "gpt-oss", apply_patch_tool_type: Some(ApplyPatchToolType::Function), uses_local_shell_tool: true, diff --git a/code-rs/core/src/model_provider_info.rs b/code-rs/core/src/model_provider_info.rs index 93f2e3d69a4..a25e58a9281 100644 --- a/code-rs/core/src/model_provider_info.rs +++ b/code-rs/core/src/model_provider_info.rs @@ -519,6 +519,26 @@ pub fn built_in_model_providers() -> HashMap { openrouter: None, }, ), + ( + "zai", + P { + name: "Z.AI".into(), + base_url: Some("https://api.z.ai/api/coding/paas/v4".to_string()), + env_key: Some("Z_AI_API_KEY".to_string()), + env_key_instructions: Some( + "Set Z_AI_API_KEY to your Z.AI API key.".to_string(), + ), + wire_api: WireApi::Chat, + query_params: None, + http_headers: None, + env_http_headers: None, + request_max_retries: None, + stream_max_retries: None, + stream_idle_timeout_ms: None, + requires_openai_auth: false, + openrouter: None, + }, + ), (BUILT_IN_OSS_MODEL_PROVIDER_ID, create_oss_provider()), ] .into_iter() diff --git a/code-rs/core/src/reasoning.rs b/code-rs/core/src/reasoning.rs index 86efc61dcc2..3558bb6a68d 100644 --- a/code-rs/core/src/reasoning.rs +++ b/code-rs/core/src/reasoning.rs @@ -61,6 +61,7 @@ const DEFAULT_EFFORTS: &[ReasoningEffort] = &[ ReasoningEffort::Medium, ReasoningEffort::High, ]; +const GLM_4_7_EFFORTS: &[ReasoningEffort] = &[ReasoningEffort::Medium]; fn reasoning_effort_rank(effort: ReasoningEffort) -> u8 { match effort { @@ -108,6 +109,10 @@ pub fn supported_reasoning_efforts_for_model(model: &str) -> &'static [Reasoning return GPT5_EFFORTS; } + if lower.starts_with("glm-4.7") { + return GLM_4_7_EFFORTS; + } + if lower.starts_with("codex-") { return CODEX_FALLBACK_EFFORTS; } diff --git a/code-rs/mcp-server/src/message_processor.rs b/code-rs/mcp-server/src/message_processor.rs index 5515cb42d51..9df48c956b3 100644 --- a/code-rs/mcp-server/src/message_processor.rs +++ b/code-rs/mcp-server/src/message_processor.rs @@ -1604,6 +1604,10 @@ fn apply_model_selection(config: &mut Config, model: &str, effort: ReasoningEffo updated = true; } + if update_provider_for_model(config, model) { + updated = true; + } + if config.model_reasoning_effort != clamped_effort { config.model_reasoning_effort = clamped_effort; updated = true; @@ -1612,6 +1616,32 @@ fn apply_model_selection(config: &mut Config, model: &str, effort: ReasoningEffo updated } +fn update_provider_for_model(config: &mut Config, model: &str) -> bool { + const ZAI_PROVIDER_ID: &str = "zai"; + const GLM_4_7_MODEL: &str = "glm-4.7"; + + if model.eq_ignore_ascii_case(GLM_4_7_MODEL) { + if !config.model_provider_id.eq_ignore_ascii_case(ZAI_PROVIDER_ID) { + if let Some(provider) = config.model_providers.get(ZAI_PROVIDER_ID) { + config.model_provider_id = ZAI_PROVIDER_ID.to_string(); + config.model_provider = provider.clone(); + return true; + } + } + return false; + } + + if config.model_provider_id.eq_ignore_ascii_case(ZAI_PROVIDER_ID) { + if let Some(provider) = config.model_providers.get("openai") { + config.model_provider_id = "openai".to_string(); + config.model_provider = provider.clone(); + return true; + } + } + + false +} + fn configure_session_op_from_config(config: &Config) -> Op { Op::ConfigureSession { provider: config.model_provider.clone(), diff --git a/code-rs/tui/src/chatwidget.rs b/code-rs/tui/src/chatwidget.rs index 18b32add0b2..fa18148ccd4 100644 --- a/code-rs/tui/src/chatwidget.rs +++ b/code-rs/tui/src/chatwidget.rs @@ -21913,6 +21913,32 @@ Have we met every part of this goal and is there no further work to do?"# .unwrap_or(requested) } + fn update_provider_for_model(&mut self, model: &str) -> bool { + const ZAI_PROVIDER_ID: &str = "zai"; + const GLM_4_7_MODEL: &str = "glm-4.7"; + + if model.eq_ignore_ascii_case(GLM_4_7_MODEL) { + if !self.config.model_provider_id.eq_ignore_ascii_case(ZAI_PROVIDER_ID) { + if let Some(provider) = self.config.model_providers.get(ZAI_PROVIDER_ID) { + self.config.model_provider_id = ZAI_PROVIDER_ID.to_string(); + self.config.model_provider = provider.clone(); + return true; + } + } + return false; + } + + if self.config.model_provider_id.eq_ignore_ascii_case(ZAI_PROVIDER_ID) { + if let Some(provider) = self.config.model_providers.get("openai") { + self.config.model_provider_id = "openai".to_string(); + self.config.model_provider = provider.clone(); + return true; + } + } + + false + } + fn apply_model_selection_inner( &mut self, model: String, @@ -21939,6 +21965,10 @@ Have we met every part of this goal and is there no further work to do?"# updated = true; } + if self.update_provider_for_model(trimmed) { + updated = true; + } + if let Some(explicit) = effort { if self.config.preferred_model_reasoning_effort != Some(explicit) { self.config.preferred_model_reasoning_effort = Some(explicit); diff --git a/code-rs/tui/src/history_cell/formatting.rs b/code-rs/tui/src/history_cell/formatting.rs index 88c2c94e7a8..337c6386aef 100644 --- a/code-rs/tui/src/history_cell/formatting.rs +++ b/code-rs/tui/src/history_cell/formatting.rs @@ -397,6 +397,7 @@ pub(crate) fn pretty_provider_name(id: &str) -> String { "read-website-fast" => "readweb", "sequential-thinking" => "think", "discord-bot" => "discord", + "zai" => "z.ai", _ => id, } .to_string() diff --git a/zai/zai-api.md b/zai/zai-api.md new file mode 100644 index 00000000000..3db38f363d6 --- /dev/null +++ b/zai/zai-api.md @@ -0,0 +1,300 @@ +# Introduction + + + The API reference describes the RESTful APIs you can use to interact with the Z.AI platform. + + +Z.AI provides standard HTTP API interfaces that support multiple programming languages and development environments, with [SDKs](/guides/develop/python/introduction) also available. + +## API Endpoint + +Z.ai Platform's general API endpoint is as follows: + +``` +https://api.z.ai/api/paas/v4 +``` + + + Note: When using the [GLM Coding Plan](/devpack/overview), you need to configure the dedicated \ + Coding endpoint - [https://api.z.ai/api/coding/paas/v4](https://api.z.ai/api/coding/paas/v4) \ + instead of the general endpoint - [https://api.z.ai/api/paas/v4](https://api.z.ai/api/paas/v4) \ + Note: The Coding API endpoint is only for Coding scenarios and is not applicable to general API scenarios. Please use them accordingly. + + +## Authentication + +The Z.AI API uses the standard **HTTP Bearer** for authentication. +An API key is required, which you can create or manage on the [API Keys Page](https://z.ai/manage-apikey/apikey-list). + +API keys should be provided via HTTP Bearer Authentication in HTTP Request Headers. + +``` +Authorization: Bearer ZAI_API_KEY +``` + +## Playground + +The API Playground allows developers to quickly try out API calls. Simply click **Try it** on the API details page to get started. + +* On the API details page, there are many interactive options, such as **switching input types**, **switching tabs**, and **adding new content**. +* You can click **Add an item** or **Add new property** to add more properties the API need. +* **Note** that when switching the tabs, the previous properties value you need re-input or re-switch. + +## Call Examples + + + + ```bash theme={null} + curl -X POST "https://api.z.ai/api/paas/v4/chat/completions" \ + -H "Content-Type: application/json" \ + -H "Accept-Language: en-US,en" \ + -H "Authorization: Bearer YOUR_API_KEY" \ + -d '{ + "model": "glm-4.7", + "messages": [ + { + "role": "system", + "content": "You are a helpful AI assistant." + }, + { + "role": "user", + "content": "Hello, please introduce yourself." + } + ], + "temperature": 1.0, + "stream": true + }' + ``` + + + + **Install SDK** + + ```bash theme={null} + # Install latest version + pip install zai-sdk + + # Or specify version + pip install zai-sdk==0.1.0 + ``` + + **Verify Installation** + + ```python theme={null} + import zai + print(zai.__version__) + ``` + + **Usage Example** + + ```python theme={null} + from zai import ZaiClient + + # Initialize client + client = ZaiClient(api_key="YOUR_API_KEY") + + # Create chat completion request + response = client.chat.completions.create( + model="glm-4.7", + messages=[ + { + "role": "system", + "content": "You are a helpful AI assistant." + }, + { + "role": "user", + "content": "Hello, please introduce yourself." + } + ] + ) + + # Get response + print(response.choices[0].message.content) + ``` + + + + **Install SDK** + + **Maven** + + ```xml theme={null} + + ai.z.openapi + zai-sdk + 0.3.0 + + ``` + + **Gradle (Groovy)** + + ```groovy theme={null} + implementation 'ai.z.openapi:zai-sdk:0.3.0' + ``` + + **Usage Example** + + ```java theme={null} + import ai.z.openapi.ZaiClient; + import ai.z.openapi.service.model.*; + import java.util.Arrays; + + public class QuickStart { + public static void main(String[] args) { + // Initialize client + ZaiClient client = ZaiClient.builder().ofZAI() + .apiKey("YOUR_API_KEY") + .build(); + + // Create chat completion request + ChatCompletionCreateParams request = ChatCompletionCreateParams.builder() + .model("glm-4.7") + .messages(Arrays.asList( + ChatMessage.builder() + .role(ChatMessageRole.USER.value()) + .content("Hello, who are you?") + .build() + )) + .stream(false) + .build(); + + // Send request + ChatCompletionResponse response = client.chat().createChatCompletion(request); + + // Get response + System.out.println(response.getData().getChoices().get(0).getMessage().getContent()); + } + } + ``` + + + + **Install SDK** + + ```bash theme={null} + # Install or upgrade to latest version + pip install --upgrade 'openai>=1.0' + ``` + + **Verify Installation** + + ```python theme={null} + python -c "import openai; print(openai.__version__)" + ``` + + **Usage Example** + + ```python theme={null} + from openai import OpenAI + + client = OpenAI( + api_key="your-Z.AI-api-key", + base_url="https://api.z.ai/api/paas/v4/" + ) + + completion = client.chat.completions.create( + model="glm-4.7", + messages=[ + {"role": "system", "content": "You are a smart and creative novelist"}, + {"role": "user", "content": "Please write a short fairy tale story as a fairy tale master"} + ] + ) + + print(completion.choices[0].message.content) + ``` + + + + **Install SDK** + + ```bash theme={null} + # Install or upgrade to latest version + npm install openai + + # Or using yarn + yarn add openai + ``` + + **Usage Example** + + ```javascript theme={null} + import OpenAI from "openai"; + + const client = new OpenAI({ + apiKey: "your-Z.AI-api-key", + baseURL: "https://api.z.ai/api/paas/v4/" + }); + + async function main() { + const completion = await client.chat.completions.create({ + model: "glm-4.7", + messages: [ + { role: "system", content: "You are a helpful AI assistant." }, + { role: "user", content: "Hello, please introduce yourself." } + ] + }); + + console.log(completion.choices[0].message.content); + } + + main(); + ``` + + + + **Install SDK** + + **Maven** + + ```xml theme={null} + + com.openai + openai-java + 2.20.1 + + ``` + + **Gradle (Groovy)** + + ```groovy theme={null} + implementation 'com.openai:openai-java:2.20.1' + ``` + + **Usage Example** + + ```java theme={null} + import com.openai.client.OpenAIClient; + import com.openai.client.okhttp.OpenAIOkHttpClient; + import com.openai.models.chat.completions.ChatCompletion; + import com.openai.models.chat.completions.ChatCompletionCreateParams; + + public class QuickStart { + public static void main(String[] args) { + // Initialize client + OpenAIClient client = OpenAIOkHttpClient.builder() + .apiKey("your-Z.AI-api-key") + .baseUrl("https://api.z.ai/api/paas/v4/") + .build(); + + // Create chat completion request + ChatCompletionCreateParams params = ChatCompletionCreateParams.builder() + .addSystemMessage("You are a helpful AI assistant.") + .addUserMessage("Hello, please introduce yourself.") + .model("glm-4.7") + .build(); + + // Send request and get response + ChatCompletion chatCompletion = client.chat().completions().create(params); + Object response = chatCompletion.choices().get(0).message().content(); + + System.out.println(response); + } + } + ``` + + + + +--- + +> To find navigation and other pages in this documentation, fetch the llms.txt file at: https://docs.z.ai/llms.txt diff --git a/zai/zai-glm-47.md b/zai/zai-glm-47.md new file mode 100644 index 00000000000..e6ba823f658 --- /dev/null +++ b/zai/zai-glm-47.md @@ -0,0 +1,485 @@ +# GLM-4.7 + +## Overview + + + The [GLM Coding Plan](https://z.ai/subscribe?utm_source=zai\&utm_medium=link\&utm_term=guide\&utm_content=glm-coding-plan\&utm_campaign=Platform_Ops&_channel_track_key=Xz9zVAvo) is a subscription package designed specifically for AI-powered coding. GLM-4.7 is now available in top coding tools, starting at just \$3/month — powering Claude Code, Cline, OpenCode, Roo Code and more. The package is designed to make coding faster, smarter, and more reliable. + + +GLM-4.7 is Z.AI's latest flagship model, featuring upgrades in two key areas: enhanced programming capabilities and more stable multi-step reasoning/execution. It demonstrates significant improvements in executing complex agent tasks while delivering more natural conversational experiences and superior front-end aesthetics. + + + + Text + + + + Text + + + + 200K + + + + 128K + + + +## Capability + + + + Offering multiple thinking modes for different scenarios + + + + Support real-time streaming responses to enhance user interaction experience + + + + Powerful tool invocation capabilities, enabling integration with various external toolsets + + + + Intelligent caching mechanism to optimize performance in long conversations + + + + Support for structured output formats like JSON, facilitating system integration + + + +## Usage + + + + GLM-4.7 focuses on “task completion” rather than single-point code generation. It autonomously accomplishes requirement comprehension, solution decomposition, and multi-technology stack integration starting from target descriptions. In complex scenarios involving frontend-backend coordination, real-time interaction, and peripheral device calls, it directly generates structurally complete, executable code frameworks. This significantly reduces manual assembly and iterative debugging costs, making it ideal for complex demos, prototype validation, and automated development workflows. + + + + In scenarios requiring cameras, real-time input, and interactive controls, GLM-4.7 demonstrates superior system-level comprehension. It integrates visual recognition, logic control, and application code into unified solutions, enabling rapid construction of interactive applications like gesture control and real-time feedback. This accelerates the journey from concept to operational application. + + + + Significantly enhanced understanding of visual code and UI specifications. GLM-4.7 provides more aesthetically pleasing and consistent default solutions for layout structures, color harmony, and component styling, reducing time spent on repetitive “fine-tuning” of styles. It is well-suited for low-code platforms, AI frontend generation tools, and rapid prototyping scenarios. + + + + Maintains context and constraints more reliably during multi-turn conversations. Responds more directly to simple queries while continuously clarifying objectives and advancing resolution paths for complex issues. GLM-4.7 functions as a collaborative “problem-solving partner,” ideal for high-frequency collaboration scenarios like development support, solution discussions, and decision-making assistance. + + + + Delivers more nuanced, vividly descriptive prose that builds atmosphere through sensory details like scent, sound, and light. In role-playing and narrative creation, it maintains consistent adherence to world-building and character archetypes, advancing plots with natural tension. Ideal for interactive storytelling, IP content creation, and character-based applications. + + + + In office creation, GLM-4.7 demonstrates significantly enhanced layout consistency and aesthetic stability. It reliably adapts to mainstream aspect ratios like 16:9, minimizes template-like elements in typography hierarchy, white space, and color schemes, and produces near-ready-to-use results. This makes it ideal for AI presentation tools, enterprise office systems, and automated content generation scenarios. + + + + Enhanced capabilities in user intent understanding, information retrieval, and result integration. For complex queries and research tasks, GLM-4.7 not only returns information but also performs structured organization and cross-source consolidation. Through multi-round interactions, it progressively narrows in on core conclusions, making it suitable for in-depth research and decision-support scenarios. + + + +## Introducing GLM-4.7 + + + + GLM-4.7 achieves significant breakthroughs across three dimensions: programming, reasoning, and agent capabilities: + + * **Enhanced Programming Capabilities**: Substantially improves model performance in multi-language coding and terminal agent applications; GLM-4.7 now implements a “think before acting” mechanism within programming frameworks like Claude Code, Kilo Code, TRAE, Cline, and Roo Code, delivering more stable performance on complex tasks. + * **Enhanced Frontend Aesthetics**: GLM-4.7 shows marked progress in frontend generation quality, producing visually superior webpages, PPTs, and posters. + * **Enhanced Tool Invocation Capabilities**: GLM-4.7 demonstrates improved tool invocation skills, scoring 67 points on the BrowseComp web task evaluation and achieving an open-source SOTA of 84.7 points on the τ²-Bench interactive tool invocation benchmark, surpassing Claude Sonnet 4.5 + * **Enhanced reasoning capabilities**: Significantly improved mathematical and reasoning skills, achieving 42.8% on the HLE (“Human Last Exam”) benchmark—a 41% increase over GLM-4.6 and surpassing GPT-5.1 + * **Enhanced General Capabilities**: GLM-4.7 delivers more concise, intelligent, and empathetic conversations, with more eloquent and immersive writing and role-playing + + Description *`Code Arena: A professional coding evaluation system with millions of global users participating in blind tests. GLM-4.7 ranks first among open-source models and domestic models, outperforming GPT-5.2`* + + In mainstream benchmark performance, GLM-4.7's coding capabilities align with Claude Sonnet 4.5: Achieved top open-source ranking on SWE-bench-Verified; Reached an open-source SOTA score of 84.9 on LiveCodeBench V6, surpassing Claude Sonnet 4.5; Achieved 73.8% on SWE-bench Verified (a 5.8% improvement over GLM-4.6), 66.7% on SWE-bench Multilingual (a 12.9% improvement), and 41% on Terminal Bench 2.0 (a 16.5% improvement). + + ![Description](https://cdn.bigmodel.cn/markdown/1766459089466image.png?attname=image.png) + + + + + + In the Claude Code environment, we tested 100 real programming tasks covering core capabilities like frontend, backend, and instruction following. Results show GLM-4.7 demonstrates significant improvements over GLM-4.6 in both stability and deliverability. Description With enhanced programming capabilities, developers can more naturally organize their development workflow around “task delivery,” forming an end-to-end closed loop from requirement understanding to implementation. + + + + GLM-4.7 further enhances the interleaved reasoning capabilities introduced in GLM-4.5 by introducing retained reasoning and round-based reasoning, making complex task execution more stable and controllable. + + * Interleaved Reasoning: Performs reasoning before each response/tool invocation, improving compliance with complex instructions and code generation quality. + * Retention-Based Reasoning: Automatically preserves reasoning blocks across multi-turn dialogues, improving cache hit rates and reducing computational costs—ideal for long-term complex tasks. + * Round-Level Reasoning: Enables round-based control of reasoning overhead within a single session—disable reasoning for simple tasks to reduce latency, or enable it for complex tasks to boost accuracy and stability. + + [\_Related Documentation: https://docs.z.ai/guides/capabilities/thinking-mode](https://docs.z.ai/guides/capabilities/thinking-mode) + + + + GLM-4.7 demonstrates superior task decomposition and technology stack integration in complex tasks, delivering **complete, executable code** in a single step while clearly identifying critical dependencies and execution steps, significantly reducing manual debugging costs. + + + + + GLM-4.7 enhances its comprehension of visual code. In frontend design, it better interprets UI design specifications, offering more aesthetically pleasing default solutions for layout structures, color harmony, and component styling. This reduces the time developers spend on style “fine-tuning.” + + + + + + +## Resources + +* [API Documentation](/api-reference/llm/chat-completion): Learn how to call the API. + +## Quick Start + +The following is a full sample code to help you onboard GLM-4.7 with ease. + + + + **Basic Call** + + ```bash theme={null} + curl -X POST "https://api.z.ai/api/paas/v4/chat/completions" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer your-api-key" \ + -d '{ + "model": "glm-4.7", + "messages": [ + { + "role": "user", + "content": "As a marketing expert, please create an attractive slogan for my product." + }, + { + "role": "assistant", + "content": "Sure, to craft a compelling slogan, please tell me more about your product." + }, + { + "role": "user", + "content": "Z.AI Open Platform" + } + ], + "thinking": { + "type": "enabled" + }, + "max_tokens": 4096, + "temperature": 1.0 + }' + ``` + + **Streaming Call** + + ```bash theme={null} + curl -X POST "https://api.z.ai/api/paas/v4/chat/completions" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer your-api-key" \ + -d '{ + "model": "glm-4.7", + "messages": [ + { + "role": "user", + "content": "As a marketing expert, please create an attractive slogan for my product." + }, + { + "role": "assistant", + "content": "Sure, to craft a compelling slogan, please tell me more about your product." + }, + { + "role": "user", + "content": "Z.AI Open Platform" + } + ], + "thinking": { + "type": "enabled" + }, + "stream": true, + "max_tokens": 4096, + "temperature": 1.0 + }' + ``` + + + + **Install SDK** + + ```bash theme={null} + # Install latest version + pip install zai-sdk + + # Or specify version + pip install zai-sdk==0.1.0 + ``` + + **Verify Installation** + + ```python theme={null} + import zai + + print(zai.__version__) + ``` + + **Basic Call** + + ```python theme={null} + from zai import ZaiClient + + client = ZaiClient(api_key="your-api-key") # Your API Key + + response = client.chat.completions.create( + model="glm-4.7", + messages=[ + { + "role": "user", + "content": "As a marketing expert, please create an attractive slogan for my product.", + }, + { + "role": "assistant", + "content": "Sure, to craft a compelling slogan, please tell me more about your product.", + }, + {"role": "user", "content": "Z.AI Open Platform"}, + ], + thinking={ + "type": "enabled", + }, + max_tokens=4096, + temperature=1.0, + ) + + # Get complete response + print(response.choices[0].message) + ``` + + **Streaming Call** + + ```python theme={null} + from zai import ZaiClient + + client = ZaiClient(api_key="your-api-key") # Your API Key + + response = client.chat.completions.create( + model="glm-4.7", + messages=[ + { + "role": "user", + "content": "As a marketing expert, please create an attractive slogan for my product.", + }, + { + "role": "assistant", + "content": "Sure, to craft a compelling slogan, please tell me more about your product.", + }, + {"role": "user", "content": "Z.AI Open Platform"}, + ], + thinking={ + "type": "enabled", # Optional: "disabled" or "enabled", default is "enabled" + }, + stream=True, + max_tokens=4096, + temperature=0.6, + ) + + # Stream response + for chunk in response: + if chunk.choices[0].delta.reasoning_content: + print(chunk.choices[0].delta.reasoning_content, end="", flush=True) + + if chunk.choices[0].delta.content: + print(chunk.choices[0].delta.content, end="", flush=True) + ``` + + + + **Install SDK** + + **Maven** + + ```xml theme={null} + + ai.z.openapi + zai-sdk + 0.3.0 + + ``` + + **Gradle (Groovy)** + + ```groovy theme={null} + implementation 'ai.z.openapi:zai-sdk:0.3.0' + ``` + + **Basic Call** + + ```java theme={null} + import ai.z.openapi.ZaiClient; + import ai.z.openapi.service.model.ChatCompletionCreateParams; + import ai.z.openapi.service.model.ChatCompletionResponse; + import ai.z.openapi.service.model.ChatMessage; + import ai.z.openapi.service.model.ChatMessageRole; + import ai.z.openapi.service.model.ChatThinking; + import java.util.Arrays; + + public class BasicChat { + public static void main(String[] args) { + // Initialize client + ZaiClient client = ZaiClient.builder().ofZAI().apiKey("your-api-key").build(); + + // Create chat completion request + ChatCompletionCreateParams request = + ChatCompletionCreateParams.builder() + .model("glm-4.7") + .messages( + Arrays.asList( + ChatMessage.builder() + .role(ChatMessageRole.USER.value()) + .content( + "As a marketing expert, please create an attractive slogan for my product.") + .build(), + ChatMessage.builder() + .role(ChatMessageRole.ASSISTANT.value()) + .content( + "Sure, to craft a compelling slogan, please tell me more about your product.") + .build(), + ChatMessage.builder() + .role(ChatMessageRole.USER.value()) + .content("Z.AI Open Platform") + .build())) + .thinking(ChatThinking.builder().type("enabled").build()) + .maxTokens(4096) + .temperature(1.0f) + .build(); + + // Send request + ChatCompletionResponse response = client.chat().createChatCompletion(request); + + // Get response + if (response.isSuccess()) { + Object reply = response.getData().getChoices().get(0).getMessage(); + System.out.println("AI Response: " + reply); + } else { + System.err.println("Error: " + response.getMsg()); + } + } + } + ``` + + **Streaming Call** + + ```java theme={null} + import ai.z.openapi.ZaiClient; + import ai.z.openapi.service.model.ChatCompletionCreateParams; + import ai.z.openapi.service.model.ChatCompletionResponse; + import ai.z.openapi.service.model.ChatMessage; + import ai.z.openapi.service.model.ChatMessageRole; + import ai.z.openapi.service.model.ChatThinking; + import ai.z.openapi.service.model.Delta; + import java.util.Arrays; + + public class StreamingChat { + public static void main(String[] args) { + // Initialize client + ZaiClient client = ZaiClient.builder().ofZAI().apiKey("your-api-key").build(); + + // Create streaming chat completion request + ChatCompletionCreateParams request = + ChatCompletionCreateParams.builder() + .model("glm-4.7") + .messages( + Arrays.asList( + ChatMessage.builder() + .role(ChatMessageRole.USER.value()) + .content( + "As a marketing expert, please create an attractive slogan for my product.") + .build(), + ChatMessage.builder() + .role(ChatMessageRole.ASSISTANT.value()) + .content( + "Sure, to craft a compelling slogan, please tell me more about your product.") + .build(), + ChatMessage.builder() + .role(ChatMessageRole.USER.value()) + .content("Z.AI Open Platform") + .build())) + .thinking(ChatThinking.builder().type("enabled").build()) + .stream(true) // Enable streaming output + .maxTokens(4096) + .temperature(1.0f) + .build(); + + ChatCompletionResponse response = client.chat().createChatCompletion(request); + + if (response.isSuccess()) { + response.getFlowable() + .subscribe( + // Process streaming message data + data -> { + if (data.getChoices() != null && !data.getChoices().isEmpty()) { + Delta delta = data.getChoices().get(0).getDelta(); + System.out.print(delta + "\n"); + } + }, + // Process streaming response error + error -> System.err.println("\nStream error: " + error.getMessage()), + // Process streaming response completion event + () -> System.out.println("\nStreaming response completed")); + } else { + System.err.println("Error: " + response.getMsg()); + } + } + } + ``` + + + + **Install SDK** + + ```bash theme={null} + # Install or upgrade to latest version + pip install --upgrade 'openai>=1.0' + ``` + + **Verify Installation** + + ```python theme={null} + python -c "import openai; print(openai.__version__)" + ``` + + **Usage Example** + + ```python theme={null} + from openai import OpenAI + + client = OpenAI( + api_key="your-Z.AI-api-key", + base_url="https://api.z.ai/api/paas/v4/", + ) + + completion = client.chat.completions.create( + model="glm-4.7", + messages=[ + {"role": "system", "content": "You are a smart and creative novelist"}, + { + "role": "user", + "content": "Please write a short fairy tale story as a fairy tale master", + }, + ], + ) + + print(completion.choices[0].message.content) + ``` + + + + +--- + +> To find navigation and other pages in this documentation, fetch the llms.txt file at: https://docs.z.ai/llms.txt