Gemini model behaviour
The Gemini API's own vocabulary — finishReason, safety settings, function-calling modes, stopSequences — and what each one does to a response you were expecting.
The Gemini API was not designed as a variant of anybody else’s. It has its own request body, its own names for things that exist elsewhere under different names, and a few concepts—grounding metadata, thinking budgets, explicit context caches—that have no equivalent in the chat-completions shape most people learned first. Nearly every surprise it produces is a consequence of that vocabulary rather than of the model: an empty answer is usually a finishReason you did not read, a dropped instruction is usually a system_instruction that was posted inside contents, and a truncated JSON object is usually an output ceiling doing exactly what it is documented to do.
These pages take the API on its own terms. Each one starts from the field as Google documents it—the literal key, the literal enum values, the literal place in the body—and works out to the behaviour you can observe. Where a figure is per-model or has changed between generations, it is named as such and pointed at the live reference rather than frozen into prose, because Gemini’s numbers move more than most.
Gemini 1.5 Pro's Context Window and the Long-Context Caveat
The 2,097,152-token input ceiling, what that many tokens actually holds, and Google's own documented limit on how well retrieval holds up at the top of the range.
9 min read
system_instruction in the Gemini API: A Separate Field From contents
Why Gemini takes the system prompt as a top-level sibling of contents rather than as a message, and what breaks when you post it as one.
8 min read
Function Calling Modes in the Gemini API: AUTO, ANY and NONE
What tool_config.function_calling_config does to the same prompt under each mode, and why ANY is the one that changes the response type.
9 min read
Gemini's Safety Settings: The Harm Categories and Threshold Levels
The adjustable harm categories, the block thresholds each accepts, and the two places in a response where a safety decision shows up.
9 min read
generateContent and streamGenerateContent: Gemini's Two Response Modes
The streamed chunk shape set against the single-response shape, including the alt=sse flag that decides whether you get server-sent events or a streamed JSON array.
9 min read
Context Caching in the Gemini API: The Minimum Token Floor and TTL
Why an explicit cache has a minimum size at all, what the TTL is charging you for, and the request that fails because it is too small to cache.
9 min read
Grounding With Google Search in the Gemini API
The one-line tool declaration that turns on Search grounding, and the groundingMetadata structure that comes back when it fires.
9 min read
Gemini's Thinking Budget Parameter
Where thinkingBudget sits in the request, what its special values mean, and why the budget and your answer are competing for the same output allowance.
9 min read
Video Input in the Gemini API: How Frames Become Tokens
The frame-sampling rate, the per-second token rates Google documents, and the arithmetic for a clip of a given length — plus the one call that gives you the real number.
9 min read
Native Audio Input in the Gemini API
The accepted audio MIME types, the per-second token cost, and what a model that hears the audio can answer that a transcript cannot.
8 min read
JSON Output in the Gemini API: response_mime_type and response_schema
The two generationConfig fields that constrain output to a shape, the OpenAPI subset the schema is written in, and the Gemini-specific propertyOrdering field.
9 min read
Gemini's Max Output Tokens per Model
The documented output ceiling for the current Gemini models, why it is unrelated to the context window, and what thinking tokens take out of it.
8 min read
finishReason Values in the Gemini API and What Each One Means
Every documented finishReason against the condition that produces it, and why blockReason is a different field answering a different question.
9 min read
Gemini Model Version Suffixes: -latest, -001 and Stable Names
How to read a Gemini model string, which forms are aliases that move underneath you, and how to tell what actually served your request.
8 min read
Gemini's Model Deprecation and Retirement Schedule
How Google's model lifecycle works — legacy, deprecated, retired — where the dates are published, and what has already been retired.
8 min read
Gemini's Tokenizer: Why Token Counts Differ From GPT's
Why the same string is a different number of tokens on Gemini than on a GPT model, and how to get both numbers for text you care about.
8 min read
The countTokens Method in the Gemini API
How to call countTokens before a generation request, what comes back, and how to turn the number into a cost estimate you can act on.
9 min read
The candidateCount Parameter in the Gemini API
What asking Gemini for several candidates in one call returns, and what it does to the tokens you are billed for.
7 min read
Gemini Flash's Context Window and Output Cap
The documented input and output token limits for the Gemini Flash line, and why the two numbers are set independently.
7 min read
Gemini's Code Execution Tool: How It Runs and Returns Results Inline
How the built-in code execution tool is declared, what the executableCode and codeExecutionResult parts contain, and what the sandbox can and cannot do.
9 min read
Parallel Function Calling in the Gemini API
How one Gemini turn can carry several functionCall parts at once, and the one rule for answering them that most implementations get wrong.
8 min read
Why Gemini Returns an Empty Response With a Safety Block Reason
What to do when Gemini returns no candidates or an empty text field, and how to tell a prompt block from an output block.
9 min read
stopSequences in the Gemini API and Its Limits
How stopSequences truncates Gemini output, how many you may pass, and why the stop text does not appear in the result.
7 min read
Gemini's Knowledge Cutoff by Model
Where Google documents each Gemini model's training cutoff, what the date does and does not mean, and how to check it for the model you call.
8 min read
The Gemini File API: Uploading Large Files Instead of Inlining Them
How to upload a file to the Gemini File API and reference it by URI in a generation request, and the request size that forces you to.
9 min read
Implicit and Explicit Caching in the Gemini API
The difference between the automatic cache you get for free and the cachedContent resource you create and pay to keep.
8 min read
Enum-Constrained Output in the Gemini API
How to make Gemini choose from a fixed list of values instead of writing a sentence, using an enum schema and the right response MIME type.
7 min read
Sending Function Responses Back in a Multi-Turn Gemini Conversation
The full three-turn shape of a Gemini tool exchange, with the exact roles and parts for the functionCall and functionResponse pair.
9 min read
Gemini's Temperature Range: Why It Goes Above 1.0
The documented 0-to-2 temperature range on the Gemini API, what values above 1.0 actually do, and why providers document different ranges.
7 min read
The Gemini Live API: Streaming Session Shape for Real-Time Audio and Video
How a Live API WebSocket session is set up and what messages flow in each direction, and how it differs from streaming generateContent.
10 min read
Other topics
- LLM fundamentals & architecture
- Tokens, tokenization & context windows
- Prompt engineering
- Reasoning models & test-time compute
- Multimodal AI: vision, audio, video
- RAG & retrieval
- Embeddings & vector search
- AI agents & tool use
- Structured output & function calling
- Fine-tuning & post-training
- Local inference errors, string by string
- Running local models day to day
- Testing code that calls an LLM
- Snapshot and property testing for model output
- Regression suites for prompts
- Eval gates in CI
- Flaky tests against a model
- Determinism and the cost of testing
- Contract and streaming tests
- Testing tool calls and retrieval
- Inference, serving & latency
- Rolling out a prompt change
- Testing AI systems in practice
- Forecasting a time series
- Machine learning on tabular data
- Geospatial data and models
- Understanding audio that is not speech
- Understanding video
- Core computer vision tasks
- Machine learning on graphs
- Point clouds and 3D
- Evaluation, benchmarks & LLM-as-judge
- Sensor and IoT data
- Logs and event streams
- Models over biological sequences
- Machine learning on molecules
- Embedding and searching code
- Extracting invoices and purchase orders
- Receipts, statements and tax forms
- Insurance policies and contracts
- Deeds, court filings and patents
- Extracting from medical records
- Observability & LLMOps
- CVs, certificates and identity documents
- Shipping, customs and technical documents
- Meetings, email, chat and filled-in forms
- Building an extraction pipeline
- Business, property and inspection documents
- Contract clauses and insurance claims
- Regulated and compliance documents
- Consumer, travel and closing documents
- Mapping one chat API onto another
- SDK and framework migrations
- Hallucination & failure modes
- Re-embedding and model deprecation
- Cutting over between providers
- Parity gaps, shims and legacy endpoints
- Moving between model versions
- Migrating vector stores and caches
- Mapping capabilities and parameters
- Migrating pipelines and agents
- Contracts, runbooks and rollback
- Auditing a codebase before a cutover
- Compliance and fine-tune migration
- LLM cost engineering
- Routing, cost tracking and multi-tenancy
- What a migration does to your prompts
- AI security & prompt injection
- Privacy, compliance & data residency
- AI governance, policy & society
- Building reliable AI applications
- AI hardware, GPUs & compute
- Open-weight models & local inference
- AI for developers & coding agents
- AI in industry: vertical playbooks
- AGI, superintelligence, alignment & the long future
- Machine learning foundations
- NLP fundamentals & classical tasks
- Data engineering for AI
- Synthetic data & dataset curation
- AI product design & UX
- Search, ranking & recommendation
- Enterprise adoption & change management
- AI careers, skills & teams
- Reading AI research
- AI in science & discovery
- Robotics & embodied AI
- AI economics, markets & business models
- AI myths, hype & media literacy
- Context engineering
- Shipping AI features: patterns & anti-patterns
- Build it: end-to-end AI tutorials
- Python for AI: hands-on recipes
- TypeScript, React and the web
- Frameworks and SDKs
- Errors and troubleshooting
- AI facts, numbers and statistics
- The history of AI
- The maths behind AI
- Architectures beyond the transformer
- Reinforcement learning
- Diffusion and generative media
- Speech, audio and voice engineering
- Benchmarks, one at a time
- AI search visibility
- Infrastructure and operations
- Databases and storage for AI
- Knowledge graphs and structured knowledge
- Classical ML in production
- Regulation, jurisdiction by jurisdiction
- Prompt recipes and pattern library
- AI for people who do not write code
- Writing, media and creative work
- Edge and on-device AI
- Interpretability and model internals
- Field notes
- OpenAI model behaviour
- Claude model behaviour
- Llama model behaviour
- Mistral model behaviour
- Qwen model behaviour
- DeepSeek model behaviour
- Cohere model behaviour
- Grok model behaviour
- Small model behaviour
- Hybrid model architectures
- Token cost by language and script
- Transliteration, romanization and script handling
- Locale-correct output
- Multilingual generation quality
- Multilingual pipelines
- The EU AI Act, article by article
- AI under the GDPR and EU data law
- US AI regulation, state and sector
- International AI governance and standards
- AI litigation and enforcement
- Running AI workloads on AWS
- Running AI workloads on Google Cloud
- Running AI workloads on Azure
- AI at the edge: Workers, Vercel and Netlify
- Serving models on Kubernetes
- Operating AI infrastructure
- Quantization formats and what they cost
- llama.cpp, flag by flag
- Ollama and the desktop local-model runtimes
- Local models on Apple Silicon
- Hardware for local inference
- Running speech and embedding models locally
- Model files, adapters and conversion
- VRAM arithmetic for local models