When gemini-3.5-flash runs Google Search grounding during thinking, the generateContent response body contains no usageMetadata.billedToolCalls and no groundingMetadata — yet the AI Studio log for the same responseId shows billedToolCalls with a non-zero successfulToolCallCount, and the model’s output text cites vertexaisearch.cloud.google.com/grounding-api-redirect/... URLs (which only exist when grounding ran). This makes it impossible to track billed search costs per request from the API response.
Setup
- Model:
gemini-3.5-flash - Endpoint:
generativelanguage.googleapis.comv1betagenerateContent(non-streaming), called via the Vercel AI SDK (@ai-sdk/google) - Tools:
google_searchenabled temperature: 0, default thinking (response showsthoughtsTokenCount: 2001)- Request date: 2026-07-08 ~16:53 ()
responseId:BhBOasX7GfyPjuMP0KyN8A4
What the API returned (raw response body)
"usageMetadata": {
"promptTokenCount": 1964,
"candidatesTokenCount": 797,
"totalTokenCount": 4762,
"promptTokensDetails": [{ "modality": "TEXT", "tokenCount": 1964 }],
"thoughtsTokenCount": 2001,
"serviceTier": "standard"
}
- No
billedToolCallsfield. candidates[0]has nogroundingMetadatablock at all (verified on the raw HTTP body, not an SDK-parsed copy — the body still carries fields likeserviceTierandthoughtSignature).- The candidate’s text does contain multiple
https://vertexaisearch.cloud.google.com/grounding-api-redirect/...source URLs, so search grounding clearly executed.
What AI Studio logs show for the same responseId
The log entry for BhBOasX7GfyPjuMP0KyN8A4 in the AI Studio logs dashboard includes:
"usageMetadata": {
"promptTokenCount": 1964,
"candidatesTokenCount": 797,
"totalTokenCount": 4762,
"promptTokensDetails": [
{
"modality": "TEXT",
"tokenCount": 1964
}
],
"thoughtsTokenCount": 2001,
"billedToolCalls": [
{
"tool": "GOOGLE_SEARCH_RETRIEVAL",
"successfulToolCallCount": 1
}
]
}
For reference, other calls of ours show entries like:
"billedToolCalls": [
{ "tool": "GOOGLE_SEARCH_RETRIEVAL", "successfulToolCallCount": 5 }
]
Questions
- Is omitting
billedToolCallsfrom thegenerateContentresponse body intended when searches run during thinking? If so, is there any way to get the billed search count programmatically per request (short of migrating to the Interactions API forgrounding_tool_count)? - Why is
groundingMetadata(includingwebSearchQueries)null/absent on this response even though the output cites grounding-redirect URLs? That removes the only documented fallback for counting searches. - If this is a known gap, is exposing
billedToolCallsin the response (matching what AI Studio logs already record server-side) on the roadmap? We bill customers per request and currently have to record these searches as 0.