重复计次修复

This commit is contained in:
leslie
2025-07-25 22:08:30 +08:00
parent 53e0577e19
commit 578d3ca34b

View File

@@ -253,12 +253,8 @@ class ApiKeyService {
if (accountId) { if (accountId) {
await redis.incrementAccountUsage(accountId, totalTokens, inputTokens, outputTokens, cacheCreateTokens, cacheReadTokens, model); await redis.incrementAccountUsage(accountId, totalTokens, inputTokens, outputTokens, cacheCreateTokens, cacheReadTokens, model);
logger.database(`📊 Recorded account usage: ${accountId} - ${totalTokens} tokens (API Key: ${keyId})`); logger.database(`📊 Recorded account usage: ${accountId} - ${totalTokens} tokens (API Key: ${keyId})`);
} else if (keyData.claudeAccountId) {
// 如果没有传入accountId但API Key绑定了专属账户也记录统计
await redis.incrementAccountUsage(keyData.claudeAccountId, totalTokens, inputTokens, outputTokens, cacheCreateTokens, cacheReadTokens, model);
logger.database(`📊 Recorded account usage (from API Key binding): ${keyData.claudeAccountId} - ${totalTokens} tokens (API Key: ${keyId})`);
} else { } else {
logger.debug(`⚠️ No accountId provided and API Key not bound to account, skipping account-level statistics`); logger.debug(`⚠️ No accountId provided for usage recording, skipping account-level statistics`);
} }
} }