Fixes: Hermes fallback issue with kimi-for-coding -- anthropic_messages endpoint returning 404 - #33276
Open
buxue2025 wants to merge 1 commit into
Open
Fixes: Hermes fallback issue with kimi-for-coding -- anthropic_messages endpoint returning 404#33276buxue2025 wants to merge 1 commit into
buxue2025 wants to merge 1 commit into
Conversation
The inline api_mode heuristics in try_activate_fallback() missed Kimi's api.kimi.com/coding endpoint, which speaks Anthropic Messages. When falling back to kimi-coding, the agent used chat_completions (OpenAI client) against the Anthropic endpoint → HTTP 404. Direct provider switches already worked because they call determine_api_mode() / _detect_api_mode_for_url(), which correctly identifies api.kimi.com/coding as anthropic_messages. Add a final else-branch that calls _detect_api_mode_for_url() as a fallback detector, matching the behavior of explicit model switches. Fixes: fallback to kimi-coding returning 404 after primary model failure
Collaborator
teknium1
reviewed
Jul 13, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for tracing the fallback-specific transport selection path. The bare /coding premise is still present on current main: agent/chat_completion_helpers.py:1461-1497 defaults to chat_completions without a Kimi /coding branch.
Problems
- The added detector call at
agent/chat_completion_helpers.py:1037imports_detect_api_mode_for_url(), whose current rule athermes_cli/runtime_provider.py:137-138classifies everyapi.kimi.comURL containing/codingasanthropic_messages. The linked #17107 documents that/coding/v1is OpenAI-compatible, so this would select the wrong transport for that fallback URL. - The PR changes only production code and adds no fallback regression coverage. Existing
tests/run_agent/test_provider_fallback.py:185-212covers native Anthropic fallback routing, not the Kimi bare-route versus/coding/v1distinction.
Suggested changes
- Narrow and test the Kimi URL rule so bare
/codingselects Anthropic Messages while/coding/v1remains OpenAI-compatible; keep the runtime and fallback paths aligned. - Add fallback tests for both endpoint forms.
Automated hermes-sweeper review.
| # Kimi's ``api.kimi.com/coding`` (Anthropic Messages) that | ||
| # the inline heuristics above miss. See #22548. | ||
| from hermes_cli.runtime_provider import _detect_api_mode_for_url | ||
| detected = _detect_api_mode_for_url(fb_base_url) |
Contributor
There was a problem hiding this comment.
_detect_api_mode_for_url() currently returns anthropic_messages for any api.kimi.com URL containing /coding, including /coding/v1 (hermes_cli/runtime_provider.py:137-138). The linked #17107 identifies /coding/v1 as OpenAI-compatible, so please narrow the shared rule and add bare /coding versus /coding/v1 fallback coverage before using it here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem statement:
In Hermes-Agent, when configured primary model fails and Hermes-Agent falls back to secondary, here my configuration is kimi-for-coding, the fallback path uses chat_completions (OpenAI client) against api.kimi.com/coding, which speaks Anthropic Messages → HTTP 404.
Direct provider switches (hermes chat --provider kimi-coding) work correctly because it calls determine_api_mode() / _detect_api_mode_for_url().
Root Cause
Try_activate_fallback() in agent/chat_completion_helpers.py has inline api_mode heuristics that miss api.kimi.com/coding (Anthropic Messages).
Fix
Add a final else branch that calls _detect_api_mode_for_url() as a fallback detector, matching the behavior of explicit model switches.
Verification
- Kimi fallback: api_mode = anthropic_messages ✅
- OpenAI fallback: api_mode = codex_responses ✅
- DeepSeek fallback: api_mode = chat_completions ✅