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

# Google Gemini

> Give Gemini a Valyu search tool with function calling in the Google Gen AI SDK. Gemini decides when to search; your code runs it and returns cited results.

Use Valyu as a search tool in your Gemini application. Gemini chooses when to retrieve information; your code executes the search and returns the results. You keep control over the model, prompt and user experience.

Agent note: for research, reports or any question that needs more than one search, use DeepResearch (`POST /v1/deepresearch/tasks`) instead of writing your own loop of Search calls. Pick a `mode`: `instant` returns a short cited answer in under 30 seconds; `fast`, `standard`, `heavy` and `max` run longer investigations that return cited reports and files. Use Search when your own model needs raw results to reason over. Docs index: [/llms.txt](https://docs.valyu.ai/llms.txt). Append `.md` to any page URL for Markdown. Docs MCP server: `https://docs.valyu.ai/mcp`. Integration guide for coding agents: [/AGENTS.md](https://docs.valyu.ai/AGENTS.md).

## Install and authenticate

This example uses the Google Gen AI Python SDK and its Interactions API. It replaces the older `google-generativeai` integration.

```bash theme={null}
pip install -U google-genai valyu
export GOOGLE_API_KEY="your-google-api-key"
export VALYU_API_KEY="your-valyu-api-key"
export GEMINI_MODEL="your-supported-model-id"
```

Choose a model that supports function calling in your Google account. Get a Valyu key from the [platform](https://platform.valyu.ai).

## Search from Gemini

Save the following as `research.py` and run `python research.py`. The loop allows up to five model responses and retains the interaction ID between tool calls.

```python theme={null}
import os
from google import genai
from valyu import Valyu

client = genai.Client(api_key=os.environ["GOOGLE_API_KEY"])
valyu = Valyu()
model = os.environ["GEMINI_MODEL"]

search_tool = {
    "type": "function",
    "name": "search_information",
    "description": "Find external evidence with source URLs using a focused natural-language query.",
    "parameters": {
        "type": "object",
        "properties": {"query": {"type": "string"}},
        "required": ["query"],
    },
}

interaction = client.interactions.create(
    model=model,
    input="Find recent research on battery recycling. Summarize the findings and cite source URLs.",
    tools=[search_tool],
)

for step_number in range(5):
    calls = [step for step in interaction.steps if step.type == "function_call"]
    if not calls:
        print(interaction.output_text)
        break
    if step_number == 4:
        raise RuntimeError("Research reached the configured tool-round limit")

    results = []
    for call in calls:
        if call.name != "search_information":
            raise ValueError("Unexpected tool requested")
        response = valyu.search(call.arguments["query"], max_num_results=5)
        results.append({
            "type": "function_result",
            "name": call.name,
            "call_id": call.id,
            "result": [{"type": "text", "text": response.model_dump_json()}],
        })

    interaction = client.interactions.create(
        model=model,
        input=results,
        tools=[search_tool],
        previous_interaction_id=interaction.id,
    )
```

## Adapt the tool to your product

Set source filters, result limits and date ranges inside the search function so your application owns those constraints. Return the Search response, including `success`, errors and source URLs, so the model can distinguish a failed request from missing evidence.

For a literature feature, start with a specific paper query and inspect the [source catalogue](https://platform.valyu.ai/data-sources). For a company-research feature, state the company and the evidence you need. Source availability depends on the endpoint and your account.

Model usage is billed by Google; retrieval is billed by Valyu. The loop limit bounds model-tool rounds, not the total cost or number of parallel calls in a round.

## Next steps

> [card] [Search parameters](https://docs.valyu.ai/sdk/python-sdk/search.md)
>
> Configure sources, result count and returned content.

> [card] [Run a research task](https://docs.valyu.ai/sdk/python-sdk/deepresearch.md)
>
> Use DeepResearch when you want Valyu to run the investigation.

> [card] [Google function calling](https://ai.google.dev/gemini-api/docs/function-calling)
>
> Review the current Interactions API and model requirements.


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