From ce2d3bed2aa0681c739dbe89787e383cc8c67d12 Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Thu, 18 Jun 2026 19:15:24 -0700 Subject: [PATCH] feat(gemini): extend x-goog-api-client to TTS path + cite Google requirement Follow-up to salvaged PR #47385. Google's partner-integration guidance requires platform/library clients to send the x-goog-api-client header (company-product/version) on Gemini API calls: https://ai.google.dev/gemini-api/docs/partner-integration - tools/tts_tool.py: add the header to the native Gemini TTS generateContent call (sibling site the original PR missed) - agent/gemini_native_adapter.py: cite the requirement doc inline - tests/tools/test_tts_gemini.py: assert the TTS header is present - scripts/release.py: AUTHOR_MAP entry for dharmadhikari@google.com --- agent/gemini_native_adapter.py | 3 +++ scripts/release.py | 1 + tests/tools/test_tts_gemini.py | 13 +++++++++++++ tools/tts_tool.py | 12 +++++++++++- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/agent/gemini_native_adapter.py b/agent/gemini_native_adapter.py index b9840d11467..25d40a76588 100644 --- a/agent/gemini_native_adapter.py +++ b/agent/gemini_native_adapter.py @@ -889,6 +889,9 @@ class GeminiNativeClient: "Content-Type": "application/json", "Accept": "application/json", "x-goog-api-key": self.api_key, + # Google requires platform/library clients to identify themselves + # via x-goog-api-client (company-product/version format). + # See https://ai.google.dev/gemini-api/docs/partner-integration "User-Agent": f"hermes-agent/{_HERMES_VERSION} (gemini-native)", "X-Goog-Api-Client": f"hermes-agent/{_HERMES_VERSION}", } diff --git a/scripts/release.py b/scripts/release.py index 6f56a14154d..08d1c2bca6f 100755 --- a/scripts/release.py +++ b/scripts/release.py @@ -475,6 +475,7 @@ AUTHOR_MAP = { "bzarnitz13@gmail.com": "Beandon13", "tony@tonysimons.dev": "asimons81", "jetha@google.com": "jethac", + "dharmadhikari@google.com": "vishal-dharm", "jani@0xhoneyjar.xyz": "deep-name", # LINE messaging plugin (synthesis PR) "32443648+leepoweii@users.noreply.github.com": "leepoweii", diff --git a/tests/tools/test_tts_gemini.py b/tests/tools/test_tts_gemini.py index 85254649d53..0c83f72d864 100644 --- a/tests/tools/test_tts_gemini.py +++ b/tests/tools/test_tts_gemini.py @@ -115,6 +115,19 @@ class TestGenerateGeminiTts: # Audio payload should match the PCM we put in assert data[44:] == fake_pcm_bytes + def test_x_goog_api_client_header_is_set(self, tmp_path, monkeypatch, mock_gemini_response): + """Google requires platform clients to send x-goog-api-client.""" + from tools.tts_tool import _generate_gemini_tts + + monkeypatch.setenv("GEMINI_API_KEY", "test-key") + + with patch("requests.post", return_value=mock_gemini_response) as mock_post: + _generate_gemini_tts("Hi", str(tmp_path / "test.wav"), {}) + + headers = mock_post.call_args[1]["headers"] + assert "X-Goog-Api-Client" in headers + assert headers["X-Goog-Api-Client"].startswith("hermes-agent/") + def test_default_voice_and_model(self, tmp_path, monkeypatch, mock_gemini_response): from tools.tts_tool import ( DEFAULT_GEMINI_TTS_MODEL, diff --git a/tools/tts_tool.py b/tools/tts_tool.py index c6e7c22de0f..8bb991a9e63 100644 --- a/tools/tts_tool.py +++ b/tools/tts_tool.py @@ -1617,11 +1617,21 @@ def _generate_gemini_tts(text: str, output_path: str, tts_config: Dict[str, Any] }, } + try: + from hermes_cli import __version__ as _hermes_version + except Exception: + _hermes_version = "0.0.0" + endpoint = f"{base_url}/models/{model}:generateContent" response = requests.post( endpoint, params={"key": api_key}, - headers={"Content-Type": "application/json"}, + headers={ + "Content-Type": "application/json", + # Google requires platform/library clients to identify themselves + # via x-goog-api-client. See https://ai.google.dev/gemini-api/docs/partner-integration + "X-Goog-Api-Client": f"hermes-agent/{_hermes_version}", + }, json=payload, timeout=60, )