From 7c07cc42878a4402d353efe3b8ae21df6d4d79f8 Mon Sep 17 00:00:00 2001 From: Haechan Date: Fri, 11 Sep 2026 05:54:00 +0000 Subject: [PATCH] fix: forward HTTP chat token limits to the model runtime --- src/api.ts | 2 +- test/guard-api.test.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/api.ts b/src/api.ts index c983de3..83b398a 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1582,7 +1582,7 @@ export function buildApi(deps: ApiDeps): Router { // concurrent callers each measured an untouched counter and every one of them passed. let out; try { - out = await market.chat({ ...body, requestId: body.request_id, messagesBase: body.messages_base, messagesPatched: body.messages_patched, patchIds: body.patch_ids ?? [body.patch_id!], visitor, caller: { operator, address: caller } }); + out = await market.chat({ ...body, maxTokens: body.max_tokens, requestId: body.request_id, messagesBase: body.messages_base, messagesPatched: body.messages_patched, patchIds: body.patch_ids ?? [body.patch_id!], visitor, caller: { operator, address: caller } }); } catch (e) { if (mine) market.refundChatQuota(mine); if (network && !mineIsShared) market.refundChatQuota(network); diff --git a/test/guard-api.test.ts b/test/guard-api.test.ts index e1b2bcf..6164c1a 100644 --- a/test/guard-api.test.ts +++ b/test/guard-api.test.ts @@ -143,6 +143,17 @@ test('D1: the node sends the configured stop sequences, and no penalties by defa assert.equal(b.presence_penalty, undefined); }); +test('HTTP max_tokens reaches both model calls and defaults to 200', async () => { + for (const limit of [1, 128, 1024, undefined]) { + bodies.length = 0; + const response = await ask('token budget test', { mode: 'compare', ...(limit === undefined ? {} : { max_tokens: limit }) }); + assert.equal(response.status, 200); + const requests = bodies.filter(body => body.path === '/v1/chat/completions'); + assert.equal(requests.length, 2); + assert.ok(requests.every(body => body.max_tokens === (limit ?? 200))); + } +}); + test('D1: "" is dropped from the stop list when the caller asked for thinking', async () => { bodies.length = 0; await ask('안녕하세요', { thinking: true });