feat: auto-detect provider when switching models via /model#1506
Merged
feat: auto-detect provider when switching models via /model#1506
Conversation
When typing /model deepseek-chat while on a different provider, the model name now auto-resolves to the correct provider instead of silently staying on the wrong one and causing API errors. Detection priority: 1. Direct provider with credentials (e.g. DEEPSEEK_API_KEY set) 2. OpenRouter catalog match with proper slug remapping 3. Direct provider without creds (clear error beats silent failure) Also adds DeepSeek as a first-class API-key provider — just set DEEPSEEK_API_KEY and /model deepseek-chat routes directly. Bare model names get remapped to proper OpenRouter slugs: /model gpt-5.4 → openai/gpt-5.4 /model claude-opus-4.6 → anthropic/claude-opus-4.6 Salvages the concept from PR #1177 by @virtaava with credential awareness and OpenRouter slug mapping added. Co-authored-by: virtaava <virtaava@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the confusing /model experience where typing
/model deepseek-chatwhile on a different provider would silently keep the wrong provider, causing API errors.Salvages the concept from PR #1177 by @virtaava, with credential awareness and OpenRouter slug mapping added.
What changed
Auto-detection in /model (cli.py + gateway/run.py):
provider:modelsyntax is given,detect_provider_for_model()finds the right providergpt-5.4→openai/gpt-5.4)DeepSeek as first-class provider (auth.py + config.py + models.py):
PROVIDER_REGISTRYas an API-key providerDEEPSEEK_API_KEYenv var, base URLhttps://api.deepseek.com/v1deepseek-chat,deepseek-reasonerNew functions in models.py:
detect_provider_for_model(model, current_provider)→(provider, model)orNone_find_openrouter_slug(bare_name)→ full OpenRouter model IDExamples
Tests
detect_provider_for_modeland_find_openrouter_slugCloses #1177 (concept salvaged with improvements)