mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
fix(usage): stop double-counting streaming usage at source
logUsage now only logs to console; DB write removed. Streaming usage is recorded once via saveUsageStats (onStreamComplete), eliminating duplicate usageHistory rows that inflated dashboard totals. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
* Token Usage Tracking - Extract, normalize, estimate and log token usage
|
* Token Usage Tracking - Extract, normalize, estimate and log token usage
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { saveRequestUsage, appendRequestLog } from "@/lib/usageDb.js";
|
|
||||||
import { FORMATS } from "../translator/formats.js";
|
import { FORMATS } from "../translator/formats.js";
|
||||||
|
|
||||||
// ANSI color codes
|
// ANSI color codes
|
||||||
@@ -333,15 +332,4 @@ export function logUsage(provider, usage, model = null, connectionId = null, api
|
|||||||
if (reasoning) msg += ` | reasoning=${reasoning}`;
|
if (reasoning) msg += ` | reasoning=${reasoning}`;
|
||||||
|
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
|
|
||||||
// Save to usage DB
|
|
||||||
const tokens = {
|
|
||||||
prompt_tokens: inTokens,
|
|
||||||
completion_tokens: outTokens,
|
|
||||||
cache_read_input_tokens: cacheRead || 0,
|
|
||||||
cache_creation_input_tokens: cacheCreation || 0,
|
|
||||||
reasoning_tokens: reasoning || 0
|
|
||||||
};
|
|
||||||
saveRequestUsage({ model, provider, connectionId, tokens, apiKey: apiKey || undefined }).catch(() => { });
|
|
||||||
appendRequestLog({ model, provider, connectionId, tokens, status: "200 OK" }).catch(() => { });
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user