googleapis / googleapis/python-genai

URL context tool not working together with Google Search on Vertex AI

Open
#941 13 comments 1 reaction 1 assignee Assigned to @kkorpal View on GitHub
priority: p2 type: bug
Dominant language
Python
Stars
4k
Forks
1k
Avg merge
2d 11h
Merged PRs (30d)
40

Description

When using the Gemini API, the URL context tool works fine together with Google Search, as documented here:
https://ai.google.dev/gemini-api/docs/url-context

However, on Vertex AI, I'm getting the following error:
```
{'error': {'code': 400, 'message': 'Multiple tools are supported only when they are all search tools.', 'status': 'INVALID_ARGUMENT'}}
```

Test code:
```python
from google import genai
from google.genai import types

def generate():
client = genai.Client(
vertexai=True,
project="XXX",
location="global",
)

model = "gemini-2.5-flash-preview-05-20"
contents = [
types.Content(
role="user",
parts=[
types.Part.from_text(text="""Summarize this page: https://ai.google.dev/gemini-api/docs/url-context"""),
],
),
]
tools = [
types.Tool(url_context=types.UrlContext()),
types.Tool(google_search=types.GoogleSearch()),
]
generate_content_config = types.GenerateContentConfig(
tools=tools,
response_mime_type="text/plain",
)

for chunk in client.models.generate_content_stream(
model=model,
contents=contents,
config=generate_content_config,
):
print(chunk.text, end="")

if __name__ == "__main__":
generate()
```

If I change client to use the Gemini API with an API key, the same code works.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.