Skip to Content
ModelsGeminiGoogle Search

Gemini Google Search

This page explains how to enable Google Search for Gemini and read the sources. For model IDs and endpoints, see the Gemini family overview.

With Google Search enabled, the model searches the web and answers based on the results, which suits questions about time-sensitive information.

gemini_grounding.py
import os from google import genai from google.genai import types client = genai.Client( api_key=os.environ["OFOX_API_KEY"], http_options={"api_version": "v1beta", "base_url": "https://api.ofox.io/gemini"}, ) resp = client.models.generate_content( model="google/gemini-3.5-flash", contents="What is the latest stable version of Python?", config=types.GenerateContentConfig(tools=[types.Tool(google_search=types.GoogleSearch())]), ) print(resp.text) meta = resp.candidates[0].grounding_metadata print("Search queries:", meta.web_search_queries) for chunk in meta.grounding_chunks or []: print("Source:", chunk.web.title, chunk.web.uri)
  • In native API responses, groundingMetadata contains the search queries (webSearchQueries) and source pages (groundingChunks).
  • The OpenAI-compatible API returns the answer only, without sources.
  • Searches are billed per use; see the model page  for the rate.

For other errors, see Common errors.

Last updated on