Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand Down
2 changes: 1 addition & 1 deletion testing/constraints-3.10.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion testing/constraints-3.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion testing/constraints-3.12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion testing/constraints-3.13.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion testing/constraints-3.14.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions tests/unit/vertexai/genai/replays/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
45 changes: 29 additions & 16 deletions vertexai/_genai/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import asyncio
import importlib
import sys
from typing import Optional, Union, TYPE_CHECKING
from types import TracebackType, ModuleType

Expand All @@ -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:
Expand All @@ -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."""

Expand Down Expand Up @@ -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,
Expand Down
Loading