mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
Requests through Vercel AI Gateway now carry referrerUrl / appName / User-Agent attribution so traffic shows up in the gateway's analytics. Adds _AI_GATEWAY_HEADERS in auxiliary_client and a new ai-gateway.vercel.sh branch in _apply_client_headers_for_base_url.
65 lines
2.1 KiB
Python
65 lines
2.1 KiB
Python
"""Attribution default_headers applied per provider via base-URL detection.
|
|
|
|
Mirrors the OpenRouter pattern for the Vercel AI Gateway so that
|
|
referrerUrl / appName / User-Agent flow into gateway analytics.
|
|
"""
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from run_agent import AIAgent
|
|
|
|
|
|
@patch("run_agent.OpenAI")
|
|
def test_openrouter_base_url_applies_or_headers(mock_openai):
|
|
mock_openai.return_value = MagicMock()
|
|
agent = AIAgent(
|
|
api_key="test-key",
|
|
base_url="https://openrouter.ai/api/v1",
|
|
model="test/model",
|
|
quiet_mode=True,
|
|
skip_context_files=True,
|
|
skip_memory=True,
|
|
)
|
|
|
|
agent._apply_client_headers_for_base_url("https://openrouter.ai/api/v1")
|
|
|
|
headers = agent._client_kwargs["default_headers"]
|
|
assert headers["HTTP-Referer"] == "https://hermes-agent.nousresearch.com"
|
|
assert headers["X-OpenRouter-Title"] == "Hermes Agent"
|
|
|
|
|
|
@patch("run_agent.OpenAI")
|
|
def test_ai_gateway_base_url_applies_attribution_headers(mock_openai):
|
|
mock_openai.return_value = MagicMock()
|
|
agent = AIAgent(
|
|
api_key="test-key",
|
|
base_url="https://openrouter.ai/api/v1",
|
|
model="test/model",
|
|
quiet_mode=True,
|
|
skip_context_files=True,
|
|
skip_memory=True,
|
|
)
|
|
|
|
agent._apply_client_headers_for_base_url("https://ai-gateway.vercel.sh/v1")
|
|
|
|
headers = agent._client_kwargs["default_headers"]
|
|
assert headers["HTTP-Referer"] == "https://hermes-agent.nousresearch.com"
|
|
assert headers["X-Title"] == "Hermes Agent"
|
|
assert headers["User-Agent"].startswith("HermesAgent/")
|
|
|
|
|
|
@patch("run_agent.OpenAI")
|
|
def test_unknown_base_url_clears_default_headers(mock_openai):
|
|
mock_openai.return_value = MagicMock()
|
|
agent = AIAgent(
|
|
api_key="test-key",
|
|
base_url="https://openrouter.ai/api/v1",
|
|
model="test/model",
|
|
quiet_mode=True,
|
|
skip_context_files=True,
|
|
skip_memory=True,
|
|
)
|
|
agent._client_kwargs["default_headers"] = {"X-Stale": "yes"}
|
|
|
|
agent._apply_client_headers_for_base_url("https://api.example.com/v1")
|
|
|
|
assert "default_headers" not in agent._client_kwargs
|