> ## Documentation Index
> Fetch the complete documentation index at: https://docs.octen.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Gemini Tool Calling

> Register Octen search APIs and Extract as function tools in the Gemini Interactions API.

For AI agents: [docs.octen.ai/integrations/gemini-tool-calling.md](https://docs.octen.ai/integrations/gemini-tool-calling.md)

Gemini decides when to search, your code runs the query on Octen [Web Search](https://docs.octen.ai/capabilities/web-search.md), and Gemini answers from the results.

> [card] [Get API Key](https://octen.ai/platform/api-keys)
>
> Create a key from the API Platform.

> [card] [Web Search API Reference](https://docs.octen.ai/api-reference/search.md)
>
> Full request/response schema.

## Install

```bash theme={null}
pip install google-genai octen
```

## Quick Start

Set your Octen and Gemini API keys:

```bash theme={null}
export OCTEN_API_KEY="your-api-key"
export GEMINI_API_KEY="your-gemini-api-key"
```

Run a tool-calling loop with Octen Web Search:

```python theme={null}
import json

from google import genai
from octen import Octen

client = genai.Client()  # reads GEMINI_API_KEY
octen = Octen()  # reads OCTEN_API_KEY

tools = [
    {
        "type": "function",
        "name": "web_search",
        "description": "Search the web for real-time information.",
        "parameters": {
            "type": "object",
            "properties": {
                "query": {"type": "string", "description": "The search query."},
            },
            "required": ["query"],
        },
    },
]


def web_search(query):
    response = octen.search.search(query=query, count=5)
    results = [
        {"title": r.get("title"), "url": r.get("url"), "highlight": r.get("highlight")}
        for r in response.results
    ]
    return json.dumps(results)


functions = {"web_search": web_search}

interaction = client.interactions.create(
    model="gemini-4-hydrogen",
    tools=tools,
    input="What happened in AI this week?",
)

while True:
    calls = [step for step in interaction.steps if step.type == "function_call"]
    if not calls:
        break

    results = [
        {
            "type": "function_result",
            "name": call.name,
            "call_id": call.id,
            "result": [{"type": "text", "text": functions[call.name](**call.arguments)}],
        }
        for call in calls
    ]
    interaction = client.interactions.create(
        model="gemini-4-hydrogen",
        tools=tools,
        input=results,
        previous_interaction_id=interaction.id,
    )

print(interaction.output_text)
```

Send `tools` on every request: `previous_interaction_id` carries the conversation history, but tool declarations are not stored with the interaction.

## Add an Extract Tool

Let Gemini read a full page from a URL it finds, with [Extract](https://docs.octen.ai/capabilities/extract.md). Add this code to the Quick Start program, right after `functions = {"web_search": web_search}`:

```python theme={null}
def extract(url):
    response = octen.extract.extract(urls=[url])
    item = response.items[0]
    if item.status != "success":
        return json.dumps({"url": url, "error": item.error_message})
    return json.dumps({"title": item.title, "url": item.url, "content": item.full_content})


tools.append(
    {
        "type": "function",
        "name": "extract",
        "description": "Read a web page and return its content as markdown.",
        "parameters": {
            "type": "object",
            "properties": {
                "url": {"type": "string", "description": "The URL of the page to read."},
            },
            "required": ["url"],
        },
    }
)
functions["extract"] = extract
```

## Add More Search Tools

Let Gemini also use [Web Search Premier](https://docs.octen.ai/capabilities/web-search-premier.md), [Broad Search](https://docs.octen.ai/capabilities/broad-search.md), [News Search](https://docs.octen.ai/capabilities/news-search.md), [Business Search](https://docs.octen.ai/capabilities/business-search.md), [Pulse Search](https://docs.octen.ai/capabilities/pulse-search.md), [Place Search](https://docs.octen.ai/capabilities/place-search.md), [Image Search](https://docs.octen.ai/capabilities/image-search.md), and [Design Search](https://docs.octen.ai/capabilities/design-search.md).

Add this code to the Quick Start program, right after `functions = {"web_search": web_search}`. Each tool takes a `query` and returns the response `data` as JSON, with the same fields as the API reference:

```python theme={null}
search_tools = {
    "web_search_premier": (octen.search.search_premier, "Search the web more broadly and rank more carefully than web_search, for a specific fact, a niche document, or a named page, and return ranked pages with query-relevant highlights."),
    "broad_search": (octen.search.broad_search, "Split a broad or comparative question into sub-queries, search them all, and return results grouped per sub-query."),
    "news_search": (octen.search.news_search, "Search recent news and return ranked articles plus storylines that group related coverage."),
    "business_search": (octen.search.business_search, "Look up companies and people and return their profile cards plus ranked sources."),
    "pulse_search": (octen.search.pulse_search, "Predict the URLs a query points to, such as official sites, docs, or help pages, and return their titles and URLs."),
    "place_search": (octen.place_search.search, "Find places such as restaurants, shops, or hotels and return place cards with address, opening hours, and rating. Include the city or area in the query."),
    "image_search": (octen.image_search.search, "Search the web for images and return image URLs with their source pages."),
    "design_search": (octen.design_search.search, "Search real web pages, app screens, and slides for design references and return them as images with their design values, such as colors and fonts, plus web results."),
}

for name, (method, description) in search_tools.items():
    tools.append(
        {
            "type": "function",
            "name": name,
            "description": description,
            "parameters": {
                "type": "object",
                "properties": {
                    "query": {"type": "string", "description": "The search query."},
                },
                "required": ["query"],
            },
        }
    )
    functions[name] = lambda query, method=method: json.dumps(method(query=query).data)
```

***

Last modified on November 24, 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.