Skip to content

Commit 943c1e4

Browse files
sararobcopybara-github
authored andcommitted
chore: GenAI SDK client - Add new tool name to request headers
PiperOrigin-RevId: 785510006
1 parent 1ceb2e1 commit 943c1e4

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

vertexai/_genai/client.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# type: ignore
2-
31
# Copyright 2025 Google LLC
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,11 +17,33 @@
1917
from typing import Optional, Union
2018

2119
import google.auth
20+
from google.cloud.aiplatform import version as aip_version
21+
from google.genai import _api_client
2222
from google.genai import _common
2323
from google.genai import client as genai_client
2424
from google.genai import types
2525

2626

27+
_GENAI_MODULES_TELEMETRY_HEADER = "vertex-genai-modules"
28+
29+
30+
def _add_tracking_headers(headers: dict[str, str]) -> None:
31+
"""Appends Vertex Gen AI modules tracking information to the request headers."""
32+
33+
tracking_label = f"{_GENAI_MODULES_TELEMETRY_HEADER}/{aip_version.__version__}"
34+
35+
user_agent = headers.get("user-agent", "")
36+
if tracking_label not in user_agent:
37+
headers["user-agent"] = f"{user_agent} {tracking_label}".strip()
38+
39+
api_client = headers.get("x-goog-api-client", "")
40+
if tracking_label not in api_client:
41+
headers["x-goog-api-client"] = f"{api_client} {tracking_label}".strip()
42+
43+
44+
_api_client._append_library_version_headers = _add_tracking_headers
45+
46+
2747
class AsyncClient:
2848

2949
"""Async Client for the GenAI SDK."""

0 commit comments

Comments
 (0)