@@ -231,17 +231,26 @@ def init(
231
231
f"{ api_transport } is not a valid transport type. "
232
232
+ f"Valid transport types: { VALID_TRANSPORT_TYPES } "
233
233
)
234
- else :
235
234
# 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 :
236
238
if not project and not api_transport :
237
239
api_transport = "rest"
238
- elif not project and api_transport != "rest" :
239
- raise ValueError (f"{ api_transport } is not supported with API keys. " )
240
+
240
241
if location :
241
242
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
+ )
242
250
if experiment_description and experiment is None :
243
251
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."
245
254
)
246
255
247
256
# reset metadata_service config if project or location is updated.
@@ -464,8 +473,9 @@ def get_client_options(
464
473
and not self ._project
465
474
and not self ._location
466
475
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.
469
479
api_endpoint = "aiplatform.googleapis.com"
470
480
471
481
# If both project and API key are passed in, project takes precedence.
0 commit comments