CodeWhale icon indicating copy to clipboard operation
CodeWhale copied to clipboard

normalize_model_for_provider replaces user-configured model name with provider-specific prefix, breaking custom OpenAI-compatible endpoints

Open dfwqdyl-ui opened this issue 6 months ago • 2 comments

Description

When using a custom OpenAI-compatible API endpoint (e.g. a self-hosted gateway or enterprise proxy), the TUI replaces the user-configured model name with a provider-specific prefixed version via normalize_model_for_provider().

This means no built-in provider can be used to connect to a custom endpoint that expects bare model names.

Steps to Reproduce

  1. Set up a custom OpenAI-compatible API gateway (e.g. https://my-gateway.example.com/v1) that serves model DeepSeek-V4-Pro
  2. Configure config.toml:
    provider = "openrouter"
    default_text_model = "DeepSeek-V4-Pro"
    
    [providers.openrouter]
    api_key = "my-key"
    base_url = "https://my-gateway.example.com/v1"
    model = "DeepSeek-V4-Pro"
    
  3. Start DeepSeek TUI and send a message

Expected Behavior

TUI sends "model": "DeepSeek-V4-Pro" to the custom endpoint (as configured by the user).

Actual Behavior

TUI sends "model": "deepseek/deepseek-v4-pro" (OpenRouter format), which the custom endpoint rejects:

HTTP 400 Bad Request: deepseek/deepseek-v4-pro model is not supported

Root Cause

normalize_model_for_provider() in crates/config/src/lib.rs unconditionally replaces model names for all built-in providers:

fn normalize_model_for_provider(provider: ProviderKind, model: &str) -> String {
    let normalized = model.trim().to_ascii_lowercase();
    match (provider, normalized.as_str()) {
        (ProviderKind::Openrouter, "deepseek-v4-pro") => "deepseek/deepseek-v4-pro".to_string(),
        (ProviderKind::Sglang, "deepseek-v4-pro") => "deepseek-ai/DeepSeek-V4-Pro".to_string(),
        (ProviderKind::Novita, "deepseek-v4-pro") => "deepseek/deepseek-v4-pro".to_string(),
        // ... all providers have similar mappings
        _ => model.to_string(),  // only unmatched names pass through
    }
}

The _ fallback only fires when the lowercased model name doesn't match any known pattern. Since deepseek-v4-pro matches for every provider, there is no way to send the bare model name regardless of which provider is selected.

Why #733 Didn't Fix This

PR #733 (for #729) preserved case when the resolved model differs only in casing. But normalize_model_for_provider doesn't just change case — it replaces the entire model name with a provider-specific prefixed variant. The case-preservation logic runs after normalization, so it has no effect here.

Suggested Fix

Add a "custom" or "openai-compatible" provider kind that skips normalize_model_for_provider entirely and passes the user's model name through unchanged:

provider = "custom"

[providers.custom]
api_key = "sk-my-key"
base_url = "https://my-gateway.example.com/v1"
model = "DeepSeek-V4-Pro"

Alternatively, skip normalization when the user explicitly sets model in [providers.<name>] — treat an explicit model override as "I know what I'm doing".

Workaround

Currently requires a local HTTP proxy that rewrites the model name before forwarding to the actual endpoint — not practical for most users.

Environment

  • DeepSeek TUI v0.8.14 (Windows x64)
  • Third-party OpenAI-compatible gateway

dfwqdyl-ui avatar May 06 '26 11:05 dfwqdyl-ui

great idea - thank you!

Hmbown avatar May 06 '26 21:05 Hmbown

maybe i can have a try

THINKER-ONLY avatar May 07 '26 12:05 THINKER-ONLY