Skip to content

DiscoveryEngineSearchTool: 400 error with regional (non-global) data stores #4697

Description

@kaligautier

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)
ifquota_project_idelseNone
)
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

fromgoogle.adk.toolsimportDiscoveryEngineSearchTooltool=DiscoveryEngineSearchTool(
data_store_id="projects/my-project/locations/eu/collections/default_collection/dataStores/my-datastore",
)
# Calling the tool triggers a 400 errorresult=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:

  • eueu-discoveryengine.googleapis.com
  • usus-discoveryengine.googleapis.com
  • europe-west1europe-west1-discoveryengine.googleapis.com
  • globaldiscoveryengine.googleapis.com (default, unchanged)

Suggested fix

Parse the location from the resource ID and pass api_endpoint to ClientOptions:

importrelocation_match=re.search(r"/locations/([^/]+)/", data_store_idorsearch_engine_id)
location=location_match.group(1) iflocation_matchelse"global"api_endpoint= (
f"{location}-discoveryengine.googleapis.com"iflocation!="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

Metadata

Metadata

Assignees

Labels

tools[Component] This issue is related to tools

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions