From c7de192b29641f6bf3abc673e3b0af30beb20634 Mon Sep 17 00:00:00 2001 From: Gabby Ong Date: Fri, 9 Oct 2026 16:15:16 +0800 Subject: [PATCH 1/2] feat: include User-Agent request context header on generateContent calls Adds a static User-Agent header ('hermes-agent (gemini-image/0.1.0)') to outgoing generateContent requests for support and compatibility context without including any user or prompt metadata. Updates the generation unit test to assert the header is sent alongside x-goog-api-key. --- __init__.py | 8 +++++++- tests/test_gemini_provider.py | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/__init__.py b/__init__.py index b0d2d4d..9796e0b 100644 --- a/__init__.py +++ b/__init__.py @@ -46,6 +46,8 @@ BASE_URL = "https://generativelanguage.googleapis.com/v1beta" DEFAULT_MODEL = "gemini-nano-banana-2.1" +PLUGIN_VERSION = "0.1.0" +USER_AGENT = f"hermes-agent (gemini-image/{PLUGIN_VERSION})" _ASPECT_RATIOS = {"landscape": "16:9", "square": "1:1", "portrait": "9:16"} _GEMINI_RATIOS_10 = ( @@ -507,7 +509,11 @@ def generate( payload["tools"] = [{"googleSearch": {}}] url = f"{base_url}/models/{quote(meta['api_model'], safe='')}:generateContent" - headers = {"x-goog-api-key": api_key, "Content-Type": "application/json"} + headers = { + "x-goog-api-key": api_key, + "Content-Type": "application/json", + "User-Agent": USER_AGENT, + } body, failure = post_json( url, headers=headers, payload=payload, timeout=_DEFAULT_TIMEOUT, label="Google AI Studio", error_message=_extract_error_message, diff --git a/tests/test_gemini_provider.py b/tests/test_gemini_provider.py index e80ea5c..7fd228e 100644 --- a/tests/test_gemini_provider.py +++ b/tests/test_gemini_provider.py @@ -253,6 +253,8 @@ def test_b64_saves_to_cache_and_sends_x_goog_api_key_header(self, provider, tmp_ ) assert "key=" not in called_url assert mock_post.call_args.kwargs["headers"]["x-goog-api-key"] == "AQ.test-key" + assert mock_post.call_args.kwargs["headers"]["User-Agent"] == gemini_plugin.USER_AGENT + assert mock_post.call_args.kwargs["headers"]["User-Agent"].startswith("hermes-agent (gemini-image/") assert mock_post.call_args.kwargs["json"]["generationConfig"]["imageConfig"] == {"aspectRatio": "16:9"} @pytest.mark.parametrize("has_image", [True, False]) From 108ea28adf6581fbba25a0a98e890bc9cecf02a6 Mon Sep 17 00:00:00 2001 From: Gabby Ong Date: Sat, 10 Oct 2026 11:39:20 +0800 Subject: [PATCH 2/2] feat: include Hermes and plugin versions in User-Agent header Formats User-Agent as 'hermes-agent/ gemini-image/' using get_version_info().base_version so both versions can be tracked separately. Updates the unit test to verify both HERMES_VERSION and PLUGIN_VERSION are present in the header. --- __init__.py | 4 +++- tests/test_gemini_provider.py | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/__init__.py b/__init__.py index 9796e0b..3d8dea1 100644 --- a/__init__.py +++ b/__init__.py @@ -38,6 +38,7 @@ from agent.image_gen_provider import ( DEFAULT_ASPECT_RATIO, resolve_aspect_ratio, save_b64_image, success_response) from agent.secret_scope import get_secret +from hermes_cli.version_info import get_version_info from plugins.image_gen._common import ( StaticImageGenProvider, collect_source_images, error_factory, load_image_gen_config, post_json, prompt_required_error, record_token_usage, resolve_static_model) @@ -46,8 +47,9 @@ BASE_URL = "https://generativelanguage.googleapis.com/v1beta" DEFAULT_MODEL = "gemini-nano-banana-2.1" +HERMES_VERSION = f"hermes-agent/{get_version_info().base_version}" PLUGIN_VERSION = "0.1.0" -USER_AGENT = f"hermes-agent (gemini-image/{PLUGIN_VERSION})" +USER_AGENT = f"{HERMES_VERSION} gemini-image/{PLUGIN_VERSION}" _ASPECT_RATIOS = {"landscape": "16:9", "square": "1:1", "portrait": "9:16"} _GEMINI_RATIOS_10 = ( diff --git a/tests/test_gemini_provider.py b/tests/test_gemini_provider.py index 7fd228e..018041d 100644 --- a/tests/test_gemini_provider.py +++ b/tests/test_gemini_provider.py @@ -253,8 +253,10 @@ def test_b64_saves_to_cache_and_sends_x_goog_api_key_header(self, provider, tmp_ ) assert "key=" not in called_url assert mock_post.call_args.kwargs["headers"]["x-goog-api-key"] == "AQ.test-key" - assert mock_post.call_args.kwargs["headers"]["User-Agent"] == gemini_plugin.USER_AGENT - assert mock_post.call_args.kwargs["headers"]["User-Agent"].startswith("hermes-agent (gemini-image/") + ua = mock_post.call_args.kwargs["headers"]["User-Agent"] + assert ua == gemini_plugin.USER_AGENT + assert gemini_plugin.HERMES_VERSION in ua + assert f"gemini-image/{gemini_plugin.PLUGIN_VERSION}" in ua assert mock_post.call_args.kwargs["json"]["generationConfig"]["imageConfig"] == {"aspectRatio": "16:9"} @pytest.mark.parametrize("has_image", [True, False])