Skip to content

fix(cli): preserve model-specific api_mode across credential refresh#17596

Open
toller892 wants to merge 1 commit into
NousResearch:mainfrom
toller892:fix/api-mode-preserve
Open

fix(cli): preserve model-specific api_mode across credential refresh#17596
toller892 wants to merge 1 commit into
NousResearch:mainfrom
toller892:fix/api-mode-preserve

Conversation

@toller892

Copy link
Copy Markdown

Problem

_ensure_runtime_credentials() unconditionally overwrites self.api_mode with resolve_runtime_provider()s return value on every turn. The resolver defaults to "chat_completions" for most providers, but some models require "anthropic_messages" (e.g. kimi-for-coding).

When a user runs /model kimi-for-coding, it correctly sets api_mode="anthropic_messages". But on the next turn, _ensure_runtime_credentials() resets it back to "chat_completions", causing a 404 error (OpenAI-format traffic sent to an Anthropic-format endpoint).

Repro

  1. Start a session with any provider
  2. /model kimi-for-coding
  3. Send a message → works
  4. Send a second message → 404 error

Root Cause

resolve_runtime_provider() always returns an api_mode (defaulting to "chat_completions"), so the fallback runtime.get("api_mode", self.api_mode) never uses self.api_mode. The /model commands correctly set transport is unconditionally overwritten.

Fix

Only overwrite self.api_mode when:

  • We are already at the default ("chat_completions") — nothing to preserve
  • The resolver returns a non-default value — it has important info

This preserves model-specific transport modes set by /model while still allowing the resolver to communicate non-default transports.

Related

Fixes #17574

_ensure_runtime_credentials() unconditionally overwrites self.api_mode
with resolve_runtime_provider()'s return value, which defaults to
"chat_completions" for most providers. This destroys the transport
mode set by the /model command for models that require non-default
transports (e.g. kimi-for-coding needs "anthropic_messages").

Fix: only overwrite api_mode when the resolver returns a non-default
value, or when we're already at the default. This preserves
model-specific transport modes across credential refreshes.

Fixes NousResearch#17574
@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard area/auth Authentication, OAuth, credential pools P2 Medium — degraded but workaround exists labels Apr 29, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #17574 (same root cause). See also #17590 which targets the same fix. Similar pattern to #9694/#15605 (model overwrite on credential refresh).

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

Labels

area/auth Authentication, OAuth, credential pools comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_ensure_runtime_credentials() silently resets api_mode, breaking providers that require non-default transport

2 participants