@@ -231,17 +231,26 @@ def init(
231231 f"{ api_transport } is not a valid transport type. "
232232 + f"Valid transport types: { VALID_TRANSPORT_TYPES } "
233233 )
234- else :
235234 # Raise error if api_transport other than rest is specified for usage with API key.
235+ elif api_key and api_transport != "rest" :
236+ raise ValueError (f"{ api_transport } is not supported with API keys. " )
237+ else :
236238 if not project and not api_transport :
237239 api_transport = "rest"
238- elif not project and api_transport != "rest" :
239- raise ValueError (f"{ api_transport } is not supported with API keys. " )
240+
240241 if location :
241242 utils .validate_region (location )
243+ # Set api_transport as "rest" if location is "global".
244+ if location == "global" and not api_transport :
245+ self ._api_transport = "rest"
246+ elif location == "global" and api_transport == "grpc" :
247+ raise ValueError (
248+ "api_transport cannot be 'grpc' when location is 'global'."
249+ )
242250 if experiment_description and experiment is None :
243251 raise ValueError (
244- "Experiment needs to be set in `init` in order to add experiment descriptions."
252+ "Experiment needs to be set in `init` in order to add experiment"
253+ " descriptions."
245254 )
246255
247256 # reset metadata_service config if project or location is updated.
@@ -464,8 +473,9 @@ def get_client_options(
464473 and not self ._project
465474 and not self ._location
466475 and not location_override
467- ):
468- # Default endpoint is location invariant if using API key
476+ ) or (self ._location == "global" ):
477+ # Default endpoint is location invariant if using API key or global
478+ # location.
469479 api_endpoint = "aiplatform.googleapis.com"
470480
471481 # If both project and API key are passed in, project takes precedence.
0 commit comments