fix: ensure account manager initialized for count_tokens

- Add ensureInitialized() call before count_tokens handler
- Use hybrid approach: local estimation for text, API for images/docs
- This prevents "No accounts available" error on first request
This commit is contained in:
minhphuc429
2026-01-14 15:43:25 +07:00
parent df81ba5632
commit 2bdecf6e96
2 changed files with 12 additions and 2 deletions

View File

@@ -278,7 +278,7 @@ export function createCountTokensHandler(accountManager) {
const result = await countTokens(
{ messages, model, system, tools, tool_choice, thinking },
accountManager,
{ useAPI: true } // Use API for accurate token counting
{ useAPI: false } // Use local estimation by default, API for complex content (images/docs)
);
res.json(result);