Skip to content

Commit 19b6f81

Browse files
committed
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.
1 parent 76545ab commit 19b6f81

3 files changed

Lines changed: 12 additions & 25 deletions

File tree

mini_swe_runner.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,7 @@ def __init__(
200200
else:
201201
client_kwargs["base_url"] = "https://openrouter.ai/api/v1"
202202

203-
if base_url and "api.anthropic.com" in base_url.strip().lower():
204-
raise ValueError(
205-
"Anthropic's native /v1/messages API is not supported yet (planned for a future release). "
206-
"Hermes currently requires OpenAI-compatible /chat/completions endpoints. "
207-
"To use Claude models now, route through OpenRouter (OPENROUTER_API_KEY) "
208-
"or any OpenAI-compatible proxy that wraps the Anthropic API."
209-
)
203+
210204

211205
# Handle API key - OpenRouter is the primary provider
212206
if api_key:

run_agent.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,7 @@ def __init__(
253253
self.provider = "openai-codex"
254254
else:
255255
self.api_mode = "chat_completions"
256-
if base_url and "api.anthropic.com" in base_url.strip().lower():
257-
raise ValueError(
258-
"Anthropic's native /v1/messages API is not supported yet (planned for a future release). "
259-
"Hermes currently requires OpenAI-compatible /chat/completions endpoints. "
260-
"To use Claude models now, route through OpenRouter (OPENROUTER_API_KEY) "
261-
"or any OpenAI-compatible proxy that wraps the Anthropic API."
262-
)
256+
263257
self.tool_progress_callback = tool_progress_callback
264258
self.clarify_callback = clarify_callback
265259
self.step_callback = step_callback

tests/test_run_agent.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -280,22 +280,21 @@ def test_long_key_masked(self, agent):
280280

281281

282282
class TestInit:
283-
def test_anthropic_base_url_fails_fast(self):
284-
"""Anthropic native endpoints should error before building an OpenAI client."""
283+
def test_anthropic_base_url_accepted(self):
284+
"""Anthropic base URLs should be accepted (OpenAI-compatible endpoint)."""
285285
with (
286286
patch("run_agent.get_tool_definitions", return_value=[]),
287287
patch("run_agent.check_toolset_requirements", return_value={}),
288288
patch("run_agent.OpenAI") as mock_openai,
289289
):
290-
with pytest.raises(ValueError, match="not supported yet"):
291-
AIAgent(
292-
api_key="test-key-1234567890",
293-
base_url="https://api.anthropic.com/v1/messages",
294-
quiet_mode=True,
295-
skip_context_files=True,
296-
skip_memory=True,
297-
)
298-
mock_openai.assert_not_called()
290+
AIAgent(
291+
api_key="test-key-1234567890",
292+
base_url="https://api.anthropic.com/v1/",
293+
quiet_mode=True,
294+
skip_context_files=True,
295+
skip_memory=True,
296+
)
297+
mock_openai.assert_called_once()
299298

300299
def test_prompt_caching_claude_openrouter(self):
301300
"""Claude model via OpenRouter should enable prompt caching."""

0 commit comments

Comments
 (0)