Skip to content

fix: route api.anthropic.com custom providers through anthropic_messages on fallback - #49247

Closed
x9x9x9x9x9x91 wants to merge 1 commit into
NousResearch:mainfrom
x9x9x9x9x9x91:fix/anthropic-custom-provider-fallback
Closed

fix: route api.anthropic.com custom providers through anthropic_messages on fallback#49247
x9x9x9x9x9x91 wants to merge 1 commit into
NousResearch:mainfrom
x9x9x9x9x9x91:fix/anthropic-custom-provider-fallback

Conversation

@x9x9x9x9x9x91

Copy link
Copy Markdown
Contributor

Problem

On the fallback provider path, api_mode detection misses custom providers that point at the native Anthropic host (api.anthropic.com) without a /anthropic base-URL suffix.

The fallback resolver only matches:

elif fb_provider == "anthropic" or fb_base_url.rstrip("/").lower().endswith("/anthropic"):
    fb_api_mode = "anthropic_messages"

A custom provider (e.g. one named cron-anthropic) whose base_url is https://api.anthropic.com has neither provider == "anthropic" nor a /anthropic suffix, so it falls through to chat_completionsPOST /v1/chat/completions404 against the Anthropic host on every fallback.

The primary path already handles this correctly in determine_api_mode() by matching the host. The fallback path just doesn't mirror it.

Fix

Mirror the primary path's host check in the fallback resolver: also route to anthropic_messages when base_url_hostname(fb_base_url) == "api.anthropic.com".

elif (
    fb_provider == "anthropic"
    or fb_base_url.rstrip("/").lower().endswith("/anthropic")
    or base_url_hostname(fb_base_url) == "api.anthropic.com"
):
    fb_api_mode = "anthropic_messages"

Test

Adds tests/run_agent/test_provider_fallback.py covering a custom provider pointed at api.anthropic.com with no /anthropic suffix, asserting it resolves to anthropic_messages on fallback (not chat_completions). Full file: 23 passed.

Fixes the whole class — name match, suffix match, and host match — not just the one site.

…ges on fallback

The fallback activation path re-derived api_mode from the provider name and a
"/anthropic" URL-suffix check, missing custom providers (e.g. cron-anthropic)
that point at the native api.anthropic.com host with no path suffix. They
defaulted to chat_completions, so failover POSTed /v1/chat/completions and 404'd
on every attempt — the configured Anthropic fallback never actually worked.
Match the host the same way the primary path's determine_api_mode() already does.

Adds a regression test asserting an api.anthropic.com custom-provider fallback
entry resolves to anthropic_messages.
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/anthropic Anthropic native Messages API P2 Medium — degraded but workaround exists labels Jun 19, 2026
teknium1 added a commit that referenced this pull request Jul 1, 2026
…ction

Widen the salvaged #32243 fix to the try_activate_fallback path: a custom
provider pointed at the native api.anthropic.com host (no /anthropic path
suffix, name != anthropic) fell through to chat_completions -> POST
/v1/chat/completions -> 404. Match the host the same way determine_api_mode()
and _detect_api_mode_for_url() now do. Absorbs #49247.
teknium1 pushed a commit that referenced this pull request Jul 1, 2026
Pins that a custom provider on the native api.anthropic.com host resolves to
anthropic_messages on the try_activate_fallback path. From #49247.
teknium1 added a commit that referenced this pull request Jul 1, 2026
@teknium1

teknium1 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Merged via #56214, which fixes the same api.anthropic.com host-detection bug. Your try_activate_fallback fix was absorbed and your test cherry-picked with your authorship preserved (24cb80f). Both you and @xxxigm are credited — thanks for catching the fallback-path sibling site.

@teknium1 teknium1 closed this Jul 1, 2026
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
…ction

Widen the salvaged NousResearch#32243 fix to the try_activate_fallback path: a custom
provider pointed at the native api.anthropic.com host (no /anthropic path
suffix, name != anthropic) fell through to chat_completions -> POST
/v1/chat/completions -> 404. Match the host the same way determine_api_mode()
and _detect_api_mode_for_url() now do. Absorbs NousResearch#49247.
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
Pins that a custom provider on the native api.anthropic.com host resolves to
anthropic_messages on the try_activate_fallback path. From NousResearch#49247.
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
Jasper6439 pushed a commit to Jasper6439/hermes-agent that referenced this pull request Jul 5, 2026
…ction

Widen the salvaged NousResearch#32243 fix to the try_activate_fallback path: a custom
provider pointed at the native api.anthropic.com host (no /anthropic path
suffix, name != anthropic) fell through to chat_completions -> POST
/v1/chat/completions -> 404. Match the host the same way determine_api_mode()
and _detect_api_mode_for_url() now do. Absorbs NousResearch#49247.
Jasper6439 pushed a commit to Jasper6439/hermes-agent that referenced this pull request Jul 5, 2026
Pins that a custom provider on the native api.anthropic.com host resolves to
anthropic_messages on the try_activate_fallback path. From NousResearch#49247.
Jasper6439 pushed a commit to Jasper6439/hermes-agent that referenced this pull request Jul 5, 2026
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
…ction

Widen the salvaged NousResearch#32243 fix to the try_activate_fallback path: a custom
provider pointed at the native api.anthropic.com host (no /anthropic path
suffix, name != anthropic) fell through to chat_completions -> POST
/v1/chat/completions -> 404. Match the host the same way determine_api_mode()
and _detect_api_mode_for_url() now do. Absorbs NousResearch#49247.
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
Pins that a custom provider on the native api.anthropic.com host resolves to
anthropic_messages on the try_activate_fallback path. From NousResearch#49247.
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
…ction

Widen the salvaged NousResearch#32243 fix to the try_activate_fallback path: a custom
provider pointed at the native api.anthropic.com host (no /anthropic path
suffix, name != anthropic) fell through to chat_completions -> POST
/v1/chat/completions -> 404. Match the host the same way determine_api_mode()
and _detect_api_mode_for_url() now do. Absorbs NousResearch#49247.
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
Pins that a custom provider on the native api.anthropic.com host resolves to
anthropic_messages on the try_activate_fallback path. From NousResearch#49247.
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
…ction

Widen the salvaged NousResearch#32243 fix to the try_activate_fallback path: a custom
provider pointed at the native api.anthropic.com host (no /anthropic path
suffix, name != anthropic) fell through to chat_completions -> POST
/v1/chat/completions -> 404. Match the host the same way determine_api_mode()
and _detect_api_mode_for_url() now do. Absorbs NousResearch#49247.
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
Pins that a custom provider on the native api.anthropic.com host resolves to
anthropic_messages on the try_activate_fallback path. From NousResearch#49247.
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
…ction

Widen the salvaged NousResearch#32243 fix to the try_activate_fallback path: a custom
provider pointed at the native api.anthropic.com host (no /anthropic path
suffix, name != anthropic) fell through to chat_completions -> POST
/v1/chat/completions -> 404. Match the host the same way determine_api_mode()
and _detect_api_mode_for_url() now do. Absorbs NousResearch#49247.
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
Pins that a custom provider on the native api.anthropic.com host resolves to
anthropic_messages on the try_activate_fallback path. From NousResearch#49247.
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
teknium1 added a commit that referenced this pull request Aug 13, 2026
Maintainer fixup on the #79787 salvage:

- An explicit fb.api_mode of "chat_completions" was silently overridden
  by the codex_responses / bedrock re-detection pass (which only skipped
  re-detection when the pre-computed mode was non-default). Track
  explicitness in fb_api_mode_explicit and gate the whole re-detection
  block on it.
- Replace the locals().get('fb_api_mode') dead-code hack with clean code
  (fb_api_mode is always bound at that point).
- Restore the post-resolve /anthropic + api.anthropic.com host check for
  named custom providers whose base_url comes from config rather than
  the fallback entry (#32243, #49247), which the PR's restructure dropped.
- Add regression tests: explicit api_mode honored (incl. explicit
  chat_completions not overridden), /anthropic-hint fallback detected
  pre-rewrite, api_mode forwarded to resolve_provider_client, plain
  fallback unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists 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.

3 participants