mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
fix(agent): fail fast on Anthropic native base URLs
This commit is contained in:
parent
de0829cec3
commit
0c0a2eb0a2
3 changed files with 30 additions and 0 deletions
|
|
@ -199,6 +199,13 @@ class MiniSWERunner:
|
||||||
client_kwargs["base_url"] = base_url
|
client_kwargs["base_url"] = base_url
|
||||||
else:
|
else:
|
||||||
client_kwargs["base_url"] = "https://openrouter.ai/api/v1"
|
client_kwargs["base_url"] = "https://openrouter.ai/api/v1"
|
||||||
|
|
||||||
|
if base_url and "api.anthropic.com" in base_url.strip().lower():
|
||||||
|
raise ValueError(
|
||||||
|
"Anthropic /v1/messages is not supported yet. "
|
||||||
|
"Hermes uses OpenAI-compatible /chat/completions. "
|
||||||
|
"Use OpenRouter or leave base_url unset."
|
||||||
|
)
|
||||||
|
|
||||||
# Handle API key - OpenRouter is the primary provider
|
# Handle API key - OpenRouter is the primary provider
|
||||||
if api_key:
|
if api_key:
|
||||||
|
|
|
||||||
|
|
@ -183,6 +183,12 @@ class AIAgent:
|
||||||
# Store effective base URL for feature detection (prompt caching, reasoning, etc.)
|
# Store effective base URL for feature detection (prompt caching, reasoning, etc.)
|
||||||
# When no base_url is provided, the client defaults to OpenRouter, so reflect that here.
|
# When no base_url is provided, the client defaults to OpenRouter, so reflect that here.
|
||||||
self.base_url = base_url or OPENROUTER_BASE_URL
|
self.base_url = base_url or OPENROUTER_BASE_URL
|
||||||
|
if base_url and "api.anthropic.com" in base_url.strip().lower():
|
||||||
|
raise ValueError(
|
||||||
|
"Anthropic /v1/messages is not supported yet. "
|
||||||
|
"Hermes uses OpenAI-compatible /chat/completions. "
|
||||||
|
"Use OpenRouter or leave base_url unset."
|
||||||
|
)
|
||||||
self.tool_progress_callback = tool_progress_callback
|
self.tool_progress_callback = tool_progress_callback
|
||||||
self.clarify_callback = clarify_callback
|
self.clarify_callback = clarify_callback
|
||||||
self._last_reported_tool = None # Track for "new tool" mode
|
self._last_reported_tool = None # Track for "new tool" mode
|
||||||
|
|
|
||||||
|
|
@ -278,6 +278,23 @@ class TestMaskApiKey:
|
||||||
|
|
||||||
|
|
||||||
class TestInit:
|
class TestInit:
|
||||||
|
def test_anthropic_base_url_fails_fast(self):
|
||||||
|
"""Anthropic native endpoints should error before building an OpenAI client."""
|
||||||
|
with (
|
||||||
|
patch("run_agent.get_tool_definitions", return_value=[]),
|
||||||
|
patch("run_agent.check_toolset_requirements", return_value={}),
|
||||||
|
patch("run_agent.OpenAI") as mock_openai,
|
||||||
|
):
|
||||||
|
with pytest.raises(ValueError, match="Anthropic /v1/messages is not supported yet"):
|
||||||
|
AIAgent(
|
||||||
|
api_key="test-key-1234567890",
|
||||||
|
base_url="https://api.anthropic.com/v1/messages",
|
||||||
|
quiet_mode=True,
|
||||||
|
skip_context_files=True,
|
||||||
|
skip_memory=True,
|
||||||
|
)
|
||||||
|
mock_openai.assert_not_called()
|
||||||
|
|
||||||
def test_prompt_caching_claude_openrouter(self):
|
def test_prompt_caching_claude_openrouter(self):
|
||||||
"""Claude model via OpenRouter should enable prompt caching."""
|
"""Claude model via OpenRouter should enable prompt caching."""
|
||||||
with (
|
with (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue