Skip to content

fix(providers): support Anthropic proxy v1 endpoints - #45842

Merged
teknium1 merged 1 commit into
NousResearch:mainfrom
helix4u:codex/anthropic-proxy-v1-endpoints
Jun 14, 2026
Merged

fix(providers): support Anthropic proxy v1 endpoints#45842
teknium1 merged 1 commit into
NousResearch:mainfrom
helix4u:codex/anthropic-proxy-v1-endpoints

Conversation

@helix4u

@helix4u helix4u commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Supports Anthropic-compatible proxy base URLs that already include the version segment, such as http://localhost:6655/anthropic/v1.

Hermes already supports custom/proxy endpoints and Anthropic Messages transport, but auto-detection only recognized URLs whose path ended exactly in /anthropic. Versioned proxy base URLs fell through to OpenAI chat-completions routing, which builds requests like /anthropic/v1/chat/completions instead of using the Anthropic Messages client.

This also makes model discovery respect the configured Anthropic/custom proxy base URL and Desktop-saved model.api_key, so the picker can query /anthropic/v1/models on the proxy instead of public Anthropic or an OpenAI-style catalog probe.

Adjacent PRs checked before this change: #43988, #37656, #30232, #37705. Those cover related URL/probe/base-url handling, but not the combined /anthropic/v1 transport detection plus configured proxy model catalog path fixed here.

Related Issue

None filed from the support thread.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • Tests (adding or improving test coverage)

Changes Made

  • hermes_cli/runtime_provider.py: detect /anthropic/v1 base URLs as anthropic_messages while keeping deeper subpaths like /anthropic/v1/models out of transport detection.
  • agent/auxiliary_client.py: mirror the same detection for auxiliary clients.
  • agent/anthropic_adapter.py: strip a trailing /v1 before constructing the regular Anthropic SDK client, matching the bearer-hook path, so SDK requests still land on /anthropic/v1/messages rather than /anthropic/v1/v1/messages.
  • hermes_cli/models.py: let Anthropic model discovery use configured model.base_url / model.api_key, and let custom provider discovery pass api_mode="anthropic_messages" for /anthropic/v1 proxy catalogs.
  • Tests: added focused coverage for runtime detection, auxiliary detection, Anthropic SDK base URL normalization, and proxy catalog discovery.

How to Test

  1. Configure an Anthropic-compatible proxy at http://localhost:6655/anthropic/v1.
  2. Set the model provider/base URL through Desktop or config with api_mode: anthropic_messages.
  3. Verify runtime calls use Anthropic Messages transport and model discovery probes http://localhost:6655/anthropic/v1/models with the saved key.
  4. Run scripts/run_tests.sh -j 4 tests/hermes_cli/test_detect_api_mode_for_url.py tests/agent/test_auxiliary_transport_autodetect.py tests/agent/test_anthropic_adapter.py tests/hermes_cli/test_model_validation.py -- -q.

Checklist

Code

  • I have read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this is not a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I have run pytest tests/ -q and all tests pass
  • I have added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I have tested on my platform: WSL/Linux targeted test runner

Documentation & Housekeeping

  • I have updated relevant documentation (README, docs/, docstrings) - or N/A
  • I have updated cli-config.yaml.example if I added/changed config keys - or N/A
  • I have updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows - or N/A
  • I have considered cross-platform impact (Windows, macOS) per the compatibility guide - or N/A
  • I have updated tool descriptions/schemas if I changed tool behavior - or N/A

Screenshots / Logs

Focused test run:

scripts/run_tests.sh -j 4 tests/hermes_cli/test_detect_api_mode_for_url.py tests/agent/test_auxiliary_transport_autodetect.py tests/agent/test_anthropic_adapter.py tests/hermes_cli/test_model_validation.py -- -q

Result: 4 files, 279 tests passed, 0 failed.

@helix4u
helix4u marked this pull request as ready for review June 13, 2026 22:05
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/anthropic Anthropic native Messages API area/config Config system, migrations, profiles labels Jun 13, 2026
@liuhao1024

Copy link
Copy Markdown
Contributor

Verified clean. Reviewed the full diff across all 8 files:

  • URL normalization: build_anthropic_client strips trailing /v1 via regex — correct for the Anthropic SDK which appends /v1/messages itself. Test confirms https://proxy.example.com/anthropic/v1https://proxy.example.com/anthropic.
  • Endpoint detection: _endpoint_speaks_anthropic_messages, _detect_api_mode_for_url, and _base_url_looks_like_anthropic_messages all use urlparse().path instead of endswith() — properly distinguishes /anthropic/v1 (base endpoint) from /anthropic/v1/models (subpath). Test coverage includes both cases.
  • Live model catalog: _fetch_anthropic_models now accepts base_url and api_key parameters, and provider_model_ids("anthropic") passes them from config. validate_requested_model does the same. Custom endpoints with anthropic_messages api_mode now get proper model discovery.
  • Test coverage: 6 new tests across 3 test files covering URL normalization, endpoint detection edge cases, and live catalog routing.

No dead variables, no broad exception catches hiding issues, no missing None guards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have provider/anthropic Anthropic native Messages API type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants