Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions agent/auxiliary_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions tests/agent/test_minimax_auxiliary_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,24 @@ def test_bigmodel_anthropic_routes_to_coding_plan_openai_endpoint(self):
== "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) == ""
Loading