Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions hermes_cli/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3301,7 +3301,12 @@ def copilot_model_api_mode(
if _should_use_copilot_responses_api(normalized):
return "codex_responses"

# Secondary: check catalog for non-GPT-5 models (Claude via /v1/messages, etc.)
# Catalog-driven fallback for models the pattern check doesn't cover.
# Honor the catalog's supported_endpoints, but only OVERRIDE chat_completions
# when the model does NOT advertise /chat/completions at all: some Copilot
# models are Responses-only (e.g. mai-code-1-flash-picker -> /responses) or
# Messages-only (Claude via /v1/messages). Models that DO advertise
# /chat/completions (Claude, Gemini on Copilot) keep using it.
if catalog:
catalog_entry = next((item for item in catalog if item.get("id") == normalized), None)
if isinstance(catalog_entry, dict):
Expand All @@ -3310,9 +3315,11 @@ def copilot_model_api_mode(
for endpoint in (catalog_entry.get("supported_endpoints") or [])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the primary resolver, but fallback activation still derives Copilot mode separately in agent/chat_completion_helpers.py:1503-1534 through the GPT-name-only predicate. Please route that sibling path through the same catalog-aware decision and add a fallback regression test; otherwise a non-GPT /responses-only fallback remains on Chat Completions.

if str(endpoint).strip()
}
# For non-GPT-5 models, check if they only support messages API
if "/v1/messages" in supported_endpoints and "/chat/completions" not in supported_endpoints:
return "anthropic_messages"
if supported_endpoints and "/chat/completions" not in supported_endpoints:
if "/responses" in supported_endpoints:
return "codex_responses"
if "/v1/messages" in supported_endpoints:
return "anthropic_messages"

return "chat_completions"

Expand Down
38 changes: 38 additions & 0 deletions tests/hermes_cli/test_model_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,44 @@ def test_copilot_api_mode_with_catalog_only_responses(self):
}]
assert copilot_model_api_mode("gpt-5.4", catalog=catalog) == "codex_responses"

def test_copilot_api_mode_non_gpt_responses_only_uses_responses(self):
"""A non-GPT Responses-only model (e.g. mai-code) must use codex_responses.

The ID regex only recognises GPT-5+ models, so without the catalog
fallback mai-code-1-flash-picker falls through to chat_completions and
the request fails with HTTP 400 'not accessible via /chat/completions'.
"""
catalog = [{
"id": "mai-code-1-flash-picker",
"supported_endpoints": ["/responses"],
}]
assert (
copilot_model_api_mode("mai-code-1-flash-picker", catalog=catalog)
== "codex_responses"
)

def test_copilot_api_mode_non_gpt_messages_only_uses_anthropic(self):
"""A non-GPT Messages-only model keeps routing to anthropic_messages."""
catalog = [{
"id": "claude-opus-4.6",
"supported_endpoints": ["/v1/messages"],
}]
assert (
copilot_model_api_mode("claude-opus-4.6", catalog=catalog)
== "anthropic_messages"
)

def test_copilot_api_mode_non_gpt_chat_capable_stays_chat(self):
"""Non-GPT models that advertise /chat/completions keep using it."""
catalog = [{
"id": "claude-opus-4.6",
"supported_endpoints": ["/chat/completions", "/v1/messages"],
}]
assert (
copilot_model_api_mode("claude-opus-4.6", catalog=catalog)
== "chat_completions"
)

def test_normalize_opencode_model_id_strips_provider_prefix(self):
assert normalize_opencode_model_id("opencode-go", "opencode-go/kimi-k2.5") == "kimi-k2.5"
assert normalize_opencode_model_id("opencode-zen", "opencode-zen/claude-sonnet-4-6") == "claude-sonnet-4-6"
Expand Down