diff --git a/packages/zen-free/models.mjs b/packages/zen-free/models.mjs index 1139922..abad0ec 100644 --- a/packages/zen-free/models.mjs +++ b/packages/zen-free/models.mjs @@ -53,6 +53,18 @@ function listedFree(id) { return /-free$/.test(id); } +// "258K" is the model's working label, not an exact maximum. Zen's live +// catalog lists deepseek-v4.1-flash-free at 200000, but on 2026-10-26 a +// request whose upstream usage was in 576 + cache_read 258,048 = 258,624 +// tokens got a 200 from the free tier. That is the measured floor; the +// later 283,545-token attempt was magpie's own estimate, not upstream +// usage, so it is not a ceiling. Reporting more than the vendor accepts +// routes requests that then fail, so the floor is used until a source +// says more. Remove this when the catalog carries the real value. +const CONTEXT_FLOOR = { + "deepseek-v4.1-flash-free": 258_624, +}; + export function buildModels(ids, provider, protocols, baseURL) { const result = {}; for (const id of ids) { @@ -81,7 +93,13 @@ export function buildModels(ids, provider, protocols, baseURL) { providerID: PROVIDER, name: model.name ?? id, api: { id, url: baseURL, npm: SDK[protocol] }, - limit: { context: 32768, output: 4096, ...model.limit }, + limit: { + output: 4096, + ...model.limit, + context: CONTEXT_FLOOR[id] + ? Math.max(model.limit?.context ?? 0, CONTEXT_FLOOR[id]) + : model.limit?.context ?? 32768, + }, capabilities: { temperature: model.temperature ?? true, reasoning: model.reasoning ?? false, diff --git a/packages/zen-free/models.test.mjs b/packages/zen-free/models.test.mjs index 981b6f2..991f029 100644 --- a/packages/zen-free/models.test.mjs +++ b/packages/zen-free/models.test.mjs @@ -113,3 +113,31 @@ test("reads the console docs' endpoint table, and Jev stays out as SystemOne", a const models = buildModels(["jev-1.13-free", "step-5-preview-free"], {}, protocols, baseURL); assert.deepEqual(Object.keys(models), ["step-5-preview-free"]); }); + +// The catalog's 200000 for deepseek-v4.1-flash-free is low. The model's +// upstream usage on 2026-10-26 was in 576 + cache_read 258,048 = 258,624 +// tokens, and the request got a 200; 258,624 is therefore the measured +// floor ("258K"), not an exact ceiling. A larger catalog value (a corrected +// 262,144 or 1,000,000) must pass through untouched, and a missing one +// falls back to the floor. +test("deepseek-v4.1-flash-free keeps its measured 258K floor over a low 200K catalog", async () => { + const { buildModels } = await subject; + const model = (context) => ({ + name: "DeepSeek V4.1 Flash Free", + cost: { input: 0, output: 0 }, + limit: { ...(context == null ? {} : { context }), output: 32000 }, + reasoning: true, + tool_call: true, + }); + const built = (context) => buildModels( + ["deepseek-v4.1-flash-free"], + { npm: "@ai-sdk/openai-compatible", models: { "deepseek-v4.1-flash-free": model(context) } }, + {}, + baseURL, + )["deepseek-v4.1-flash-free"]; + assert.equal(built(200000).limit.context, 258624); + assert.equal(built(undefined).limit.context, 258624); + assert.equal(built(262144).limit.context, 262144); + assert.equal(built(1000000).limit.context, 1000000); + assert.equal(built(200000).limit.output, 32000); +}); diff --git a/packages/zen-free/package.json b/packages/zen-free/package.json index b34e9f3..333d4af 100644 --- a/packages/zen-free/package.json +++ b/packages/zen-free/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-zen-free-auth", - "version": "0.1.16", + "version": "0.1.17", "description": "OpenCode Zen free models through the public credential, with native streaming protocols", "type": "module", "main": "./index.mjs",