Fix issue with Ollama usage not being tracked and shown in 9router UI (#1102)

Co-authored-by: Abhi <abhi@fresent.com>
This commit is contained in:
Fresent 2026-05-14 08:28:18 +05:30 committed by GitHub
parent 5327a7dc30
commit d1613e8ad5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -220,6 +220,16 @@ export function extractUsage(chunk) {
});
}
// Ollama NDJSON format (raw from provider, before translation)
// Ollama sends: {"model":"...","done":true,"prompt_eval_count":N,"eval_count":M}
if (chunk.done === true && typeof chunk.prompt_eval_count === "number") {
return normalizeUsage({
prompt_tokens: chunk.prompt_eval_count || 0,
completion_tokens: chunk.eval_count || 0,
total_tokens: (chunk.prompt_eval_count || 0) + (chunk.eval_count || 0)
});
}
return null;
}