I’m building a system that uses gemini-3.8-flash through the Gemini Developer API, and I need to determine, before calling generateContent, whether a complete multimodal request is guaranteed to fit the model’s input/context limit.
Our intended request contains:
- a system instruction;
- textual content;
- multiple ordered inline WAV/audio parts (up to 16 within one request);
- generation configuration;
- response-format/schema configuration where applicable.
We can call:
POST /v1beta/models/{model}:countTokens
using the generateContentRequest form with the same request contents/configuration intended for generateContent.
The public documentation and examples appear to show that countTokens.totalTokens and the later generation promptTokenCount can differ. We therefore do not want to assume that countTokens <= inputTokenLimit by itself guarantees that the request will be accepted.
Could someone from the Gemini API team clarify the authoritative rule?
1. When models.countTokens receives the full generateContentRequest, does totalTokens include every component relevant to input-context admission for the later generateContent request, including multimodal/audio tokenization, media quantization, and any provider-added framing?
2. If not, is there a documented conservative maximum overhead or another supported preflight rule such that:
countTokens.totalTokens + documented_bound <= inputTokenLimit
guarantees that the subsequent generateContent request will fit?
We do not need an exact prediction of final usage or billing. We need a conservative admission guarantee that can be checked before submitting the generation request.
Separately, the Gemini billing FAQ states that the “GetTokens API” is not billed and does not count against inference quota. Does that statement apply specifically to:
POST /v1beta/models/{model}:countTokens
including multimodal/audio requests using the full generateContentRequest form?
If so, are there any separate count-specific quotas, media restrictions, or audio exceptions we should account for?
An attributable Google API-team answer or pointer to the governing documentation would be very helpful.