Intro to Gemini 2.5 Flash-Lite
Source notebook
Repo path:
gemini/getting-started/intro_gemini_2_5_flash_lite.ipynb· Open on GitHub · intro
Introduces Gemini 2.5 Flash-Lite on Vertex AI with prompting, thinking, structured output, search, and code tools.
Summary
This notebook teaches how to use the Gemini API through the Google Gen AI SDK for Python with the Gemini 2.5 Flash-Lite model. It walks from authentication and client setup to text generation, model configuration, safety settings, thinking budget, summarized thoughts, controlled JSON output, Google Search grounding, and code execution.
Key code patterns
Vertex AI client setup
from google import genai
client = genai.Client(
enterprise=True,
project=PROJECT_ID,
location="global",
)Connects the Google Gen AI SDK to the generative AI service on Vertex AI.
Basic text generation
response = client.models.generate_content(
model=MODEL_ID,
contents="Why is the sky blue?",
)
display(Markdown(response.text))Shows the core generate_content call and response.text access pattern.
Generation config and safety
response = client.models.generate_content(
model=MODEL_ID,
contents=prompt,
config=GenerateContentConfig(
system_instruction=system_instruction,
temperature=0.7,
top_p=0.95,
safety_settings=safety_settings,
),
)Demonstrates request-level control over instructions, sampling, output length, and safety filters.
Thinking budget
response = client.models.generate_content(
model=MODEL_ID,
contents="How many R's are in the word strawberry?",
config=GenerateContentConfig(
thinking_config=ThinkingConfig(
include_thoughts=True,
thinking_budget=1024,
)
),
)Controls Gemini 2.5 Flash-Lite reasoning behavior and optionally returns summarized thoughts.
Controlled JSON output
class RecipeList(BaseModel):
recipes: list[Recipe]
response = client.models.generate_content(
model=MODEL_ID,
contents="List a few popular cookie recipes and their ingredients.",
config=GenerateContentConfig(
response_mime_type="application/json",
response_schema=RecipeList,
),
)Uses a Pydantic schema so model output follows a defined JSON structure.
Google Search tool
google_search_tool = Tool(google_search=GoogleSearch())
response = client.models.generate_content(
model=MODEL_ID,
contents="What is the current temperature in Austin, TX?",
config=GenerateContentConfig(
tools=[google_search_tool],
),
)Lets the model use Google Search to improve accuracy and recency.
Code execution tool
code_execution_tool = Tool(code_execution=ToolCodeExecution())
response = client.models.generate_content(
model=MODEL_ID,
contents="Calculate 20th fibonacci number. Then find the nearest palindrome to it.",
config=GenerateContentConfig(
tools=[code_execution_tool],
temperature=0,
),
)Enables the model to generate and run Python code, then use the result in its answer.
Models & APIs used
- Models: gemini-2.5-flash-lite
- APIs / services: Vertex AI, Gemini API
- SDKs / libraries:
google-genai,pydantic
When to use this
Use this pattern to prototype high-volume Gemini 2.5 Flash-Lite workflows that need low-cost text generation, structured output, grounding, or code execution on Vertex AI.
Gotchas & caveats
- A Google Cloud project or Vertex AI API key is required; the notebook uses a Google Cloud project.
- Colab users must authenticate with google.colab.auth.authenticate_user().
- PROJECT_ID must be set or available through the GOOGLE_CLOUD_PROJECT environment variable.
- LOCATION is set to global.
- Gemini 2.5 Flash-Lite thinking mode is off by default; set thinking_budget to enable or control it.
- thinking_budget values shown are 0 for off, -1 for dynamic thinking, or 512-24576 for allocated thinking budget.
- The notebook notes that on June 15, 2026, access to Gemini 2.5 Flash-Lite on Gemini Enterprise Agent Platform will be removed for new and inactive projects only, and model tuning will be turned off.
Best practices
- Use GenerateContentConfig to keep model parameters, system instruction, safety settings, tools, and schemas explicit per request.
- Use system_instruction to provide task context, persona, formatting rules, and interaction guidelines.
- Use safety_settings to adjust blocking behavior for specific harm categories.
- Inspect usage_metadata to see prompt, candidate, thoughts, and total token counts.
- Use response_schema with response_mime_type=“application/json” for controlled generation.
- Check part.thought to separate summarized thoughts from final answer when include_thoughts is enabled.
- Set temperature=0 for deterministic code execution tasks.
Related
- Concepts: Getting Started · Gemini Capabilities · Function Calling & Tools
- Entities: Vertex AI · Google GenAI SDK · Grounding · Gemini
- Area: Gemini Notebooks
- Best practices: Getting Started - Best Practices · Gemini Capabilities - Best Practices · Function Calling & Tools - Best Practices