From df81ba563221dca0b2e0f6908547821bf1222664 Mon Sep 17 00:00:00 2001 From: minhphuc429 Date: Wed, 14 Jan 2026 15:36:47 +0700 Subject: [PATCH] feat: use API-based token counting for 100% accuracy Switch from local estimation (gpt-tokenizer) to API-based counting via Google Cloud Code API for accurate token counts. Falls back to local estimation if API call fails. --- src/cloudcode/count-tokens.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cloudcode/count-tokens.js b/src/cloudcode/count-tokens.js index 32188de..d70586a 100644 --- a/src/cloudcode/count-tokens.js +++ b/src/cloudcode/count-tokens.js @@ -278,7 +278,7 @@ export function createCountTokensHandler(accountManager) { const result = await countTokens( { messages, model, system, tools, tool_choice, thinking }, accountManager, - { useAPI: false } // Default to local estimation for speed + { useAPI: true } // Use API for accurate token counting ); res.json(result);