UniterRouter
API ReferenceGoogle Compatible

Grounding & Search

Gemini Grounding API - Enhance AI responses with real-time Google Search data. Build fact-checked, up-to-date AI applications with web search integration.

Grounding with Google Search

Grounding connects Gemini to real-time information from Google Search, ensuring responses are based on current, factual data rather than just training knowledge.

Supported Models: Grounding is available on Gemini 1.5+ models.

How It Works

  1. Enable Google Search grounding
  2. Model queries Google Search for relevant information
  3. Responses cite sources from search results
  4. Grounding metadata shows which sources were used

Enable Grounding

curl -X POST "https://api.uniterouter.ai/v1beta/models/gemini-2.0-flash:generateContent" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: $UNITEROUTER_API_KEY" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [{"text": "What are the latest developments in AI regulation?"}]
      }
    ],
    "tools": [
      {
        "googleSearch": {}
      }
    ]
  }'
import google.generativeai as genai

genai.configure(
    api_key="your_uniterouter_api_key",
    transport="rest",
    client_options={"api_endpoint": "api.uniterouter.ai"}
)

model = genai.GenerativeModel(
    "gemini-2.0-flash",
    tools=["google_search"]
)

response = model.generate_content(
    "What are the latest developments in AI regulation?"
)

print(response.text)

# Access grounding metadata
if response.candidates[0].grounding_metadata:
    for chunk in response.candidates[0].grounding_metadata.grounding_chunks:
        if chunk.web:
            print(f"Source: {chunk.web.title} - {chunk.web.uri}")
import { GoogleGenerativeAI } from "@google/generative-ai";

const genAI = new GoogleGenerativeAI("your_uniterouter_api_key", {
  baseUrl: "https://api.uniterouter.ai"
});

const model = genAI.getGenerativeModel({
  model: "gemini-2.0-flash",
  tools: [{ googleSearch: {} }]
});

const result = await model.generateContent(
  "What are the latest developments in AI regulation?"
);

console.log(result.response.text());

// Access grounding metadata
const metadata = result.response.candidates?.[0]?.groundingMetadata;
if (metadata?.groundingChunks) {
  for (const chunk of metadata.groundingChunks) {
    if (chunk.web) {
      console.log(`Source: ${chunk.web.title} - ${chunk.web.uri}`);
    }
  }
}

Response with Grounding

{
  "candidates": [{
    "content": {
      "parts": [{
        "text": "Recent developments in AI regulation include..."
      }],
      "role": "model"
    },
    "groundingMetadata": {
      "searchEntryPoint": {
        "renderedContent": "<search results HTML>"
      },
      "groundingChunks": [
        {
          "web": {
            "uri": "https://example.com/ai-regulation",
            "title": "AI Regulation Update 2024"
          }
        }
      ],
      "groundingSupports": [
        {
          "segment": {
            "startIndex": 0,
            "endIndex": 100
          },
          "groundingChunkIndices": [0],
          "confidenceScores": [0.95]
        }
      ],
      "webSearchQueries": ["AI regulation 2024 latest news"]
    }
  }]
}

Grounding Metadata

FieldDescription
searchEntryPointRendered search results
groundingChunksSources used (web pages)
groundingSupportsWhich response parts cite which sources
webSearchQueriesQueries sent to Google Search
retrievalMetadataAdditional retrieval info

Dynamic Retrieval

Control when grounding is used:

{
  "tools": [{
    "googleSearch": {
      "dynamicRetrievalConfig": {
        "mode": "MODE_DYNAMIC",
        "dynamicThreshold": 0.5
      }
    }
  }]
}
ModeDescription
MODE_UNSPECIFIEDDefault behavior
MODE_DYNAMICModel decides based on query

Use Cases

Use CaseExample Query
Current Events"What happened in the news today?"
Fact Checking"What is the population of Tokyo?"
Research"Latest research on quantum computing"
Product Info"When was iPhone 15 released?"
Sports"Who won the last World Cup?"

Google Maps Grounding

For location-based queries:

model = genai.GenerativeModel(
    "gemini-2.0-flash",
    tools=["google_maps"]
)

response = model.generate_content(
    "Find Italian restaurants near Times Square"
)

Combining Grounding with Other Tools

model = genai.GenerativeModel(
    "gemini-2.0-flash",
    tools=[
        "google_search",
        "code_execution",
        {
            "function_declarations": [...]
        }
    ]
)

Best Practices

  1. Use for current info - Grounding is best for time-sensitive queries
  2. Check citations - Verify important claims against sources
  3. Combine tools - Use with code execution for data analysis
  4. Dynamic mode - Let model decide when to search for efficiency

Limitations

  • Search quota limits may apply
  • Some queries may not trigger search
  • Results depend on Google Search availability

How is this guide?