Skip to content

Commit 843b983

Browse files
committed
feat: add z.ai provider with GLM models (coding endpoint)
- New provider: Z.ai with 11 GLM models (GLM-5, GLM-4.7 series, GLM-4.6, GLM-4.5 series, GLM-4-32B) - Uses coding-specific endpoint: api.z.ai/api/coding/paas/v4 - OpenAI-compatible, no new dependencies needed - Configurable base URL via ZAI_API_BASE_URL env var - Updated provider count from 19 to 20 in README and docs
1 parent 52ab659 commit 843b983

6 files changed

Lines changed: 137 additions & 4 deletions

File tree

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ XAI_API_KEY=your_xai_api_key_here
5959
# Get your API key from: https://platform.moonshot.ai/console/api-keys
6060
MOONSHOT_API_KEY=your_moonshot_api_key_here
6161

62+
# Z.ai (GLM models — coding endpoint)
63+
# Get your API key from: https://z.ai/manage-apikey/apikey-list
64+
ZAI_API_KEY=your_zai_api_key_here
65+
# ZAI_API_BASE_URL=https://api.z.ai/api/coding/paas/v4 # default; change to https://api.z.ai/api/paas/v4 for general use
66+
6267
# Hugging Face
6368
# Get your API key from: https://huggingface.co/settings/tokens
6469
HuggingFace_API_KEY=your_huggingface_api_key_here

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pnpm run dev
3939

4040
## Why Devonz?
4141

42-
- **19 AI providers** — OpenAI, Anthropic, Google, Groq, Ollama, and 14 more. Swap models mid-conversation.
42+
- **20 AI providers** — OpenAI, Anthropic, Google, Groq, Z.ai, Ollama, and more. Swap models mid-conversation.
4343
- **Full dev environment in the browser** — editor, terminal, live preview, all powered by WebContainers.
4444
- **One-click deploy** — push to GitHub, GitLab, Netlify, or Vercel directly from the UI.
4545
- **MCP tools** — extend the agent with Model Context Protocol servers for specialized workflows.
@@ -65,7 +65,7 @@ pnpm run dev
6565

6666
**AI & Code Generation**
6767
- Natural language to full-stack apps (Node.js-based)
68-
- 19 LLM providers with hot-swappable model selection
68+
- 20 LLM providers with hot-swappable model selection
6969
- MCP (Model Context Protocol) tool integration
7070
- Automatic error detection and auto-fix from terminal output
7171
- Attach images to prompts for visual context
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import { BaseProvider } from '~/lib/modules/llm/base-provider';
2+
import type { ModelInfo } from '~/lib/modules/llm/types';
3+
import type { IProviderSetting } from '~/types/model';
4+
import type { LanguageModelV1 } from 'ai';
5+
import { createOpenAI } from '@ai-sdk/openai';
6+
7+
export default class ZaiProvider extends BaseProvider {
8+
name = 'Z.ai';
9+
getApiKeyLink = 'https://z.ai/manage-apikey/apikey-list';
10+
labelForGetApiKey = 'Get Z.ai API Key';
11+
icon = 'i-ph:brain';
12+
13+
config = {
14+
apiTokenKey: 'ZAI_API_KEY',
15+
baseUrlKey: 'ZAI_API_BASE_URL',
16+
};
17+
18+
staticModels: ModelInfo[] = [
19+
{
20+
name: 'glm-5',
21+
label: 'GLM-5',
22+
provider: 'Z.ai',
23+
maxTokenAllowed: 131072,
24+
maxCompletionTokens: 131072,
25+
},
26+
{
27+
name: 'glm-4.7',
28+
label: 'GLM-4.7',
29+
provider: 'Z.ai',
30+
maxTokenAllowed: 131072,
31+
maxCompletionTokens: 131072,
32+
},
33+
{
34+
name: 'glm-4.7-flash',
35+
label: 'GLM-4.7 Flash',
36+
provider: 'Z.ai',
37+
maxTokenAllowed: 131072,
38+
maxCompletionTokens: 131072,
39+
},
40+
{
41+
name: 'glm-4.7-flashx',
42+
label: 'GLM-4.7 FlashX',
43+
provider: 'Z.ai',
44+
maxTokenAllowed: 131072,
45+
maxCompletionTokens: 131072,
46+
},
47+
{
48+
name: 'glm-4.6',
49+
label: 'GLM-4.6',
50+
provider: 'Z.ai',
51+
maxTokenAllowed: 131072,
52+
maxCompletionTokens: 131072,
53+
},
54+
{
55+
name: 'glm-4.5',
56+
label: 'GLM-4.5',
57+
provider: 'Z.ai',
58+
maxTokenAllowed: 98304,
59+
maxCompletionTokens: 98304,
60+
},
61+
{
62+
name: 'glm-4.5-air',
63+
label: 'GLM-4.5 Air',
64+
provider: 'Z.ai',
65+
maxTokenAllowed: 98304,
66+
maxCompletionTokens: 98304,
67+
},
68+
{
69+
name: 'glm-4.5-x',
70+
label: 'GLM-4.5 X',
71+
provider: 'Z.ai',
72+
maxTokenAllowed: 98304,
73+
maxCompletionTokens: 98304,
74+
},
75+
{
76+
name: 'glm-4.5-airx',
77+
label: 'GLM-4.5 AirX',
78+
provider: 'Z.ai',
79+
maxTokenAllowed: 98304,
80+
maxCompletionTokens: 98304,
81+
},
82+
{
83+
name: 'glm-4.5-flash',
84+
label: 'GLM-4.5 Flash',
85+
provider: 'Z.ai',
86+
maxTokenAllowed: 98304,
87+
maxCompletionTokens: 98304,
88+
},
89+
{
90+
name: 'glm-4-32b-0414-128k',
91+
label: 'GLM-4 32B 128K',
92+
provider: 'Z.ai',
93+
maxTokenAllowed: 131072,
94+
maxCompletionTokens: 16384,
95+
},
96+
];
97+
98+
getModelInstance(options: {
99+
model: string;
100+
serverEnv: Env;
101+
apiKeys?: Record<string, string>;
102+
providerSettings?: Record<string, IProviderSetting>;
103+
}): LanguageModelV1 {
104+
const { model, serverEnv, apiKeys, providerSettings } = options;
105+
106+
const { baseUrl, apiKey } = this.getProviderBaseUrlAndKey({
107+
apiKeys,
108+
providerSettings: providerSettings?.[this.name],
109+
serverEnv,
110+
defaultBaseUrlKey: 'ZAI_API_BASE_URL',
111+
defaultApiTokenKey: 'ZAI_API_KEY',
112+
});
113+
114+
if (!apiKey) {
115+
throw new Error(`Missing API key for ${this.name} provider`);
116+
}
117+
118+
const openai = createOpenAI({
119+
baseURL: baseUrl || 'https://api.z.ai/api/coding/paas/v4',
120+
apiKey,
121+
});
122+
123+
return openai(model);
124+
}
125+
}

app/lib/modules/llm/registry.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import HyperbolicProvider from './providers/hyperbolic';
1717
import AmazonBedrockProvider from './providers/amazon-bedrock';
1818
import GithubProvider from './providers/github';
1919
import MoonshotProvider from './providers/moonshot';
20+
import ZaiProvider from './providers/zai';
2021

2122
export {
2223
AnthropicProvider,
@@ -38,4 +39,5 @@ export {
3839
LMStudioProvider,
3940
AmazonBedrockProvider,
4041
GithubProvider,
42+
ZaiProvider,
4143
};

docs/LLM-PROVIDERS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## Overview
88

9-
Devonz supports **19 LLM providers** through a pluggable provider system built on the [Vercel AI SDK](https://sdk.vercel.ai/). Each provider is a self-contained class that extends `BaseProvider`.
9+
Devonz supports **20 LLM providers** through a pluggable provider system built on the [Vercel AI SDK](https://sdk.vercel.ai/). Each provider is a self-contained class that extends `BaseProvider`.
1010

1111
---
1212

@@ -32,6 +32,7 @@ Devonz supports **19 LLM providers** through a pluggable provider system built o
3232
| Hyperbolic | `HYPERBOLIC_API_KEY` | No | Hyperbolic inference |
3333
| Ollama | `OLLAMA_API_BASE_URL` | Yes | Local models (no API key) |
3434
| LM Studio | `LMSTUDIO_API_BASE_URL` | Yes | Local models (no API key) |
35+
| Z.ai | `ZAI_API_KEY` | No | GLM models (coding endpoint) |
3536
| OpenAI-Like | `OPENAI_LIKE_API_BASE_URL` | No | Any OpenAI-compatible API |
3637

3738
---

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
| Language | TypeScript (strict) |
3131
| Styling | UnoCSS + SCSS + Radix UI |
3232
| State | Nanostores |
33-
| AI/LLM | Vercel AI SDK v4.3 (19 providers) |
33+
| AI/LLM | Vercel AI SDK v4.3 (20 providers) |
3434
| Editor | CodeMirror 6 |
3535
| Terminal | xterm.js 5.5 |
3636
| Runtime | WebContainer API |

0 commit comments

Comments
 (0)