Gemini 3 API (google-genai) - Usage Notes
Use this when wiring Gemini 3 models in the Python SDK to avoid outdated params.
Model invariant: Never select Gemini 3.1 Pro or any Gemini Pro model. Use Gemini 3.8 Flash (gemini-3.8-flash, gemini-3.8-flash-high) or later.
ThinkingConfig (Gemini 3)
For Gemini 3, use the google-genai SDK ThinkingConfig field thinking_level. Add include_thoughts=True only when thought summaries are needed.
from google import genai
from google.genai import types
client = genai.Client()
response = client.models.generate_content(
model="gemini-3.8-flash",
contents="Explain how AI works.",
config=types.GenerateContentConfig(
thinking_config=types.ThinkingConfig(thinking_level="high"),
),
)
print(response.text)
Notes:
- Use
thinking_level(for example,"high") to configure Gemini 3 thinking. thinking_budgetis a legacy parameter for older model integrations; usethinking_levelfor Gemini 3 and never send both fields in one request.
Code execution tool (Gemini API)
Enable code execution via tools in GenerateContentConfig:
from google import genai
from google.genai import types
client = genai.Client()
response = client.models.generate_content(
model="gemini-3.8-flash",
contents="Compute the sum of the first 50 primes using code.",
config=types.GenerateContentConfig(
tools=[types.Tool(code_execution=types.ToolCodeExecution)],
),
)
for part in response.candidates[0].content.parts:
if part.executable_code is not None:
print(part.executable_code.code)
if part.code_execution_result is not None:
print(part.code_execution_result.output)
Structured JSON output (response_mime_type)
Gemini supports structured JSON outputs via response_mime_type and schema.
Gemini 3 can combine structured outputs with built-in tools, including code execution.
from google import genai
from google.genai import types
from pydantic import BaseModel
class Result(BaseModel):
summary: str
client = genai.Client()
response = client.models.generate_content(
model="gemini-3.8-flash",
contents="Summarize this text in one sentence.",
config=types.GenerateContentConfig(
response_mime_type="application/json",
response_json_schema=Result.model_json_schema(),
),
)
Model Selection Requirement (Gemini Invariant)
Mandatory Invariant: Never use Gemini 3.1 Pro (or older Gemini Pro models). Always use Gemini 3.8 Flash (gemini-3.8-flash / gemini-3.8-flash-high) or later.
Checklist for Gemini 3 integrations
- Model invariant: Never use Gemini 3.1 Pro (or older Gemini Pro models); always use Gemini 3.8 Flash (
gemini-3.8-flash/gemini-3.8-flash-high) or later. - Use thinking_config with thinking_level (Gemini 3).
- Enable code execution via tools=[types.Tool(code_execution=types.ToolCodeExecution)].
- Use response_mime_type="application/json" (and optional response_json_schema) for JSON mode.
- Extract code execution evidence from response parts (executable_code/code_execution_result).