From 008ac655a9402bcef6c331eaf401698ada43300c Mon Sep 17 00:00:00 2001 From: Yijia-Xiao Date: Thu, 17 Sep 2026 07:31:44 +0000 Subject: [PATCH] fix(cli): send GLM traffic to the platform its key belongs to - the provider table named the China endpoint while the key mapping and client registry named Z.AI --- cli/utils.py | 4 +++- tests/test_cli_config_precedence.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cli/utils.py b/cli/utils.py index 534f9afa8..df16cbde8 100644 --- a/cli/utils.py +++ b/cli/utils.py @@ -362,7 +362,9 @@ def _llm_provider_table() -> list[tuple[str, str, str | None]]: ("xAI", "xai", "https://api.x.ai/v1"), ("DeepSeek", "deepseek", "https://api.deepseek.com"), ("Qwen", "qwen", "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"), - ("GLM", "glm", "https://open.bigmodel.cn/api/paas/v4/"), + # Z.AI international, the platform ZHIPU_API_KEY belongs to; the CN + # platform is the separate glm-cn key, chosen in the region prompt. + ("GLM", "glm", "https://api.z.ai/api/paas/v4/"), ("MiniMax", "minimax", "https://api.minimax.io/v1"), ("OpenRouter", "openrouter", "https://openrouter.ai/api/v1"), ("Mistral", "mistral", "https://api.mistral.ai/v1"), diff --git a/tests/test_cli_config_precedence.py b/tests/test_cli_config_precedence.py index b2f1f0cc8..e70cf90d0 100644 --- a/tests/test_cli_config_precedence.py +++ b/tests/test_cli_config_precedence.py @@ -67,3 +67,19 @@ def test_checkpoint_flag_overrides_env(flag): with mock.patch.object(m, "DEFAULT_CONFIG", patched): cfg = m._build_run_config(SELECTIONS, checkpoint=flag) assert cfg["checkpoint_enabled"] is flag + + +@pytest.mark.unit +def test_glm_resolves_to_the_endpoint_its_key_belongs_to(): + """The provider table, the client registry and the key mapping must name the + same platform: glm is Z.AI international (ZHIPU_API_KEY) and glm-cn is + BigModel China. A mismatch sends the key to the other platform and every + call fails auth.""" + from cli.utils import resolve_backend_url + from tradingagents.llm_clients.api_key_env import get_api_key_env + from tradingagents.llm_clients.openai_client import OPENAI_COMPATIBLE_PROVIDERS + + assert resolve_backend_url("glm", None, None) == OPENAI_COMPATIBLE_PROVIDERS["glm"].base_url + assert get_api_key_env("glm") == "ZHIPU_API_KEY" + assert "z.ai" in OPENAI_COMPATIBLE_PROVIDERS["glm"].base_url + assert "bigmodel.cn" in OPENAI_COMPATIBLE_PROVIDERS["glm-cn"].base_url