Skip to content

Commit 34392dd

Browse files
Z.ai: add GLM-4.5-X, AirX, Flash (expand model coverage) (#8745)
* feat(zai): add GLM-4.5-X, AirX, Flash; sync with Z.ai docs; keep canonical api line keys * feat(zai): add GLM-4.5V vision model (supportsImages, pricing, 16K max output); add tests * feat(types,zai): sync Z.AI international model map and tests - Update pricing, context window, and capabilities for: glm-4.5-x, glm-4.5-airx, glm-4.5-flash, glm-4.5v, glm-4.6 - Add glm-4-32b-0414-128k - Align tests with new model specs * fix(zai): align handler generics with expanded model ids to satisfy CI compile step * chore(zai): remove tier pricing blocks for Z.ai models * fix(zai): simplify names in zaiApiLineConfigs for clarity * chore(zai): set default temperature to 0.6 --------- Co-authored-by: Roo Code <[email protected]>
1 parent 6ffdd44 commit 34392dd

File tree

3 files changed

+147
-76
lines changed

3 files changed

+147
-76
lines changed

packages/types/src/providers/zai.ts

Lines changed: 112 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import type { ModelInfo } from "../model.js"
22
import { ZaiApiLine } from "../provider-settings.js"
33

44
// Z AI
5+
// https://docs.z.ai/guides/llm/glm-4-32b-0414-128k
56
// https://docs.z.ai/guides/llm/glm-4.5
7+
// https://docs.z.ai/guides/llm/glm-4.6
68
// https://docs.z.ai/guides/overview/pricing
9+
// https://bigmodel.cn/pricing
710

811
export type InternationalZAiModelId = keyof typeof internationalZAiModels
9-
export const internationalZAiDefaultModelId: InternationalZAiModelId = "glm-4.5"
12+
export const internationalZAiDefaultModelId: InternationalZAiModelId = "glm-4.6"
1013
export const internationalZAiModels = {
1114
"glm-4.5": {
1215
maxTokens: 98_304,
@@ -32,9 +35,55 @@ export const internationalZAiModels = {
3235
description:
3336
"GLM-4.5-Air is the lightweight version of GLM-4.5. It balances performance and cost-effectiveness, and can flexibly switch to hybrid thinking models.",
3437
},
38+
"glm-4.5-x": {
39+
maxTokens: 98_304,
40+
contextWindow: 131_072,
41+
supportsImages: false,
42+
supportsPromptCache: true,
43+
inputPrice: 2.2,
44+
outputPrice: 8.9,
45+
cacheWritesPrice: 0,
46+
cacheReadsPrice: 0.45,
47+
description:
48+
"GLM-4.5-X is a high-performance variant optimized for strong reasoning with ultra-fast responses.",
49+
},
50+
"glm-4.5-airx": {
51+
maxTokens: 98_304,
52+
contextWindow: 131_072,
53+
supportsImages: false,
54+
supportsPromptCache: true,
55+
inputPrice: 1.1,
56+
outputPrice: 4.5,
57+
cacheWritesPrice: 0,
58+
cacheReadsPrice: 0.22,
59+
description: "GLM-4.5-AirX is a lightweight, ultra-fast variant delivering strong performance with lower cost.",
60+
},
61+
"glm-4.5-flash": {
62+
maxTokens: 98_304,
63+
contextWindow: 131_072,
64+
supportsImages: false,
65+
supportsPromptCache: true,
66+
inputPrice: 0,
67+
outputPrice: 0,
68+
cacheWritesPrice: 0,
69+
cacheReadsPrice: 0,
70+
description: "GLM-4.5-Flash is a free, high-speed model excellent for reasoning, coding, and agentic tasks.",
71+
},
72+
"glm-4.5v": {
73+
maxTokens: 16_384,
74+
contextWindow: 131_072,
75+
supportsImages: true,
76+
supportsPromptCache: true,
77+
inputPrice: 0.6,
78+
outputPrice: 1.8,
79+
cacheWritesPrice: 0,
80+
cacheReadsPrice: 0.11,
81+
description:
82+
"GLM-4.5V is Z.AI's multimodal visual reasoning model (image/video/text/file input), optimized for GUI tasks, grounding, and document/video understanding.",
83+
},
3584
"glm-4.6": {
3685
maxTokens: 98_304,
37-
contextWindow: 204_800,
86+
contextWindow: 200_000,
3887
supportsImages: false,
3988
supportsPromptCache: true,
4089
inputPrice: 0.6,
@@ -44,10 +93,21 @@ export const internationalZAiModels = {
4493
description:
4594
"GLM-4.6 is Zhipu's newest model with an extended context window of up to 200k tokens, providing enhanced capabilities for processing longer documents and conversations.",
4695
},
96+
"glm-4-32b-0414-128k": {
97+
maxTokens: 98_304,
98+
contextWindow: 131_072,
99+
supportsImages: false,
100+
supportsPromptCache: false,
101+
inputPrice: 0.1,
102+
outputPrice: 0.1,
103+
cacheWritesPrice: 0,
104+
cacheReadsPrice: 0,
105+
description: "GLM-4-32B is a 32 billion parameter model with 128k context length, optimized for efficiency.",
106+
},
47107
} as const satisfies Record<string, ModelInfo>
48108

49109
export type MainlandZAiModelId = keyof typeof mainlandZAiModels
50-
export const mainlandZAiDefaultModelId: MainlandZAiModelId = "glm-4.5"
110+
export const mainlandZAiDefaultModelId: MainlandZAiModelId = "glm-4.6"
51111
export const mainlandZAiModels = {
52112
"glm-4.5": {
53113
maxTokens: 98_304,
@@ -60,26 +120,6 @@ export const mainlandZAiModels = {
60120
cacheReadsPrice: 0.057,
61121
description:
62122
"GLM-4.5 is Zhipu's latest featured model. Its comprehensive capabilities in reasoning, coding, and agent reach the state-of-the-art (SOTA) level among open-source models, with a context length of up to 128k.",
63-
tiers: [
64-
{
65-
contextWindow: 32_000,
66-
inputPrice: 0.21,
67-
outputPrice: 1.0,
68-
cacheReadsPrice: 0.043,
69-
},
70-
{
71-
contextWindow: 128_000,
72-
inputPrice: 0.29,
73-
outputPrice: 1.14,
74-
cacheReadsPrice: 0.057,
75-
},
76-
{
77-
contextWindow: Infinity,
78-
inputPrice: 0.29,
79-
outputPrice: 1.14,
80-
cacheReadsPrice: 0.057,
81-
},
82-
],
83123
},
84124
"glm-4.5-air": {
85125
maxTokens: 98_304,
@@ -92,26 +132,52 @@ export const mainlandZAiModels = {
92132
cacheReadsPrice: 0.02,
93133
description:
94134
"GLM-4.5-Air is the lightweight version of GLM-4.5. It balances performance and cost-effectiveness, and can flexibly switch to hybrid thinking models.",
95-
tiers: [
96-
{
97-
contextWindow: 32_000,
98-
inputPrice: 0.07,
99-
outputPrice: 0.4,
100-
cacheReadsPrice: 0.014,
101-
},
102-
{
103-
contextWindow: 128_000,
104-
inputPrice: 0.1,
105-
outputPrice: 0.6,
106-
cacheReadsPrice: 0.02,
107-
},
108-
{
109-
contextWindow: Infinity,
110-
inputPrice: 0.1,
111-
outputPrice: 0.6,
112-
cacheReadsPrice: 0.02,
113-
},
114-
],
135+
},
136+
"glm-4.5-x": {
137+
maxTokens: 98_304,
138+
contextWindow: 131_072,
139+
supportsImages: false,
140+
supportsPromptCache: true,
141+
inputPrice: 0.29,
142+
outputPrice: 1.14,
143+
cacheWritesPrice: 0,
144+
cacheReadsPrice: 0.057,
145+
description:
146+
"GLM-4.5-X is a high-performance variant optimized for strong reasoning with ultra-fast responses.",
147+
},
148+
"glm-4.5-airx": {
149+
maxTokens: 98_304,
150+
contextWindow: 131_072,
151+
supportsImages: false,
152+
supportsPromptCache: true,
153+
inputPrice: 0.1,
154+
outputPrice: 0.6,
155+
cacheWritesPrice: 0,
156+
cacheReadsPrice: 0.02,
157+
description: "GLM-4.5-AirX is a lightweight, ultra-fast variant delivering strong performance with lower cost.",
158+
},
159+
"glm-4.5-flash": {
160+
maxTokens: 98_304,
161+
contextWindow: 131_072,
162+
supportsImages: false,
163+
supportsPromptCache: true,
164+
inputPrice: 0,
165+
outputPrice: 0,
166+
cacheWritesPrice: 0,
167+
cacheReadsPrice: 0,
168+
description: "GLM-4.5-Flash is a free, high-speed model excellent for reasoning, coding, and agentic tasks.",
169+
},
170+
"glm-4.5v": {
171+
maxTokens: 16_384,
172+
contextWindow: 131_072,
173+
supportsImages: true,
174+
supportsPromptCache: true,
175+
inputPrice: 0.29,
176+
outputPrice: 0.93,
177+
cacheWritesPrice: 0,
178+
cacheReadsPrice: 0.057,
179+
description:
180+
"GLM-4.5V is Z.AI's multimodal visual reasoning model (image/video/text/file input), optimized for GUI tasks, grounding, and document/video understanding.",
115181
},
116182
"glm-4.6": {
117183
maxTokens: 98_304,
@@ -124,45 +190,19 @@ export const mainlandZAiModels = {
124190
cacheReadsPrice: 0.057,
125191
description:
126192
"GLM-4.6 is Zhipu's newest model with an extended context window of up to 200k tokens, providing enhanced capabilities for processing longer documents and conversations.",
127-
tiers: [
128-
{
129-
contextWindow: 32_000,
130-
inputPrice: 0.21,
131-
outputPrice: 1.0,
132-
cacheReadsPrice: 0.043,
133-
},
134-
{
135-
contextWindow: 128_000,
136-
inputPrice: 0.29,
137-
outputPrice: 1.14,
138-
cacheReadsPrice: 0.057,
139-
},
140-
{
141-
contextWindow: 200_000,
142-
inputPrice: 0.29,
143-
outputPrice: 1.14,
144-
cacheReadsPrice: 0.057,
145-
},
146-
{
147-
contextWindow: Infinity,
148-
inputPrice: 0.29,
149-
outputPrice: 1.14,
150-
cacheReadsPrice: 0.057,
151-
},
152-
],
153193
},
154194
} as const satisfies Record<string, ModelInfo>
155195

156-
export const ZAI_DEFAULT_TEMPERATURE = 0
196+
export const ZAI_DEFAULT_TEMPERATURE = 0.6
157197

158198
export const zaiApiLineConfigs = {
159199
international_coding: {
160-
name: "International Coding Plan",
200+
name: "International",
161201
baseUrl: "https://api.z.ai/api/coding/paas/v4",
162202
isChina: false,
163203
},
164204
china_coding: {
165-
name: "China Coding Plan",
205+
name: "China",
166206
baseUrl: "https://open.bigmodel.cn/api/coding/paas/v4",
167207
isChina: true,
168208
},

src/api/providers/__tests__/zai.spec.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,22 @@ describe("ZAiHandler", () => {
8282
const model = handlerWithModel.getModel()
8383
expect(model.id).toBe(testModelId)
8484
expect(model.info).toEqual(internationalZAiModels[testModelId])
85-
expect(model.info.contextWindow).toBe(204_800)
85+
expect(model.info.contextWindow).toBe(200_000)
86+
})
87+
88+
it("should return GLM-4.5v international model with vision support", () => {
89+
const testModelId: InternationalZAiModelId = "glm-4.5v"
90+
const handlerWithModel = new ZAiHandler({
91+
apiModelId: testModelId,
92+
zaiApiKey: "test-zai-api-key",
93+
zaiApiLine: "international_coding",
94+
})
95+
const model = handlerWithModel.getModel()
96+
expect(model.id).toBe(testModelId)
97+
expect(model.info).toEqual(internationalZAiModels[testModelId])
98+
expect(model.info.supportsImages).toBe(true)
99+
expect(model.info.maxTokens).toBe(16_384)
100+
expect(model.info.contextWindow).toBe(131_072)
86101
})
87102
})
88103

@@ -134,6 +149,21 @@ describe("ZAiHandler", () => {
134149
expect(model.info).toEqual(mainlandZAiModels[testModelId])
135150
expect(model.info.contextWindow).toBe(204_800)
136151
})
152+
153+
it("should return GLM-4.5v China model with vision support", () => {
154+
const testModelId: MainlandZAiModelId = "glm-4.5v"
155+
const handlerWithModel = new ZAiHandler({
156+
apiModelId: testModelId,
157+
zaiApiKey: "test-zai-api-key",
158+
zaiApiLine: "china_coding",
159+
})
160+
const model = handlerWithModel.getModel()
161+
expect(model.id).toBe(testModelId)
162+
expect(model.info).toEqual(mainlandZAiModels[testModelId])
163+
expect(model.info.supportsImages).toBe(true)
164+
expect(model.info.maxTokens).toBe(16_384)
165+
expect(model.info.contextWindow).toBe(131_072)
166+
})
137167
})
138168

139169
describe("Default behavior", () => {

src/api/providers/zai.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
mainlandZAiDefaultModelId,
66
type InternationalZAiModelId,
77
type MainlandZAiModelId,
8+
type ModelInfo,
89
ZAI_DEFAULT_TEMPERATURE,
910
zaiApiLineConfigs,
1011
} from "@roo-code/types"
@@ -13,11 +14,11 @@ import type { ApiHandlerOptions } from "../../shared/api"
1314

1415
import { BaseOpenAiCompatibleProvider } from "./base-openai-compatible-provider"
1516

16-
export class ZAiHandler extends BaseOpenAiCompatibleProvider<InternationalZAiModelId | MainlandZAiModelId> {
17+
export class ZAiHandler extends BaseOpenAiCompatibleProvider<string> {
1718
constructor(options: ApiHandlerOptions) {
1819
const isChina = zaiApiLineConfigs[options.zaiApiLine ?? "international_coding"].isChina
19-
const models = isChina ? mainlandZAiModels : internationalZAiModels
20-
const defaultModelId = isChina ? mainlandZAiDefaultModelId : internationalZAiDefaultModelId
20+
const models = (isChina ? mainlandZAiModels : internationalZAiModels) as unknown as Record<string, ModelInfo>
21+
const defaultModelId = (isChina ? mainlandZAiDefaultModelId : internationalZAiDefaultModelId) as string
2122

2223
super({
2324
...options,

0 commit comments

Comments
 (0)