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
8 changes: 0 additions & 8 deletions tests/unit/vertexai/genai/replays/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 12 additions & 5 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 _api_client as genai_api_client
from google.genai import version as genai_version
from . import live

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