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.
This commit is contained in:
minhphuc429
2026-01-14 15:36:47 +07:00
parent 53da774bb6
commit df81ba5632

View File

@@ -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);