Gemini 3.1 Flash¶
Overview¶
Gemini 3.1 Flash Image Preview is Google’s more efficient conversational image model in the Gemini 3 family. Google highlights low latency, mainstream price positioning, expanded output size options, and better aspect-ratio handling. In a documentation portal, it belongs in the category of practical image generation for product teams that want faster turnaround and a more forgiving cost profile than the Pro image variant.
API base URL¶
Example payload¶
{
"model": "gemini-3.1-flash-image-preview",
"contents": [
{
"text": "Generate a polished product visual with soft studio lighting"
}
],
"config": {
"imageConfig": {
"aspectRatio": "1:1",
"imageSize": "2K",
"enhancePrompt": false
}
}
}
Our Current Pricing¶
Gemini image billing is hybrid. The preferred path is token-based when the provider returns token counts, but the code also carries fallback per-image amounts for cases where output token data is missing.
Implemented pricing key for this model family: gemini-3.1-flash-image-preview.
Preferred formula:
cost_usd =
(tokens_out * output_price_per_1m_tokens / 1_000_000) +
(tokens_in * input_price_per_1m_tokens / 1_000_000)
Fallback behavior applies only when tokensOut is absent or zero. Fallback rows are 512x512 -> 0.045 USD, 2048x2048 -> 0.101 USD, 4096x4096 -> 0.151 USD, with 0.067 USD as the default. If the pricing key itself is unknown, the final defensive fallback is 0.0025 USD. Final rounding is to 6 decimal places.
The practical billing rule is straightforward. First try to read the usage object and compute cost from tokensIn and tokensOut. If usage is missing, look up the output size you requested or inferred and charge the fallback image amount. That dual strategy is useful because Gemini image responses can be metered precisely when usage is present, but your product still needs a deterministic amount when it is not.