Skip to content

Commit cfdd200

Browse files
sararobcopybara-github
authored andcommitted
chore: Update headers
PiperOrigin-RevId: 908716648
1 parent 1f9c8e0 commit cfdd200

8 files changed

Lines changed: 35 additions & 28 deletions

File tree

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@
326326
"google-cloud-storage >= 3.10.0, < 4.0.0; python_version>='3.13'",
327327
"google-cloud-bigquery >= 1.15.0, < 4.0.0, !=3.20.0",
328328
"google-cloud-resource-manager >= 1.3.3, < 3.0.0",
329-
"google-genai >= 1.37.0, <2.0.0; python_version<'3.10'",
330-
"google-genai >= 1.66.0, <2.0.0; python_version>='3.10'",
329+
"google-genai >= 1.75.0, < 2.0.0",
331330
)
332331
+ genai_requires,
333332
extras_require={

testing/constraints-3.10.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This constraints file is required for unit tests.
33
# List all library dependencies and extras in this file.
44
google-api-core==2.21.0 # Tests google-api-core with rest async support
5-
google-auth==2.47.0 # Tests google-auth with rest async support
5+
google-auth==2.49.0 # Updated to satisfy google-genai 2.0.0 requirement
66
proto-plus==1.22.3
77
protobuf
88
mock==4.0.2

testing/constraints-3.11.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This constraints file is required for unit tests.
33
# List all library dependencies and extras in this file.
44
google-api-core==2.21.0 # Tests google-api-core with rest async support
5-
google-auth==2.47.0 # Tests google-auth with rest async support
5+
google-auth==2.49.0 # Updated to satisfy google-genai 2.0.0 requirement
66
proto-plus
77
protobuf
88
mock==4.0.2

testing/constraints-3.12.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This constraints file is required for unit tests.
33
# List all library dependencies and extras in this file.
44
google-api-core==2.21.0 # Tests google-api-core with rest async support
5-
google-auth==2.47.0 # Tests google-auth with rest async support
5+
google-auth==2.49.0 # Updated to satisfy google-genai 2.0.0 requirement
66
proto-plus
77
mock==4.0.2
88
google-cloud-storage==3.0.0 # Updated to v3.x, backward compatible with v2.x via wrapper

testing/constraints-3.13.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This constraints file is required for unit tests.
33
# List all library dependencies and extras in this file.
44
google-api-core==2.27.0 # Tests google-api-core with rest async support
5-
google-auth==2.47.0 # Tests google-auth with rest async support
5+
google-auth==2.49.0 # Updated to satisfy google-genai 2.0.0 requirement
66
proto-plus
77
mock==4.0.2
88
google-cloud-storage==3.10.0 # Updated to v3.x, backward compatible with v2.x via wrapper

testing/constraints-3.14.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This constraints file is required for unit tests.
33
# List all library dependencies and extras in this file.
44
google-api-core==2.27.0
5-
google-auth==2.47.0 # Tests google-auth with rest async support
5+
google-auth==2.49.0 # Updated to satisfy google-genai 2.0.0 requirement
66
proto-plus
77
mock==4.0.2
88
google-cloud-storage==3.10.0 # Updated for Python 3.14 compatibility

tests/unit/vertexai/genai/replays/conftest.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from vertexai._genai.client import (
2727
_GENAI_MODULES_TELEMETRY_HEADER,
2828
)
29-
from google.cloud.aiplatform import version as aip_version
3029
from google.cloud import storage, bigquery
3130
from google.genai import _replay_api_client
3231
from google.genai import types as genai_types
@@ -265,10 +264,6 @@ def client(use_vertex, replays_prefix, http_options, request):
265264
if http_options.headers is None:
266265
http_options.headers = {}
267266

268-
tracking_label = f"{_GENAI_MODULES_TELEMETRY_HEADER}/{aip_version.__version__}"
269-
http_options.headers["user-agent"] = tracking_label
270-
http_options.headers["x-goog-api-client"] = tracking_label
271-
272267
replay_client = _replay_api_client.ReplayApiClient(
273268
mode=mode,
274269
replay_id=replay_id,

vertexai/_genai/client.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import asyncio
1717
import importlib
18+
import sys
1819
from typing import Optional, Union, TYPE_CHECKING
1920
from types import TracebackType, ModuleType
2021

@@ -23,6 +24,8 @@
2324
from google.genai import _common
2425
from google.genai import client as genai_client
2526
from google.genai import types
27+
from google.genai import version as genai_version
28+
from google.genai import _api_client as genai_api_client
2629
from . import live
2730

2831
if TYPE_CHECKING:
@@ -42,6 +45,32 @@
4245
_GENAI_MODULES_TELEMETRY_HEADER = "vertex-genai-modules"
4346

4447

48+
def _custom_append_library_version_headers(headers: dict[str, str]) -> None:
49+
"""Overridde GenAI SDK header injection to use custom vertex-genai-modules header."""
50+
genai_sdk_version = genai_version.__version__
51+
module_version = aip_version.__version__
52+
python_version = sys.version.split()[0]
53+
54+
combined_label = f"google-genai-sdk/{genai_sdk_version}+{_GENAI_MODULES_TELEMETRY_HEADER}/{module_version}"
55+
full_header = f"{combined_label} gl-python/{python_version}"
56+
57+
if "user-agent" not in headers or combined_label not in headers["user-agent"]:
58+
headers["user-agent"] = f"{full_header} " + headers.get("user-agent", "")
59+
headers["user-agent"] = headers["user-agent"].strip()
60+
61+
if (
62+
"x-goog-api-client" not in headers
63+
or combined_label not in headers["x-goog-api-client"]
64+
):
65+
headers["x-goog-api-client"] = f"{full_header} " + headers.get(
66+
"x-goog-api-client", ""
67+
)
68+
headers["x-goog-api-client"] = headers["x-goog-api-client"].strip()
69+
70+
71+
genai_api_client.append_library_version_headers = _custom_append_library_version_headers
72+
73+
4574
class AsyncClient:
4675
"""Async Gen AI Client for the Vertex SDK."""
4776

@@ -219,22 +248,6 @@ def __init__(
219248
if http_options.headers is None:
220249
http_options.headers = {}
221250

222-
tracking_label = f"{_GENAI_MODULES_TELEMETRY_HEADER}/{aip_version.__version__}"
223-
224-
if "user-agent" in http_options.headers:
225-
http_options.headers["user-agent"] = (
226-
f"{http_options.headers['user-agent']} {tracking_label}"
227-
)
228-
else:
229-
http_options.headers["user-agent"] = tracking_label
230-
231-
if "x-goog-api-client" in http_options.headers:
232-
http_options.headers["x-goog-api-client"] = (
233-
f"{http_options.headers['x-goog-api-client']} {tracking_label}"
234-
)
235-
else:
236-
http_options.headers["x-goog-api-client"] = tracking_label
237-
238251
self._api_client = genai_client.Client._get_api_client(
239252
vertexai=True,
240253
api_key=api_key,

0 commit comments

Comments
 (0)