Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit 1044901

Browse files
roomote[bot]hannesrudolph
authored andcommitted
feat: add GLM-5 model support to Z.ai provider (#11440)
1 parent e112e05 commit 1044901

3 files changed

Lines changed: 158 additions & 2 deletions

File tree

packages/types/src/providers/zai.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,21 @@ export const internationalZAiModels = {
120120
description:
121121
"GLM-4.7 is Zhipu's latest model with built-in thinking capabilities enabled by default. It provides enhanced reasoning for complex tasks while maintaining fast response times.",
122122
},
123+
"glm-5": {
124+
maxTokens: 16_384,
125+
contextWindow: 202_752,
126+
supportsImages: false,
127+
supportsPromptCache: true,
128+
supportsReasoningEffort: ["disable", "medium"],
129+
reasoningEffort: "medium",
130+
preserveReasoning: true,
131+
inputPrice: 0.6,
132+
outputPrice: 2.2,
133+
cacheWritesPrice: 0,
134+
cacheReadsPrice: 0.11,
135+
description:
136+
"GLM-5 is Zhipu's next-generation model with a 202k context window and built-in thinking capabilities. It delivers state-of-the-art reasoning, coding, and agentic performance.",
137+
},
123138
"glm-4.7-flash": {
124139
maxTokens: 16_384,
125140
contextWindow: 200_000,
@@ -281,6 +296,21 @@ export const mainlandZAiModels = {
281296
description:
282297
"GLM-4.7 is Zhipu's latest model with built-in thinking capabilities enabled by default. It provides enhanced reasoning for complex tasks while maintaining fast response times.",
283298
},
299+
"glm-5": {
300+
maxTokens: 16_384,
301+
contextWindow: 202_752,
302+
supportsImages: false,
303+
supportsPromptCache: true,
304+
supportsReasoningEffort: ["disable", "medium"],
305+
reasoningEffort: "medium",
306+
preserveReasoning: true,
307+
inputPrice: 0.29,
308+
outputPrice: 1.14,
309+
cacheWritesPrice: 0,
310+
cacheReadsPrice: 0.057,
311+
description:
312+
"GLM-5 is Zhipu's next-generation model with a 202k context window and built-in thinking capabilities. It delivers state-of-the-art reasoning, coding, and agentic performance.",
313+
},
284314
"glm-4.7-flash": {
285315
maxTokens: 16_384,
286316
contextWindow: 204_800,

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

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,22 @@ describe("ZAiHandler", () => {
9898
expect(model.info.preserveReasoning).toBe(true)
9999
})
100100

101+
it("should return GLM-5 international model with thinking support", () => {
102+
const testModelId: InternationalZAiModelId = "glm-5"
103+
const handlerWithModel = new ZAiHandler({
104+
apiModelId: testModelId,
105+
zaiApiKey: "test-zai-api-key",
106+
zaiApiLine: "international_coding",
107+
})
108+
const model = handlerWithModel.getModel()
109+
expect(model.id).toBe(testModelId)
110+
expect(model.info).toEqual(internationalZAiModels[testModelId])
111+
expect(model.info.contextWindow).toBe(202_752)
112+
expect(model.info.supportsReasoningEffort).toEqual(["disable", "medium"])
113+
expect(model.info.reasoningEffort).toBe("medium")
114+
expect(model.info.preserveReasoning).toBe(true)
115+
})
116+
101117
it("should return GLM-4.5v international model with vision support", () => {
102118
const testModelId: InternationalZAiModelId = "glm-4.5v"
103119
const handlerWithModel = new ZAiHandler({
@@ -193,6 +209,22 @@ describe("ZAiHandler", () => {
193209
expect(model.info.reasoningEffort).toBe("medium")
194210
expect(model.info.preserveReasoning).toBe(true)
195211
})
212+
213+
it("should return GLM-5 China model with thinking support", () => {
214+
const testModelId: MainlandZAiModelId = "glm-5"
215+
const handlerWithModel = new ZAiHandler({
216+
apiModelId: testModelId,
217+
zaiApiKey: "test-zai-api-key",
218+
zaiApiLine: "china_coding",
219+
})
220+
const model = handlerWithModel.getModel()
221+
expect(model.id).toBe(testModelId)
222+
expect(model.info).toEqual(mainlandZAiModels[testModelId])
223+
expect(model.info.contextWindow).toBe(202_752)
224+
expect(model.info.supportsReasoningEffort).toEqual(["disable", "medium"])
225+
expect(model.info.reasoningEffort).toBe("medium")
226+
expect(model.info.preserveReasoning).toBe(true)
227+
})
196228
})
197229

198230
describe("International API", () => {
@@ -522,4 +554,98 @@ describe("ZAiHandler", () => {
522554
expect(callArgs.thinking).toBeUndefined()
523555
})
524556
})
557+
558+
describe("GLM-5 Thinking Mode", () => {
559+
it("should enable thinking by default for GLM-5 (default reasoningEffort is medium)", async () => {
560+
const handlerWithModel = new ZAiHandler({
561+
apiModelId: "glm-5",
562+
zaiApiKey: "test-zai-api-key",
563+
zaiApiLine: "international_coding",
564+
// No reasoningEffort setting - should use model default (medium)
565+
})
566+
567+
mockCreate.mockImplementationOnce(() => {
568+
return {
569+
[Symbol.asyncIterator]: () => ({
570+
async next() {
571+
return { done: true }
572+
},
573+
}),
574+
}
575+
})
576+
577+
const messageGenerator = handlerWithModel.createMessage("system prompt", [])
578+
await messageGenerator.next()
579+
580+
// For GLM-5 with default reasoning (medium), thinking should be enabled
581+
expect(mockCreate).toHaveBeenCalledWith(
582+
expect.objectContaining({
583+
model: "glm-5",
584+
thinking: { type: "enabled" },
585+
}),
586+
)
587+
})
588+
589+
it("should disable thinking for GLM-5 when reasoningEffort is set to disable", async () => {
590+
const handlerWithModel = new ZAiHandler({
591+
apiModelId: "glm-5",
592+
zaiApiKey: "test-zai-api-key",
593+
zaiApiLine: "international_coding",
594+
enableReasoningEffort: true,
595+
reasoningEffort: "disable",
596+
})
597+
598+
mockCreate.mockImplementationOnce(() => {
599+
return {
600+
[Symbol.asyncIterator]: () => ({
601+
async next() {
602+
return { done: true }
603+
},
604+
}),
605+
}
606+
})
607+
608+
const messageGenerator = handlerWithModel.createMessage("system prompt", [])
609+
await messageGenerator.next()
610+
611+
// For GLM-5 with reasoning disabled, thinking should be disabled
612+
expect(mockCreate).toHaveBeenCalledWith(
613+
expect.objectContaining({
614+
model: "glm-5",
615+
thinking: { type: "disabled" },
616+
}),
617+
)
618+
})
619+
620+
it("should enable thinking for GLM-5 when reasoningEffort is set to medium", async () => {
621+
const handlerWithModel = new ZAiHandler({
622+
apiModelId: "glm-5",
623+
zaiApiKey: "test-zai-api-key",
624+
zaiApiLine: "international_coding",
625+
enableReasoningEffort: true,
626+
reasoningEffort: "medium",
627+
})
628+
629+
mockCreate.mockImplementationOnce(() => {
630+
return {
631+
[Symbol.asyncIterator]: () => ({
632+
async next() {
633+
return { done: true }
634+
},
635+
}),
636+
}
637+
})
638+
639+
const messageGenerator = handlerWithModel.createMessage("system prompt", [])
640+
await messageGenerator.next()
641+
642+
// For GLM-5 with reasoning set to medium, thinking should be enabled
643+
expect(mockCreate).toHaveBeenCalledWith(
644+
expect.objectContaining({
645+
model: "glm-5",
646+
thinking: { type: "enabled" },
647+
}),
648+
)
649+
})
650+
})
525651
})

src/api/providers/zai.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ export class ZAiHandler extends BaseOpenAiCompatibleProvider<string> {
5252
) {
5353
const { id: modelId, info } = this.getModel()
5454

55-
// Check if this is a GLM-4.7 model with thinking support
56-
const isThinkingModel = modelId === "glm-4.7" && Array.isArray(info.supportsReasoningEffort)
55+
// Check if this is a thinking model (e.g. GLM-4.7, GLM-5) with thinking support
56+
const isThinkingModel = Array.isArray(info.supportsReasoningEffort)
5757

5858
if (isThinkingModel) {
5959
// For GLM-4.7, thinking is ON by default in the API.

0 commit comments

Comments
 (0)