Calculate Gemini API Cost from usageMetadata
Use the token counts from one completed generateContent response to estimate what that Standard text request cost.
Find and copy the usage object
- Open the final
generateContentresponse JSON in your API client or app logs. - Copy the object inside
usageMetadata. Keep its token counts and anyserviceTieror modality fields. - Select the model that made the request, paste the object, and choose Calculate cost. When the full response includes a supported
modelVersion, the calculator detects it.
Copying the usage object keeps prompt and response text out of the editor.
Example usageMetadata
Select Gemini 4 Neon before pasting this example.
{
"promptTokenCount": 105000,
"cachedContentTokenCount": 100000,
"candidatesTokenCount": 1500,
"thoughtsTokenCount": 500,
"totalTokenCount": 107000
}
Expected estimate $0.0600
How the fields affect cost
- Uncached input equals
promptTokenCountminuscachedContentTokenCount. The prompt count already includes cached tokens. - Cache reads use
cachedContentTokenCountat the model’s cache read rate. - Output includes both
candidatesTokenCountandthoughtsTokenCount. Each part uses the output rate.
Each part has its own rate, so totalTokenCount alone cannot determine the cost. This calculator covers standard text generation. Check your billing dashboard for other service tiers, non-text requests, grounding, and explicit cache storage.