Intro to Gemini 3.5 Flash

Source notebook

Repo path: gemini/getting-started/intro_gemini_3_5_flash.ipynb · Open on GitHub · intermediate

Quickstart for Gemini 3.5 Flash generation, multimodal inputs, tools, grounding, and safety with Google GenAI SDK.

Summary

This notebook teaches how to use Gemini 3.5 Flash through the Google Gen AI SDK with an enterprise client and a Google Cloud project. It walks through synchronous, streaming, async, and chat generation, then adds thinking control, multimodal media handling, function calling, grounding tools, structured JSON output, token utilities, and safety settings.

Key code patterns

Enterprise client setup

from google import genai
 
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
LOCATION = "global"
client = genai.Client(enterprise=True, project=PROJECT_ID, location=LOCATION)
MODEL_ID = "gemini-3.5-flash"

Creates the Google GenAI client used by all Gemini 3.5 Flash examples.

Generate and stream content

response = client.models.generate_content(
    model=MODEL_ID,
    contents="How does AI work?",
)
 
for chunk in client.models.generate_content_stream(
    model=MODEL_ID,
    contents=prompt,
):
    print(chunk.text, end="")

Shows standard synchronous generation and low-latency streaming output.

Thinking level control

response = client.models.generate_content(
    model=MODEL_ID,
    contents=prompt,
    config=types.GenerateContentConfig(
        thinking_config=types.ThinkingConfig(
            thinking_level=types.ThinkingLevel.HIGH
        )
    ),
)

Adjusts reasoning depth to balance latency, cost, and answer quality.

Per-part multimodal resolution

types.Part(
    file_data=types.FileData(
        file_uri="gs://cloud-samples-data/generative-ai/image/a-man-and-a-dog.png",
        mime_type="image/jpeg",
    ),
    media_resolution=types.PartMediaResolution(
        level=types.PartMediaResolutionLevel.MEDIA_RESOLUTION_ULTRA_HIGH
    ),
)

Controls token use and visual fidelity separately for each media input.

Manual function calling history

history = [
    types.Content(role="user", parts=[types.Part(text=prompt)]),
    response.candidates[0].content,
    types.Content(role="tool", parts=[
        types.Part.from_function_response(
            name=function_call.name,
            response=function_response_data,
        )
    ]),
]

Preserves the model content block containing the thought signature across tool turns.

Structured JSON output

response = client.models.generate_content(
    model=MODEL_ID,
    contents="Give me information for the United States.",
    config=types.GenerateContentConfig(
        response_mime_type="application/json",
        response_schema=CountryInfo,
    ),
)

Constrains model output to a Pydantic or OpenAPI-style schema.

Models & APIs used

  • Models: gemini-3.5-flash
  • APIs / services: Agent Platform API, Cloud Storage, Google Search Grounding, URL Context, Code Execution
  • SDKs / libraries: google-genai, pydantic

When to use this

Use this pattern when building Gemini 3.5 Flash apps that need fast generation, reasoning controls, multimodal inputs, tools, grounding, and safety controls.

Gotchas & caveats

  • Gemini 3.5 Flash features require google-genai for Python version 2.0.0 or later; the notebook installs google-genai[pyopenssl]>=2.4.0.
  • A Google Cloud project is required and the Agent Platform API must be enabled.
  • The notebook uses LOCATION = “global”.
  • Colab users must run auth.authenticate_user().
  • thinking_level cannot be combined with legacy thinking_budget in the same configuration block or the API returns 400 Bad Request.
  • For manual function calling, the previous candidate content containing the thought signature must be included in subsequent history.
  • response.text can be None when safety filters block a response.

Best practices

  • Use streaming for user-facing or chat-based interfaces to receive chunks immediately.
  • Use async generation to improve throughput in web apps and multi-agent systems.
  • Use per-part media resolution when different media inputs need different fidelity levels.
  • Use automatic function calling when possible because the SDK manages thought signatures behind the scenes.
  • Preserve response.candidates[0].content in manual tool histories to maintain reasoning context.
  • Keep temperature, top_p, and top_k at defaults for Gemini 3+ as recommended in the notebook.
  • Use response schemas when structured JSON output is required.
  • Count or compute tokens before dispatching requests when prompt token volume matters.