From 388ebe9d90bae85221768efffc2049c8af5b5d9c Mon Sep 17 00:00:00 2001 From: Sara Robinson Date: Fri, 1 May 2026 07:08:17 -0700 Subject: [PATCH] chore: Update headers PiperOrigin-RevId: 908716648 --- tests/unit/vertexai/genai/replays/conftest.py | 8 -------- vertexai/_genai/client.py | 17 ++++++++++++----- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/tests/unit/vertexai/genai/replays/conftest.py b/tests/unit/vertexai/genai/replays/conftest.py index 0f9eed0c5b..fb002b311c 100644 --- a/tests/unit/vertexai/genai/replays/conftest.py +++ b/tests/unit/vertexai/genai/replays/conftest.py @@ -23,10 +23,6 @@ client as vertexai_genai_client_module, ) from vertexai._genai import _agent_engines_utils -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 +261,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 2e43782554..0e758e239e 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 _api_client as genai_api_client +from google.genai import version as genai_version from . import live if TYPE_CHECKING: @@ -208,21 +211,25 @@ def __init__( if http_options.headers is None: http_options.headers = {} - tracking_label = f"{_GENAI_MODULES_TELEMETRY_HEADER}/{aip_version.__version__}" + genai_sdk_version = genai_version.__version__ + module_version = aip_version.__version__ + python_version = sys.version.split()[0] + + agent_platform_header = f"google-genai-sdk/{genai_sdk_version}+{_GENAI_MODULES_TELEMETRY_HEADER}/{module_version} gl-python/{python_version}" if "user-agent" in http_options.headers: http_options.headers["user-agent"] = ( - f"{http_options.headers['user-agent']} {tracking_label}" + f"{agent_platform_header} " + http_options.headers["user-agent"] ) else: - http_options.headers["user-agent"] = tracking_label + http_options.headers["user-agent"] = agent_platform_header 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}" + f"{agent_platform_header} " + http_options.headers["x-goog-api-client"] ) else: - http_options.headers["x-goog-api-client"] = tracking_label + http_options.headers["x-goog-api-client"] = agent_platform_header self._api_client = genai_client.Client._get_api_client( vertexai=True,