Skip to content

Commit a08a69d

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: Release API key support for Predict
PiperOrigin-RevId: 734290755
1 parent 8cbea81 commit a08a69d

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

google/cloud/aiplatform/models.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -699,15 +699,19 @@ def __init__(
699699

700700
@property
701701
def _prediction_client(self) -> utils.PredictionClientWithOverride:
702+
api_key = initializer.global_config.api_key
703+
if api_key and initializer.global_config.project:
704+
api_key = None
702705
# The attribute might not exist due to issues in
703706
# `VertexAiResourceNounWithFutureManager._sync_object_with_future_result`
704707
# We should switch to @functools.cached_property once its available.
705708
if not getattr(self, "_prediction_client_value", None):
706709
self._prediction_client_value = initializer.global_config.create_client(
707710
client_class=utils.PredictionClientWithOverride,
708711
credentials=self.credentials,
709-
location_override=self.location,
712+
location_override=self.location if not api_key else None,
710713
prediction_client=True,
714+
api_key=api_key,
711715
)
712716
return self._prediction_client_value
713717

google/cloud/aiplatform_v1/services/prediction_service/client.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,19 @@ def endpoint_path(
249249
endpoint: str,
250250
) -> str:
251251
"""Returns a fully-qualified endpoint string."""
252-
return "projects/{project}/locations/{location}/endpoints/{endpoint}".format(
253-
project=project,
254-
location=location,
255-
endpoint=endpoint,
256-
)
252+
if project == "None":
253+
return "endpoints/{endpoint}".format(
254+
endpoint=endpoint,
255+
)
256+
else:
257+
return (
258+
"projects/{project}/locations/{location}/endpoints/{endpoint}"
259+
.format(
260+
project=project,
261+
location=location,
262+
endpoint=endpoint,
263+
)
264+
)
257265

258266
@staticmethod
259267
def parse_endpoint_path(path: str) -> Dict[str, str]:

0 commit comments

Comments
 (0)