fix: allow Anthropic API URLs as custom OpenAI-compatible endpoints
Removed the hard block on base_url containing 'api.anthropic.com'. Anthropic now offers an OpenAI-compatible /chat/completions endpoint, so blocking their URL prevents legitimate use. If the endpoint isn't compatible, the API call will fail with a proper error anyway. Removed from: run_agent.py, mini_swe_runner.py Updated test to verify Anthropic URLs are accepted.
This commit is contained in:
parent
76545ab365
commit
19b6f81ee7
3 changed files with 12 additions and 25 deletions
|
|
@ -200,13 +200,7 @@ class MiniSWERunner:
|
||||||
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's native /v1/messages API is not supported yet (planned for a future release). "
|
|
||||||
"Hermes currently requires OpenAI-compatible /chat/completions endpoints. "
|
|
||||||
"To use Claude models now, route through OpenRouter (OPENROUTER_API_KEY) "
|
|
||||||
"or any OpenAI-compatible proxy that wraps the Anthropic API."
|
|
||||||
)
|
|
||||||
|
|
||||||
# Handle API key - OpenRouter is the primary provider
|
# Handle API key - OpenRouter is the primary provider
|
||||||
if api_key:
|
if api_key:
|
||||||
|
|
|
||||||
|
|
@ -253,13 +253,7 @@ class AIAgent:
|
||||||
self.provider = "openai-codex"
|
self.provider = "openai-codex"
|
||||||
else:
|
else:
|
||||||
self.api_mode = "chat_completions"
|
self.api_mode = "chat_completions"
|
||||||
if base_url and "api.anthropic.com" in base_url.strip().lower():
|
|
||||||
raise ValueError(
|
|
||||||
"Anthropic's native /v1/messages API is not supported yet (planned for a future release). "
|
|
||||||
"Hermes currently requires OpenAI-compatible /chat/completions endpoints. "
|
|
||||||
"To use Claude models now, route through OpenRouter (OPENROUTER_API_KEY) "
|
|
||||||
"or any OpenAI-compatible proxy that wraps the Anthropic API."
|
|
||||||
)
|
|
||||||
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.step_callback = step_callback
|
self.step_callback = step_callback
|
||||||
|
|
|
||||||
|
|
@ -280,22 +280,21 @@ class TestMaskApiKey:
|
||||||
|
|
||||||
|
|
||||||
class TestInit:
|
class TestInit:
|
||||||
def test_anthropic_base_url_fails_fast(self):
|
def test_anthropic_base_url_accepted(self):
|
||||||
"""Anthropic native endpoints should error before building an OpenAI client."""
|
"""Anthropic base URLs should be accepted (OpenAI-compatible endpoint)."""
|
||||||
with (
|
with (
|
||||||
patch("run_agent.get_tool_definitions", return_value=[]),
|
patch("run_agent.get_tool_definitions", return_value=[]),
|
||||||
patch("run_agent.check_toolset_requirements", return_value={}),
|
patch("run_agent.check_toolset_requirements", return_value={}),
|
||||||
patch("run_agent.OpenAI") as mock_openai,
|
patch("run_agent.OpenAI") as mock_openai,
|
||||||
):
|
):
|
||||||
with pytest.raises(ValueError, match="not supported yet"):
|
|
||||||
AIAgent(
|
AIAgent(
|
||||||
api_key="test-key-1234567890",
|
api_key="test-key-1234567890",
|
||||||
base_url="https://api.anthropic.com/v1/messages",
|
base_url="https://api.anthropic.com/v1/",
|
||||||
quiet_mode=True,
|
quiet_mode=True,
|
||||||
skip_context_files=True,
|
skip_context_files=True,
|
||||||
skip_memory=True,
|
skip_memory=True,
|
||||||
)
|
)
|
||||||
mock_openai.assert_not_called()
|
mock_openai.assert_called_once()
|
||||||
|
|
||||||
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."""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue