diff --git a/setup.py b/setup.py index de356dcdd4..5b797d7a74 100644 --- a/setup.py +++ b/setup.py @@ -326,8 +326,7 @@ "google-cloud-storage >= 3.10.0, < 4.0.0; python_version>='3.13'", "google-cloud-bigquery >= 1.15.0, < 4.0.0, !=3.20.0", "google-cloud-resource-manager >= 1.3.3, < 3.0.0", - "google-genai >= 1.37.0, <2.0.0; python_version<'3.10'", - "google-genai >= 1.66.0, <2.0.0; python_version>='3.10'", + "google-genai >= 1.75.0, < 2.0.0", ) + genai_requires, extras_require={ diff --git a/testing/constraints-3.10.txt b/testing/constraints-3.10.txt index b931b4f348..dd356721ac 100644 --- a/testing/constraints-3.10.txt +++ b/testing/constraints-3.10.txt @@ -2,7 +2,7 @@ # This constraints file is required for unit tests. # List all library dependencies and extras in this file. google-api-core==2.21.0 # Tests google-api-core with rest async support -google-auth==2.47.0 # Tests google-auth with rest async support +google-auth==2.49.0 # Updated to satisfy google-genai 2.0.0 requirement proto-plus==1.22.3 protobuf mock==4.0.2 diff --git a/testing/constraints-3.11.txt b/testing/constraints-3.11.txt index 205412f0e5..cde565badd 100644 --- a/testing/constraints-3.11.txt +++ b/testing/constraints-3.11.txt @@ -2,7 +2,7 @@ # This constraints file is required for unit tests. # List all library dependencies and extras in this file. google-api-core==2.21.0 # Tests google-api-core with rest async support -google-auth==2.47.0 # Tests google-auth with rest async support +google-auth==2.49.0 # Updated to satisfy google-genai 2.0.0 requirement proto-plus protobuf mock==4.0.2 diff --git a/testing/constraints-3.12.txt b/testing/constraints-3.12.txt index 35b3def89d..aa22536bdf 100644 --- a/testing/constraints-3.12.txt +++ b/testing/constraints-3.12.txt @@ -2,7 +2,7 @@ # This constraints file is required for unit tests. # List all library dependencies and extras in this file. google-api-core==2.21.0 # Tests google-api-core with rest async support -google-auth==2.47.0 # Tests google-auth with rest async support +google-auth==2.49.0 # Updated to satisfy google-genai 2.0.0 requirement proto-plus mock==4.0.2 google-cloud-storage==3.0.0 # Updated to v3.x, backward compatible with v2.x via wrapper diff --git a/testing/constraints-3.13.txt b/testing/constraints-3.13.txt index ecc94df9ac..b1f0db5130 100644 --- a/testing/constraints-3.13.txt +++ b/testing/constraints-3.13.txt @@ -2,7 +2,7 @@ # This constraints file is required for unit tests. # List all library dependencies and extras in this file. google-api-core==2.27.0 # Tests google-api-core with rest async support -google-auth==2.47.0 # Tests google-auth with rest async support +google-auth==2.49.0 # Updated to satisfy google-genai 2.0.0 requirement proto-plus mock==4.0.2 google-cloud-storage==3.10.0 # Updated to v3.x, backward compatible with v2.x via wrapper diff --git a/testing/constraints-3.14.txt b/testing/constraints-3.14.txt index d3d2ea38b7..be613a2606 100644 --- a/testing/constraints-3.14.txt +++ b/testing/constraints-3.14.txt @@ -2,7 +2,7 @@ # This constraints file is required for unit tests. # List all library dependencies and extras in this file. google-api-core==2.27.0 -google-auth==2.47.0 # Tests google-auth with rest async support +google-auth==2.49.0 # Updated to satisfy google-genai 2.0.0 requirement proto-plus mock==4.0.2 google-cloud-storage==3.10.0 # Updated for Python 3.14 compatibility diff --git a/tests/unit/vertexai/genai/replays/conftest.py b/tests/unit/vertexai/genai/replays/conftest.py index 0f9eed0c5b..11aa555552 100644 --- a/tests/unit/vertexai/genai/replays/conftest.py +++ b/tests/unit/vertexai/genai/replays/conftest.py @@ -26,7 +26,6 @@ from vertexai._genai.client import ( _GENAI_MODULES_TELEMETRY_HEADER, ) -from google.cloud.aiplatform import version as aip_version from google.cloud import storage, bigquery from google.genai import _replay_api_client from google.genai import types as genai_types @@ -265,10 +264,6 @@ def client(use_vertex, replays_prefix, http_options, request): if http_options.headers is None: http_options.headers = {} - tracking_label = f"{_GENAI_MODULES_TELEMETRY_HEADER}/{aip_version.__version__}" - http_options.headers["user-agent"] = tracking_label - http_options.headers["x-goog-api-client"] = tracking_label - replay_client = _replay_api_client.ReplayApiClient( mode=mode, replay_id=replay_id, diff --git a/vertexai/_genai/client.py b/vertexai/_genai/client.py index 77d8a9aadc..ba6b6515ac 100644 --- a/vertexai/_genai/client.py +++ b/vertexai/_genai/client.py @@ -15,6 +15,7 @@ import asyncio import importlib +import sys from typing import Optional, Union, TYPE_CHECKING from types import TracebackType, ModuleType @@ -23,6 +24,8 @@ from google.genai import _common from google.genai import client as genai_client from google.genai import types +from google.genai import version as genai_version +from google.genai import _api_client as genai_api_client from . import live if TYPE_CHECKING: @@ -42,6 +45,32 @@ _GENAI_MODULES_TELEMETRY_HEADER = "vertex-genai-modules" +def _custom_append_library_version_headers(headers: dict[str, str]) -> None: + """Overridde GenAI SDK header injection to use custom vertex-genai-modules header.""" + genai_sdk_version = genai_version.__version__ + module_version = aip_version.__version__ + python_version = sys.version.split()[0] + + combined_label = f"google-genai-sdk/{genai_sdk_version}+{_GENAI_MODULES_TELEMETRY_HEADER}/{module_version}" + full_header = f"{combined_label} gl-python/{python_version}" + + if "user-agent" not in headers or combined_label not in headers["user-agent"]: + headers["user-agent"] = f"{full_header} " + headers.get("user-agent", "") + headers["user-agent"] = headers["user-agent"].strip() + + if ( + "x-goog-api-client" not in headers + or combined_label not in headers["x-goog-api-client"] + ): + headers["x-goog-api-client"] = f"{full_header} " + headers.get( + "x-goog-api-client", "" + ) + headers["x-goog-api-client"] = headers["x-goog-api-client"].strip() + + +genai_api_client.append_library_version_headers = _custom_append_library_version_headers + + class AsyncClient: """Async Gen AI Client for the Vertex SDK.""" @@ -219,22 +248,6 @@ def __init__( if http_options.headers is None: http_options.headers = {} - tracking_label = f"{_GENAI_MODULES_TELEMETRY_HEADER}/{aip_version.__version__}" - - if "user-agent" in http_options.headers: - http_options.headers["user-agent"] = ( - f"{http_options.headers['user-agent']} {tracking_label}" - ) - else: - http_options.headers["user-agent"] = tracking_label - - if "x-goog-api-client" in http_options.headers: - http_options.headers["x-goog-api-client"] = ( - f"{http_options.headers['x-goog-api-client']} {tracking_label}" - ) - else: - http_options.headers["x-goog-api-client"] = tracking_label - self._api_client = genai_client.Client._get_api_client( vertexai=True, api_key=api_key,