Skip to content

TUI: /new after /model switch to custom provider model fails with 'no API key' when model name exists in native provider catalog #16857

@peltason-uri

Description

@peltason-uri

Bug Description

When using /model to switch to a model served via a custom provider (e.g. custom:xuanji), and the model name also exists in a native provider's static catalog (e.g. deepseek-v4-pro exists in the native deepseek provider catalog), running /new fails with:

error: agent init failed: Provider 'deepseek' is set in config.yaml but no API key was found.
Set the DEEPSEEK_API_KEY environment variable, or switch to a different provider with `hermes model`.

Steps to Reproduce

  1. Configure a custom provider (e.g. custom:xuanji) with models like deepseek-v4-pro
  2. In TUI, run /model deepseek-v4-pro — switches successfully to custom:xuanji
  3. Run /new — fails with the error above

Root Cause

In tui_gateway/server.py, _resolve_startup_runtime() (line ~628):

  1. /model correctly sets HERMES_MODEL=deepseek-v4-pro and HERMES_INFERENCE_PROVIDER=custom:xuanji in env vars
  2. On /new, _resolve_startup_runtime() detects HERMES_MODEL is set (line 634-637)
  3. It reads config.model.provider (custom:xuanji) as current_provider (line 644-652)
  4. It calls detect_static_provider_for_model("deepseek-v4-pro", "custom:xuanji") (line 654)
  5. Since custom:xuanji has no static catalog, _model_in_provider_catalog() returns False
  6. The function iterates all native provider catalogs and matches deepseek-v4-pro to the native deepseek provider
  7. Returns ("deepseek", "deepseek-v4-pro"), overriding the correct custom:xuanji provider
  8. resolve_runtime_provider then fails because DEEPSEEK_API_KEY is not set

Note: This bug is masked for models like claude-opus-4-7 if ANTHROPIC_API_KEY happens to be set — the wrong provider is used but authentication succeeds by coincidence.

Expected Behavior

/new should respect the HERMES_INFERENCE_PROVIDER env var set by /model, since it represents the user's explicit provider choice.

Suggested Fix

In _resolve_startup_runtime(), check HERMES_INFERENCE_PROVIDER before falling through to detect_static_provider_for_model():

# If /model set HERMES_INFERENCE_PROVIDER, honour it directly
inference_provider = os.environ.get("HERMES_INFERENCE_PROVIDER", "").strip()
if inference_provider:
    return model, inference_provider

This should be inserted after the HERMES_TUI_PROVIDER check (line 630-632) and before the static detection logic.

Environment

  • Hermes Agent TUI mode
  • Custom provider with models that share names with native provider catalogs

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High — major feature broken, no workaroundarea/configConfig system, migrations, profilescomp/gatewayGateway runner, session dispatch, deliverycomp/tuiTerminal UI (ui-tui/ + tui_gateway/)type/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions