Description
DiscoveryEngineSearchTool fails with a 400 error when used with a data store located in a non-global region (e.g. eu).
Error
400 Incorrect API endpoint used. The current endpoint can only serve traffic from "global" region,
but got "eu" region from the API request.
Please follow https://cloud.google.com/generative-ai-app-builder/docs/locations to use the correct regional API endpoint.
Root cause
In discovery_engine_search_tool.py (L75-84), the SearchServiceClient is always created with the default global endpoint (discoveryengine.googleapis.com):
credentials, _ = google.auth.default()
quota_project_id = getattr(credentials, "quota_project_id", None)
options = (
client_options.ClientOptions(quota_project_id=quota_project_id)
if quota_project_id
else None
)
self._discovery_engine_client = discoveryengine.SearchServiceClient(
credentials=credentials, client_options=options
)
However, regional data stores (e.g. eu, us, or single-region like europe-west1) require regional endpoints such as eu-discoveryengine.googleapis.com, as documented in Discovery Engine locations.
The location is already present in the data_store_id parameter (e.g. projects/{project}/locations/eu/collections/…), but it is never used to configure the client endpoint.
Reproduction
from google.adk.tools import DiscoveryEngineSearchTool
tool = DiscoveryEngineSearchTool(
data_store_id="projects/my-project/locations/eu/collections/default_collection/dataStores/my-datastore",
)
# Calling the tool triggers a 400 error
result = tool.discovery_engine_search("test query")
# → {"status": "error", "error_message": "400 Incorrect API endpoint used..."}
Expected behavior
The tool should extract the location from data_store_id (or search_engine_id) and set the appropriate api_endpoint in ClientOptions:
eu → eu-discoveryengine.googleapis.com
us → us-discoveryengine.googleapis.com
europe-west1 → europe-west1-discoveryengine.googleapis.com
global → discoveryengine.googleapis.com (default, unchanged)
Suggested fix
Parse the location from the resource ID and pass api_endpoint to ClientOptions:
import re
location_match = re.search(r"/locations/([^/]+)/", data_store_id or search_engine_id)
location = location_match.group(1) if location_match else "global"
api_endpoint = (
f"{location}-discoveryengine.googleapis.com"
if location != "global"
else "discoveryengine.googleapis.com"
)
options = client_options.ClientOptions(
api_endpoint=api_endpoint,
quota_project_id=quota_project_id,
)
Alternatively, accept an optional client_options or api_endpoint parameter in the constructor to let users override it.
Environment
google-adk version: 1.25.1
- Data store location: eu
- Python: 3.14
Description
DiscoveryEngineSearchToolfails with a 400 error when used with a data store located in a non-global region (e.g.eu).Error
Root cause
In
discovery_engine_search_tool.py(L75-84), theSearchServiceClientis always created with the default global endpoint (discoveryengine.googleapis.com):However, regional data stores (e.g.
eu,us, or single-region likeeurope-west1) require regional endpoints such aseu-discoveryengine.googleapis.com, as documented in Discovery Engine locations.The location is already present in the
data_store_idparameter (e.g.projects/{project}/locations/eu/collections/…), but it is never used to configure the client endpoint.Reproduction
Expected behavior
The tool should extract the location from
data_store_id(orsearch_engine_id) and set the appropriateapi_endpointinClientOptions:eu→eu-discoveryengine.googleapis.comus→us-discoveryengine.googleapis.comeurope-west1→europe-west1-discoveryengine.googleapis.comglobal→discoveryengine.googleapis.com(default, unchanged)Suggested fix
Parse the location from the resource ID and pass
api_endpointtoClientOptions:Alternatively, accept an optional
client_optionsorapi_endpointparameter in the constructor to let users override it.Environment
google-adkversion: 1.25.1