Skip to content

Fix custom provider support for base_url and list-format models#12045

Closed
PaulMa-Lab wants to merge 1 commit into
NousResearch:mainfrom
PaulMa-Lab:fix/custom-provider-base-url-models
Closed

Fix custom provider support for base_url and list-format models#12045
PaulMa-Lab wants to merge 1 commit into
NousResearch:mainfrom
PaulMa-Lab:fix/custom-provider-base-url-models

Conversation

@PaulMa-Lab

Copy link
Copy Markdown

Summary

This PR fixes three bugs that prevent custom providers from working correctly when using the v12+ providers: configuration format with base_url field and list-format models.

Problem

Users configuring custom providers like this:

providers:
  alibaba-coding:
    base_url: https://coding.dashscope.aliyuncs.com/v1
    api_key: sk-xxx
    models:
      - qwen3.5-plus
      - qwen3-max-2026-01-23
      - qwen3-coder-next

Experience three issues:

  1. CLI rejects the provider - hermes chat --provider alibaba-coding fails with "invalid choice"
  2. Model picker shows duplicate entries - Provider appears twice, one with "0 models"
  3. Models not loaded - Custom provider shows "(0 models)" in picker UI

Root Causes

Bug 1: Hardcoded provider choices in CLI (main.py:6427)

The --provider argument used a hardcoded list of builtin providers, rejecting any custom providers defined in config.

Bug 2: Missing base_url field check (model_switch.py:1043)

The user_providers section only checked api and url fields, but the newer config format uses base_url (matching OpenAI-compatible API conventions).

Bug 3: Models field type mismatch (config.py:1831)

The normalization function only accepted dict-format models:

if isinstance(models, dict) and models:

But list-format (which is more intuitive for simple provider configs) was rejected, causing models to be dropped during normalization.

Changes

1. Dynamic provider loading (main.py)

  • Added _get_provider_choices() function that loads config at argparse setup time
  • Merges builtin + custom providers from config.yaml
  • Falls back gracefully if config loading fails

2. Support base_url field (model_switch.py)

  • Updated API URL lookup to check base_url first, then api, then url
  • Maintains backward compatibility with legacy formats

3. Accept list-format models (config.py)

  • Changed type check from dict to (dict, list)
  • Both formats now work correctly

Testing

Before fix:

$ hermes chat --provider alibaba-coding
error: argument --provider: invalid choice: 'alibaba-coding'

# Model picker shows:
# - alibaba-coding (8 models)
# - alibaba-coding (0 models)  ← duplicate with no models

After fix:

$ hermes chat --provider alibaba-coding
# Works correctly

# Model picker shows:
# - alibaba-coding (8 models)  ← single entry, all models loaded

Impact

  • ✅ Zero breaking changes - all existing configs continue to work
  • ✅ Enables proper support for v12+ provider configuration format
  • ✅ Consistent field priority across codebase (base_url → api → url)
  • ✅ Supports both dict and list formats for models field

Checklist

  • Fixes affect only custom provider loading logic
  • Backward compatible with legacy config formats
  • Tested with real custom provider configuration
  • No new dependencies added

- Add dynamic provider loading in CLI argparse (main.py)
- Support base_url field in model picker (model_switch.py)
- Accept list-format models in normalization (config.py)

Fixes custom providers configured with:
  providers:
    custom-name:
      base_url: https://...
      models: [model1, model2, ...]

Before: CLI rejected provider, picker showed duplicates with 0 models
After: Provider works correctly with all models loaded
@teknium1

Copy link
Copy Markdown
Contributor

Closing in favor of #13509, which solves the same models: list-format drop with a cleaner fix (converts to dict shape at normalize time so downstream code sees a consistent type) and adds focused tests. Your analysis of the bug was correct — credit preserved via this comment. Thanks!

@teknium1 teknium1 closed this Apr 23, 2026
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard area/config Config system, migrations, profiles labels Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles 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.

3 participants