mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-22 16:43:35 +00:00
fix: 修复总Token消耗USD计算与模型统计不一致的问题
- 修正Redis key匹配模式从 'usage:model:*:*' 到 'usage:model:*:*:*' - 更新正则表达式以支持hourly统计数据 - 确保所有模型都使用正确的价格计算费用 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1191,7 +1191,7 @@ router.get('/usage-costs', authenticateAdmin, async (req, res) => {
|
||||
pattern = `usage:model:monthly:*:${currentMonth}`;
|
||||
} else {
|
||||
// 全部时间,先尝试从Redis获取所有历史模型统计数据
|
||||
const allModelKeys = await client.keys('usage:model:*:*');
|
||||
const allModelKeys = await client.keys('usage:model:*:*:*');
|
||||
logger.info(`💰 Total period calculation: found ${allModelKeys.length} model keys`);
|
||||
|
||||
if (allModelKeys.length > 0) {
|
||||
@@ -1200,7 +1200,7 @@ router.get('/usage-costs', authenticateAdmin, async (req, res) => {
|
||||
|
||||
for (const key of allModelKeys) {
|
||||
// 解析模型名称
|
||||
let modelMatch = key.match(/usage:model:(?:daily|monthly):(.+):\d{4}-\d{2}(?:-\d{2})?$/);
|
||||
let modelMatch = key.match(/usage:model:(?:daily|monthly|hourly):(.+):(\d{4}-\d{2}(?:-\d{2})?(?::\d{2})?)$/);
|
||||
if (!modelMatch) continue;
|
||||
|
||||
const model = modelMatch[1];
|
||||
|
||||
Reference in New Issue
Block a user