From 3eed019c497b5235efb4d67f5443f11ca781938b Mon Sep 17 00:00:00 2001 From: Jamie Pine Date: Tue, 24 Feb 2026 21:43:14 -0800 Subject: [PATCH 1/2] fix zai-coding-plan model routing to use zai/ prefix The Z.AI Coding Plan API expects model names with the 'zai/' prefix (e.g., 'zai/glm-5') rather than bare model names (e.g., 'glm-5'). Added remap_model_name_for_api() helper to handle provider-specific model name formatting. Applied to all OpenAI-compatible API call methods. --- src/llm/model.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/llm/model.rs b/src/llm/model.rs index c2a166dd0..f46d368ea 100644 --- a/src/llm/model.rs +++ b/src/llm/model.rs @@ -512,8 +512,9 @@ impl SpacebotModel { messages.extend(convert_messages_to_openai(&request.chat_history)); + let api_model_name = self.remap_model_name_for_api(); let mut body = serde_json::json!({ - "model": self.model_name, + "model": api_model_name, "messages": messages, }); @@ -616,8 +617,9 @@ impl SpacebotModel { let input = convert_messages_to_openai_responses(&request.chat_history); + let api_model_name = self.remap_model_name_for_api(); let mut body = serde_json::json!({ - "model": self.model_name, + "model": api_model_name, "input": input, }); @@ -819,6 +821,16 @@ impl SpacebotModel { parse_openai_response(response_body, provider_display_name) } + /// Remap model name for providers that require a different format in API calls. + fn remap_model_name_for_api(&self) -> String { + if self.provider == "zai-coding-plan" { + // Z.AI Coding Plan API expects "zai/glm-5" not "glm-5" + format!("zai/{}", self.model_name) + } else { + self.model_name.clone() + } + } + /// Generic OpenAI-compatible API call with optional bearer auth. async fn call_openai_compatible_with_optional_auth( &self, @@ -838,8 +850,9 @@ impl SpacebotModel { messages.extend(convert_messages_to_openai(&request.chat_history)); + let api_model_name = self.remap_model_name_for_api(); let mut body = serde_json::json!({ - "model": self.model_name, + "model": api_model_name, "messages": messages, }); From a15577cb716acd937fd2ded7095803df53f35c70 Mon Sep 17 00:00:00 2001 From: Jamie Pine <32987599+jamiepine@users.noreply.github.com> Date: Tue, 24 Feb 2026 21:51:09 -0800 Subject: [PATCH 2/2] Update src/llm/model.rs Co-authored-by: tembo[bot] <208362400+tembo[bot]@users.noreply.github.com> --- src/llm/model.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/llm/model.rs b/src/llm/model.rs index f46d368ea..4a08911cd 100644 --- a/src/llm/model.rs +++ b/src/llm/model.rs @@ -825,7 +825,8 @@ impl SpacebotModel { fn remap_model_name_for_api(&self) -> String { if self.provider == "zai-coding-plan" { // Z.AI Coding Plan API expects "zai/glm-5" not "glm-5" - format!("zai/{}", self.model_name) + let model_name = self.model_name.strip_prefix("zai/").unwrap_or(&self.model_name); + format!("zai/{model_name}") } else { self.model_name.clone() }