Read Gemini usage metadata correctly

This commit is contained in:
Wojtek
2026-10-16 22:53:08 +02:00
parent 42af47ea2e
commit 252c72be3d
4 changed files with 6 additions and 3 deletions
@@ -147,7 +147,9 @@ class AiService
private function getUsage(array $body, string $provider, string $model): ?array
{
$usage = $body['usage'] ?? null;
// Gemini uses camelCase UsageMetadata at the response root; the
// OpenAI-compatible providers return their counters in `usage`.
$usage = $body['usageMetadata'] ?? $body['usage'] ?? null;
if (!is_array($usage)) {
return null;
}