The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): anchor ZAI/Kimi base_url host matching to avoid substring false positives
pierrenode2d9f116351ba
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.pyindex 39daa4deed9..0c8253d3e50 100644--- a/agent/auxiliary_client.py+++ b/agent/auxiliary_client.py@@ -1283,7 +1283,7 @@ def _to_openai_base_url(base_url: str) -> str:# ZAI uses /api/anthropic for the Coding Plan's Anthropic wire. The# matching OpenAI-wire endpoint is /api/coding/paas/v4; /api/paas/v4# is the independently billed general API.- if "open.bigmodel.cn" in url or "bigmodel" in url or "api.z.ai" in url:+ if base_url_host_matches(url, "open.bigmodel.cn") or base_url_host_matches(url, "api.z.ai"):rewritten = url[: -len("/anthropic")] + "/coding/paas/v4"logger.debug("Auxiliary client: rewrote ZAI base URL %s → %s", url, rewritten)return rewritten@@ -1297,7 +1297,7 @@ def _to_openai_base_url(base_url: str) -> str:url,)return url- if "api.kimi.com" in url and url.endswith("/coding"):+ if base_url_host_matches(url, "api.kimi.com") and url.endswith("/coding"):# Kimi Code uses /coding/v1/messages for Anthropic SDK (appends /v1/messages)# but /coding/v1/chat/completions for OpenAI SDK (appends /chat/completions)# Without /v1 here, OpenAI SDK hits /coding/chat/completions — a 404.diff --git a/tests/agent/test_minimax_auxiliary_url.py b/tests/agent/test_minimax_auxiliary_url.pyindex 0f07670c7cd..bfc41a00023 100644--- a/tests/agent/test_minimax_auxiliary_url.py+++ b/tests/agent/test_minimax_auxiliary_url.py@@ -51,5 +51,24 @@ class TestToOpenaiBaseUrl:== "https://open.bigmodel.cn/api/coding/paas/v4")+ def test_bigmodel_marker_in_path_does_not_false_positive(self):+ """Host-anchored matching: 'bigmodel' in the path must not trigger rewrite."""+ url = "https://gateway.example.com/proxy/bigmodel-fallback/anthropic"+ assert _to_openai_base_url(url) == url++ def test_zai_marker_in_path_does_not_false_positive(self):+ url = "https://gateway.example.com/api.z.ai-mirror/anthropic"+ assert _to_openai_base_url(url) == url++ def test_kimi_coding_host_rewritten(self):+ assert (+ _to_openai_base_url("https://api.kimi.com/coding")+ == "https://api.kimi.com/coding/v1"+ )++ def test_kimi_marker_in_path_does_not_false_positive(self):+ url = "https://gateway.example.com/some/api.kimi.com-proxy/coding"+ assert _to_openai_base_url(url) == url+def test_none(self):assert _to_openai_base_url(None) == ""