fix(auxiliary): keep ZAI Coding Plan routing

This commit is contained in:
Xie
2026-08-03 09:40:43 +08:00
committed by Teknium
parent a0939901df
commit ddbef9cd79
2 changed files with 27 additions and 6 deletions
+11 -4
View File
@@ -1271,13 +1271,20 @@ def _to_openai_base_url(base_url: str) -> str:
Anthropic-**only** custom gateways (path ends in ``/anthropic`` but has no
sibling ``/v1``) must keep their path; rewriting them to ``/v1`` yields 404
on compression/vision/title_generation (#83642).
ZAI exposes its general API and Coding Plan on separate endpoints. Its
Anthropic-compatible Coding Plan endpoint maps to ``/api/coding/paas/v4``
on the OpenAI wire, not the general ``/api/paas/v4`` endpoint. Rewriting
to the general endpoint changes the billing pool and can return a false
insufficient-balance error for a valid Coding Plan key.
"""
url = str(base_url or "").strip().rstrip("/")
if url.endswith("/anthropic"):
# ZAI (open.bigmodel.cn) uses /api/anthropic for Anthropic wire
# but /api/paas/v4 for OpenAI wire — the generic /v1 rewrite is wrong.
if "open.bigmodel.cn" in url or "bigmodel" in url:
rewritten = url[: -len("/anthropic")] + "/paas/v4"
# 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:
rewritten = url[: -len("/anthropic")] + "/coding/paas/v4"
logger.debug("Auxiliary client: rewrote ZAI base URL %s → %s", url, rewritten)
return rewritten
if _is_dual_surface_anthropic_host(url):
+16 -2
View File
@@ -1,7 +1,9 @@
"""Tests for MiniMax auxiliary client URL normalization.
"""Tests for Anthropic-to-OpenAI auxiliary URL normalization.
MiniMax and MiniMax-CN set inference_base_url to the /anthropic path.
The auxiliary client uses the OpenAI SDK, which needs /v1 instead.
The auxiliary client uses the OpenAI SDK, which needs /v1 instead. ZAI's
Anthropic endpoint belongs to Coding Plan, whose OpenAI-compatible peer is the
separately billed /api/coding/paas/v4 endpoint.
"""
import sys
@@ -37,5 +39,17 @@ class TestToOpenaiBaseUrl:
url = "https://minimax.io.evil.example.com/anthropic"
assert _to_openai_base_url(url) == url
def test_zai_anthropic_routes_to_coding_plan_openai_endpoint(self):
assert (
_to_openai_base_url("https://api.z.ai/api/anthropic")
== "https://api.z.ai/api/coding/paas/v4"
)
def test_bigmodel_anthropic_routes_to_coding_plan_openai_endpoint(self):
assert (
_to_openai_base_url("https://open.bigmodel.cn/api/anthropic")
== "https://open.bigmodel.cn/api/coding/paas/v4"
)
def test_none(self):
assert _to_openai_base_url(None) == ""