fix: merge tracking headers even when llm_request.config.http_options is not set in Gemini.generate_content_async

PiperOrigin-RevId: 788568620
This commit is contained in:
Xuan Yang
2025-07-29 12:52:32 -07:00
committed by Copybara-Service
parent 646eb42533
commit ec8dd5721a
2 changed files with 60 additions and 200 deletions
+6 -3
View File
@@ -116,9 +116,12 @@ class Gemini(BaseLlm):
)
logger.debug(_build_request_log(llm_request))
# add tracking headers to custom headers given it will override the headers
# set in the api client constructor
if llm_request.config and llm_request.config.http_options:
# Always add tracking headers to custom headers given it will override
# the headers set in the api client constructor to avoid tracking headers
# being dropped if user provides custom headers or overrides the api client.
if llm_request.config:
if not llm_request.config.http_options:
llm_request.config.http_options = types.HttpOptions()
if not llm_request.config.http_options.headers:
llm_request.config.http_options.headers = {}
llm_request.config.http_options.headers.update(self._tracking_headers)