pi-mono/packages/ai/test/zai-coding-plan-models.test.ts
Mario Zechner 7ddbac2823 fix(ai): keep cloudflare ai gateway workers-ai models when models.dev drops them
models.dev's cloudflare-ai-gateway catalog no longer lists workers-ai/*
entries, which removed every openai-completions model from the generated
gateway catalog and narrowed the inferred provider api union. Derive the
gateway's workers-ai models from the cloudflare-workers-ai catalog and pin
the provider's api generic. Also move the zai glm-5.3 cost assertion, now
that models.dev prices it in the zai API catalog.
2026-08-25 16:52:29 +02:00

60 lines
1.6 KiB
TypeScript

import { expect, it } from "vitest";
import { getBuiltinModel } from "../src/providers/all.ts";
it("exposes GLM-4.6V on the China Coding Plan catalog", () => {
const model = getBuiltinModel("zai-coding-cn", "glm-4.6v");
expect(model).toMatchObject({
id: "glm-4.6v",
provider: "zai-coding-cn",
api: "openai-completions",
baseUrl: "https://open.bigmodel.cn/api/coding/paas/v4",
reasoning: true,
input: ["text", "image"],
cost: { input: 0.3, output: 0.9, cacheRead: 0, cacheWrite: 0 },
contextWindow: 128000,
maxTokens: 32768,
compat: {
maxTokensField: "max_tokens",
thinkingFormat: "zai",
zaiToolStream: true,
},
});
});
it("uses API-equivalent reference costs for Coding Plan models", () => {
expect(getBuiltinModel("zai", "glm-5.2").cost).toEqual({
input: 1.4,
output: 4.4,
cacheRead: 0.26,
cacheWrite: 0,
});
expect(getBuiltinModel("zai-coding-cn", "glm-5.1").cost).toEqual({
input: 1.4,
output: 4.4,
cacheRead: 0.26,
cacheWrite: 0,
});
expect(getBuiltinModel("zai-coding-cn", "glm-5v-turbo").cost).toEqual({
input: 1.2,
output: 4,
cacheRead: 0.24,
cacheWrite: 0,
});
for (const provider of ["zai", "zai-coding-cn"] as const) {
expect(getBuiltinModel(provider, "glm-5.3").cost).toEqual({
input: 1.4,
output: 4.4,
cacheRead: 0.26,
cacheWrite: 0,
});
}
});
it("keeps zero costs for Coding Plan models without a matching API price", () => {
const zeroCost = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
for (const provider of ["zai", "zai-coding-cn"] as const) {
expect(getBuiltinModel(provider, "glm-5.2-highspeed").cost).toEqual(zeroCost);
}
});