File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- # type: ignore
2-
31# Copyright 2025 Google LLC
42#
53# Licensed under the Apache License, Version 2.0 (the "License");
1917from typing import Optional , Union
2018
2119import google .auth
20+ from google .cloud .aiplatform import version as aip_version
21+ from google .genai import _api_client
2222from google .genai import _common
2323from google .genai import client as genai_client
2424from 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+
2747class AsyncClient :
2848
2949 """Async Client for the GenAI SDK."""
You can’t perform that action at this time.
0 commit comments