Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: add Z.ai as an API provider (#14034)

Nilay27d7e24a010f
diff --git a/studio/backend/core/inference/provider_model_capabilities.py b/studio/backend/core/inference/provider_model_capabilities.py
index a4f8d75243b..7cb8e4e78e1 100644
--- a/studio/backend/core/inference/provider_model_capabilities.py
+++ b/studio/backend/core/inference/provider_model_capabilities.py
@@ -90,6 +90,7 @@ MODELS_DEV_PROVIDER_MAP = {
"cohere": "cohere",
"huggingface": "huggingface",
"alibaba": "qwen",
+ "zai": "zai",
"ollama-cloud": "ollama",
"lmstudio": "lmstudio",
}
diff --git a/studio/backend/core/inference/providers.py b/studio/backend/core/inference/providers.py
index f98fdc38812..dd4ef5902ad 100644
--- a/studio/backend/core/inference/providers.py
+++ b/studio/backend/core/inference/providers.py
@@ -280,6 +280,42 @@ PROVIDER_REGISTRY: dict[str, dict[str, Any]] = {
# is allowed"). Strip both so the server uses its required defaults.
"body_omit": ("temperature", "top_p"),
},
+ "zai": {
+ "display_name": "Z.ai",
+ "base_url": "https://api.z.ai/api/paas/v4",
+ "default_models": [
+ "glm-5.3",
+ "glm-5.3-flash",
+ "glm-5.3-flashx",
+ "glm-5.2",
+ "glm-4.7-flash",
+ "glm-4.5-flash",
+ "glm-4.6v-flash",
+ ],
+ "model_capabilities": {
+ "glm-5.3": {"vision": False},
+ "glm-5.3-flash": {"vision": True},
+ "glm-5.3-flashx": {"vision": True},
+ "glm-5.2": {"vision": False},
+ "glm-5.1": {"vision": False},
+ "glm-5": {"vision": False},
+ "glm-4.7": {"vision": False},
+ "glm-4.6": {"vision": False},
+ "glm-4.5": {"vision": False},
+ "glm-4.5-air": {"vision": False},
+ "glm-4.7-flash": {"vision": False},
+ "glm-4.5-flash": {"vision": False},
+ "glm-4.6v-flash": {"vision": True},
+ },
+ "supports_streaming": True,
+ "supports_vision": True,
+ "supports_tool_calling": True,
+ "studio_tools": True,
+ "auth_header": "Authorization",
+ "auth_prefix": "Bearer ",
+ "notes": "Z.ai API key. China mainland: use base URL https://open.bigmodel.cn/api/paas/v4",
+ "body_omit": ("presence_penalty",),
+ },
"qwen": {
"display_name": "Qwen",
"base_url": "https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py
index f2cd2d1d53e..932b2f16dc7 100644
--- a/studio/backend/routes/inference.py
+++ b/studio/backend/routes/inference.py
@@ -10092,15 +10092,16 @@ _TEXT_ONLY_PROVIDER_TYPES = frozenset({"cohere", "deepseek", "mistral"})
# Mixed catalogs require model-level vision capability; family flags do not
# identify which models accept images. Qwen has unrestricted text defaults;
-# its vision models use separate qwen-vl-* or Qwen2.5-VL IDs. Kimi is excluded
+# its vision models use separate qwen-vl-* or Qwen2.5-VL IDs. Z.ai lists text
+# GLMs beside the -v / flash vision ones. Kimi is excluded
# because its allowlist permits only multimodal kimi-k3/k2.5/k2.6.
# Single-endpoint types (custom, vllm, ollama, llamacpp, lmstudio) retain the
# registry default: no model catalog exists to check the configured endpoint.
-_MIXED_CATALOG_PROVIDER_TYPES = frozenset({"huggingface", "openrouter", "qwen", "qwencloud"})
+_MIXED_CATALOG_PROVIDER_TYPES = frozenset({"huggingface", "openrouter", "qwen", "qwencloud", "zai"})
# Mixed catalogs whose models.dev namespace answers vision per model.
# Mirrors CATALOG_VISION_PROVIDER_TYPES in external-providers.ts.
-_CATALOG_VISION_NAMESPACES = {"qwencloud": "qwen"}
+_CATALOG_VISION_NAMESPACES = {"qwencloud": "qwen", "zai": "zai"}
def _external_takes_mcp_images(
diff --git a/studio/backend/tests/test_zai_provider.py b/studio/backend/tests/test_zai_provider.py
new file mode 100644
index 00000000000..01483d4e889
--- /dev/null
+++ b/studio/backend/tests/test_zai_provider.py
@@ -0,0 +1,216 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import asyncio
+import json
+import threading
+from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
+
+import httpx
+
+from core.inference import external_provider as ep_mod
+from core.inference.providers import list_available_providers
+from models.inference import ChatCompletionRequest
+
+
+_SSE = (
+ 'data: {"choices":[{"index":0,"delta":{"role":"assistant","reasoning_content":"thinking it over"}}]}\n\n'
+ 'data: {"choices":[{"index":0,"delta":{"content":"hello"}}]}\n\n'
+ 'data: {"choices":[{"index":0,"delta":{},"finish_reason":"stop"}],'
+ '"usage":{"prompt_tokens":8,"completion_tokens":2,"total_tokens":10}}\n\n'
+ "data: [DONE]\n\n"
+).encode()
+_MODELS = b'{"object":"list","data":[{"id":"glm-5.3","object":"model"},{"id":"glm-4.7","object":"model"}]}'
+_NOT_FOUND = b'{"error":{"code":"404","message":"Not Found"}}'
+
+
+class _ZaiLikeServer(BaseHTTPRequestHandler):
+ protocol_version = "HTTP/1.1"
+ seen: list = []
+
+ def log_message(self, *args, **kwargs) -> None:
+ return
+
+ def _reply(self, status: int, content_type: str, raw: bytes) -> None:
+ self.send_response(status)
+ self.send_header("Content-Type", content_type)
+ self.send_header("Content-Length", str(len(raw)))
+ self.end_headers()
+ self.wfile.write(raw)
+
+ def do_GET(self) -> None:
+ self.seen.append((self.path, None))
+ if self.path.endswith("/models"):
+ self._reply(200, "application/json", _MODELS)
+ else:
+ self._reply(404, "application/json", _NOT_FOUND)
+
+ def do_POST(self) -> None:
+ length = int(self.headers.get("Content-Length") or 0)
+ body = json.loads(self.rfile.read(length) or b"{}")
+ self.seen.append((self.path, body))
+ if self.path.endswith("/chat/completions"):
+ self._reply(200, "text/event-stream", _SSE)
+ else:
+ self._reply(404, "application/json", _NOT_FOUND)
+
+
+def _against_the_server(make_call):
+ _ZaiLikeServer.seen = []
+ httpd = ThreadingHTTPServer(("127.0.0.1", 0), _ZaiLikeServer)
+ thread = threading.Thread(target = httpd.serve_forever, daemon = True)
+ thread.start()
+ loop = asyncio.new_event_loop()
+ previous = ep_mod._http_client
+ ep_mod._http_client = httpx.AsyncClient()
+ try:
+ result = loop.run_until_complete(
+ make_call(f"http://127.0.0.1:{httpd.server_address[1]}/api/paas/v4")
+ )
+ loop.run_until_complete(ep_mod._http_client.aclose())
+ finally:
+ ep_mod._http_client = previous
+ loop.close()
+ httpd.shutdown()
+ httpd.server_close()
+ thread.join(timeout = 10)
+ return result, _ZaiLikeServer.seen
+
+
+async def _chat_through_the_route(base_url: str) -> str:
+ import routes.inference as ri
+ from starlette.requests import Request
+
+ async def receive() -> dict:
+ return {"type": "http.disconnect"}
+
+ payload = ChatCompletionRequest(
+ provider_type = "zai",
+ provider_base_url = base_url,
+ messages = [{"role": "user", "content": "hi"}],
+ model = "glm-5.3",
+ stream = True,
+ presence_penalty = 0.5,
+ temperature = 0.6,
+ )
+ request = Request(
+ {
+ "type": "http",
+ "http_version": "1.1",
+ "method": "POST",
+ "path": "/v1/chat/completions",
+ "raw_path": b"/v1/chat/completions",
+ "root_path": "",
+ "scheme": "http",
+ "query_string": b"",
+ "headers": [(b"content-type", b"application/json")],
+ "client": ("127.0.0.1", 12345),
+ "server": ("127.0.0.1", 8000),
+ },
+ receive,
+ )
+ response = await ri._proxy_to_external_provider(payload, request)
+ streamed = []
+ async for chunk in response.body_iterator:
+ streamed.append(chunk if isinstance(chunk, str) else chunk.decode())
+ return "".join(streamed)
+
+
+async def _check_and_list_models(base_url: str):
+ import routes.providers as providers_route
+ from models.providers import ProviderModelsRequest, ProviderTestRequest
+
+ check = await providers_route.test_provider(
+ ProviderTestRequest(provider_type = "zai", base_url = base_url),
+ _current_subject = "unsloth",
+ via_api_key = False,
+ )
+ models = await providers_route.list_provider_models(
+ ProviderModelsRequest(provider_type = "zai", base_url = base_url),
+ _current_subject = "unsloth",
+ via_api_key = False,
+ )
+ return check, [m.id for m in models]
+
+
+def test_zai_is_offered_on_the_pay_as_you_go_api():
+ zai = next(e for e in list_available_providers() if e["provider_type"] == "zai")
+ assert zai["base_url"] == "https://api.z.ai/api/paas/v4"
+ assert not zai["hidden"]
+ assert zai["model_list_mode"] == "remote"
+ for free_model in ("glm-4.7-flash", "glm-4.5-flash", "glm-4.6v-flash"):
+ assert free_model in zai["default_models"]
+ vision = {m: c["vision"] for m, c in zai["model_capabilities"].items()}
+ assert vision["glm-5.3"] is False and vision["glm-4.5-flash"] is False
+ assert vision["glm-5.3-flash"] is True and vision["glm-4.6v-flash"] is True
+
+
+def test_zai_chat_reaches_the_api_and_streams_reasoning_and_usage_back():
+ streamed, seen = _against_the_server(_chat_through_the_route)
+ [(path, body)] = seen
+ assert path == "/api/paas/v4/chat/completions"
+ assert body["model"] == "glm-5.3"
+ assert body["temperature"] == 0.6
+ assert "presence_penalty" not in body
+ chunks = [
+ json.loads(line[len("data: ") :])
+ for line in streamed.splitlines()
+ if line.startswith("data: {")
+ ]
+ deltas = [c["choices"][0]["delta"] for c in chunks if c.get("choices")]
+ assert "thinking it over" in "".join(d.get("reasoning_content") or "" for d in deltas)
+ assert "hello" in "".join(d.get("content") or "" for d in deltas)
+ assert any((c.get("usage") or {}).get("completion_tokens") == 2 for c in chunks)
+
+
+def test_zai_check_and_model_list_read_the_live_models_route():
+ (check, model_ids), seen = _against_the_server(_check_and_list_models)
+ assert check.success is True, check.message
+ assert model_ids == ["glm-5.3", "glm-4.7"]
+ assert [path for path, _ in seen] == ["/api/paas/v4/models", "/api/paas/v4/models"]
+
+
+def test_zai_models_get_their_window_and_modalities_from_the_catalog():
+ from core.inference.provider_model_capabilities import trim_models_dev_catalog
+
+ catalog = trim_models_dev_catalog(
+ {
+ "zai": {
+ "models": {
+ "glm-4.7-flashx": {
+ "modalities": {"input": ["text"]},
+ "limit": {"context": 200000},
+ },
+ "glm-5v-turbo": {
+ "modalities": {"input": ["text", "image"]},
+ "limit": {"context": 200000},
+ },
+ }
+ }
+ }
+ )
+ assert catalog["zai"]["glm-4.7-flashx"] == {"input": ["text"], "context": 200000}
+ assert catalog["zai"]["glm-5v-turbo"]["input"] == ["text", "image"]
+
+
+def test_zai_mcp_pictures_reach_only_its_vision_models(monkeypatch):
+ import routes.providers as providers_route
+ from core.inference.providers import get_provider_info
+ from routes.inference import _external_takes_mcp_images
+
+ info = get_provider_info("zai")
+ catalog = {
+ "fetched_at": 0,
+ "providers": {
+ "zai": {
+ "glm-5v-turbo": {"input": ["text", "image"]},
+ "glm-4.7-flashx": {"input": ["text"]},
+ }
+ },
+ }
+ monkeypatch.setattr(providers_route, "_model_catalog_cache", catalog)
+ assert _external_takes_mcp_images("zai", True, "glm-4.6v-flash", info) is True
+ assert _external_takes_mcp_images("zai", True, "glm-5.3", info) is False
+ assert _external_takes_mcp_images("zai", True, "glm-5v-turbo", info) is True
+ assert _external_takes_mcp_images("zai", True, "glm-4.7-flashx", info) is False
+ assert _external_takes_mcp_images("zai", True, "glm-unlisted", info) is False
diff --git a/studio/frontend/scripts/check-bundle-budget.ts b/studio/frontend/scripts/check-bundle-budget.ts
index 7bc4734b1f2..90ff4a053b4 100644
--- a/studio/frontend/scripts/check-bundle-budget.ts
+++ b/studio/frontend/scripts/check-bundle-budget.ts
@@ -204,8 +204,12 @@ export const BUDGET = {
// 2,047,569 B transfer against ca3d1d0ce4, one machine and build, Node 24, chunk count unchanged at 95): its
// connection row, logo mapping and capability entries live in tables the startup chunks already load. Raised
// by that growth.
- transferBytes: 2_047_520,
- rawBytes: 6_806_014,
+ // Z.ai as a connection (#14034) adds 73 B raw / 29 B transfer (6,804,389 -> 6,804,462 B raw, 2,047,551 ->
+ // 2,047,580 B transfer against f172c8d7c4, one machine and build, Node 24, chunk count unchanged at 95): its
+ // logo mapping, capability row and vision gate entries live in tables the startup chunks already load. Raised
+ // by that growth.
+ transferBytes: 2_047_549,
+ rawBytes: 6_806_087,
};
// The chunk count is reported but not budgeted. Splitting a page out of the entry raises it while lowering the
diff --git a/studio/frontend/scripts/refresh-model-catalog-snapshot.mjs b/studio/frontend/scripts/refresh-model-catalog-snapshot.mjs
index e856ede39b6..b710998711d 100644
--- a/studio/frontend/scripts/refresh-model-catalog-snapshot.mjs
+++ b/studio/frontend/scripts/refresh-model-catalog-snapshot.mjs
@@ -25,6 +25,7 @@ const PROVIDER_MAP = {
cohere: "cohere",
huggingface: "huggingface",
alibaba: "qwen",
+ zai: "zai",
"ollama-cloud": "ollama",
lmstudio: "lmstudio",
};
diff --git a/studio/frontend/src/features/chat/external-providers.ts b/studio/frontend/src/features/chat/external-providers.ts
index c30a937bb68..7cdcb9e65dd 100644
--- a/studio/frontend/src/features/chat/external-providers.ts
+++ b/studio/frontend/src/features/chat/external-providers.ts
@@ -282,9 +282,9 @@ export function providerModelSupportsVision(
// Mirrors _MIXED_CATALOG_PROVIDER_TYPES in studio/backend/routes/inference.py: vision for
// the family, unknown for a given model, so an MCP picture is not sent to one the
// registry says nothing about.
-const MIXED_CATALOG_PROVIDER_TYPES = new Set(["huggingface", "openrouter", "qwen", "qwencloud"]);
+const MIXED_CATALOG_PROVIDER_TYPES = new Set(["huggingface", "openrouter", "qwen", "qwencloud", "zai"]);
// Mirrors _CATALOG_VISION_NAMESPACES: mixed catalogs whose model catalog answers vision per model.
-const CATALOG_VISION_PROVIDER_TYPES = new Set(["qwencloud"]);
+const CATALOG_VISION_PROVIDER_TYPES = new Set(["qwencloud", "zai"]);
/** Whether the backend's external tool loop will hand this model an MCP picture -- the
* same rule as its _external_takes_mcp_images, so envelopes the backend would strip
diff --git a/studio/frontend/src/features/chat/provider-capabilities.ts b/studio/frontend/src/features/chat/provider-capabilities.ts
index c3c6f3e07d3..998d9b07159 100644
--- a/studio/frontend/src/features/chat/provider-capabilities.ts
+++ b/studio/frontend/src/features/chat/provider-capabilities.ts
@@ -754,6 +754,7 @@ const PROVIDER_CAPABILITIES: Record<string, ProviderCapabilities> = {
presencePenalty: false,
},
qwen: OPENAI_COMPAT_BASE,
+ zai: { ...OPENAI_COMPAT_BASE, presencePenalty: false },
huggingface: OPENAI_COMPAT_BASE,
// OpenRouter silently drops unsupported params, so surface every knob and let the gateway
// fan out per model.
diff --git a/studio/frontend/src/features/chat/provider-logo-path.ts b/studio/frontend/src/features/chat/provider-logo-path.ts
index f8a9a3b4fc6..53ce0792a70 100644
--- a/studio/frontend/src/features/chat/provider-logo-path.ts
+++ b/studio/frontend/src/features/chat/provider-logo-path.ts
@@ -13,6 +13,7 @@ const HUB_PROVIDER_IDS = new Map([
["kimi", "moonshotai"],
["qwen", "qwen"],
["qwencloud", "qwen"],
+ ["zai", "zai-org"],
]);
const HUB_LOGO_PATHS = new Map(
diff --git a/studio/frontend/tests/mcp-images.test.ts b/studio/frontend/tests/mcp-images.test.ts
index 8bf5381a321..a55c885502e 100644
--- a/studio/frontend/tests/mcp-images.test.ts
+++ b/studio/frontend/tests/mcp-images.test.ts
@@ -441,6 +441,7 @@ test("the upload gate is the backend's external MCP gate, not provider-level vis
assert.equal(providerModelTakesMcpImages("qwencloud", "qwen3-vl-plus"), true);
assert.equal(providerModelTakesMcpImages("qwencloud", "qwen3.7-max"), false);
assert.equal(providerModelTakesMcpImages("qwencloud", "glm-5.3"), false);
+ assert.equal(providerModelTakesMcpImages("zai", "glm-4.7-flashx"), false);
// Known text-only endpoints stay a no; a vision family with a plain catalog is a yes.
assert.equal(providerModelTakesMcpImages("mistral", "mistral-large"), false);
assert.equal(providerModelTakesMcpImages("anthropic", "claude-x"), true);
diff --git a/studio/frontend/tests/provider-logo-path.test.ts b/studio/frontend/tests/provider-logo-path.test.ts
index 397b2be4af5..8fe5dc11378 100644
--- a/studio/frontend/tests/provider-logo-path.test.ts
+++ b/studio/frontend/tests/provider-logo-path.test.ts
@@ -20,6 +20,7 @@ test("connections use the model hub's canonical provider images", () => {
["kimi", "moonshotai"],
["qwen", "qwen"],
["qwencloud", "qwen"],
+ ["zai", "zai-org"],
]) {
const hubLogo = PROVIDER_LOGOS.find(({ id }) => id === hubId);
assert.ok(hubLogo, hubId);
@@ -39,7 +40,7 @@ test("every supported connection resolves to an existing public asset", () => {
for (const type of [
"openai", "openai_codex", "deepseek", "mistral", "huggingface", "kimi",
"qwen", "qwencloud", "gemini", "anthropic", "openrouter", "vllm", "ollama", "llama_cpp",
- "liquid", "typesafe",
+ "liquid", "typesafe", "zai",
]) {
const path = providerLogoPath(type);
assert.ok(path?.startsWith("/"), type);