Description
Description
The AI Request Logs show a lower token count than Google AI Studio
for requests made with thinking models (e.g. gemini-2.5-flash,
gemini-3-flash-preview).
Expected behavior
Token count in the logs matches Google AI Studio.
Actual behavior
The logs show fewer tokens. In the example above: 309 in WordPress vs 338 input + ~570 output in Google AI Studio.
Root cause
Log_Data_Extractor::extract_token_usage() ignores thoughtsTokenCount (internal reasoning tokens) from Google's usageMetadata. The SDK itself already handles this correctly in GoogleTextGenerationModel.php:584:
($usage['candidatesTokenCount'] ?? 0) + ($usage['thoughtsTokenCount'] ?? 0)
But Log_Data_Extractor.php:239–243 does not:
$input = $usage['promptTokenCount'] ?? null;
$output = $usage['candidatesTokenCount'] ?? null; // ← thoughtsTokenCount ignored
Affected file
includes/Logging/Log_Data_Extractor.php
Step-by-step reproduction instructions
Steps to reproduce
- Enable the AI Request Logging experiment
- Configure the Google provider with a thinking model (e.g.
gemini-3-flash-preview)
- Trigger a text generation (e.g. via the Title Generation experiment)
- Compare the token count in Tools → AI Request Logs with the usage in Google AI Studio → Usage
Screenshots, screen recording, code snippet
No response
Environment info
No response
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except the AI plugin.
Please confirm which theme type you used for testing.
Description
Description
The AI Request Logs show a lower token count than Google AI Studio
for requests made with thinking models (e.g.
gemini-2.5-flash,gemini-3-flash-preview).Expected behavior
Token count in the logs matches Google AI Studio.
Actual behavior
The logs show fewer tokens. In the example above: 309 in WordPress vs 338 input + ~570 output in Google AI Studio.
Root cause
Log_Data_Extractor::extract_token_usage()ignoresthoughtsTokenCount(internal reasoning tokens) from Google'susageMetadata. The SDK itself already handles this correctly inGoogleTextGenerationModel.php:584:But
Log_Data_Extractor.php:239–243does not:Affected file
includes/Logging/Log_Data_Extractor.phpStep-by-step reproduction instructions
Steps to reproduce
gemini-3-flash-preview)Screenshots, screen recording, code snippet
No response
Environment info
No response
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except the AI plugin.
Please confirm which theme type you used for testing.