diff --git a/agent/chat_completion_helpers.py b/agent/chat_completion_helpers.py index 56228ac09..8392a76a3 100644 --- a/agent/chat_completion_helpers.py +++ b/agent/chat_completion_helpers.py @@ -1241,7 +1241,17 @@ def try_activate_fallback(agent, reason: "FailoverReason | None" = None) -> bool _fb_is_azure = agent._is_azure_openai_url(fb_base_url) if fb_provider == "openai-codex": fb_api_mode = "codex_responses" - elif fb_provider == "anthropic" or fb_base_url.rstrip("/").lower().endswith("/anthropic"): + elif ( + fb_provider == "anthropic" + or fb_base_url.rstrip("/").lower().endswith("/anthropic") + or base_url_hostname(fb_base_url) == "api.anthropic.com" + ): + # Custom providers (e.g. cron-anthropic) point at the native + # api.anthropic.com host with no "/anthropic" path suffix, so the + # name/suffix checks above miss them and they default to + # chat_completions → POST /v1/chat/completions → 404. Match the + # host the same way determine_api_mode() and _detect_api_mode_for_url() + # do on the primary path. (#32243, #49247) fb_api_mode = "anthropic_messages" elif _fb_is_azure: # Azure OpenAI serves gpt-5.x on /chat/completions — does NOT