[Bug] `--provider openai-api` fails with credential selection error when `default_provider` is a named profile
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 19.9k
- Forks
- 2.3k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 30
Description
Summary
When [provider].default_provider in config.toml is set to any custom named profile (e.g., company-gateway, my-local-proxy, etc.), explicitly overriding it via the CLI with --provider openai-api fails. The CLI aborts with:
Failed to select the credential route for --provider openai-api: Provider OpenRouter does not support OAuth/API-key credential selection.
This breaks the ability to use CLI provider overrides whenever a user sets their default environment to a custom gateway.
Root Cause
In crates/jcode-base/src/provider/mod.rs:1716-1735, set_credential_mode operates on the currently active provider.
- During startup, the active provider slot is correctly initialized to the
default_providerfrom the configuration file. For all custom named profiles, this uses theOpenRoutercompatibility runtime under the hood. - When the user passes
--provider openai-api, the initialization sequence attempts to configure the credential mode for the newopenai-apiroute. - However, it calls
set_credential_modebefore properly re-binding the active provider slot to the built-inOpenAIprovider. - Because the active slot is still pointing to the custom named profile (
OpenRouter),set_credential_modehits the fallback arm at line 1728 and bails out (since onlyActiveProvider::ClaudeandActiveProvider::OpenAIsupport credential mode selection).
Workaround
Users currently have to completely omit the --provider openai-api flag and instead pin the route via the model prefix directly: --model openai-api:<model>.
Proposed Fix
Update the provider selection and initialization logic (likely in src/cli/provider_init.rs) to ensure that when an explicit --provider flag is passed, the active provider slot is correctly switched to that requested provider before applying credential routing settings. Alternatively, modify set_credential_mode to accept an explicit provider target rather than relying on self.active_provider().
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in crates/jcode-base/src/provider/mod.rs around set_credential_mode at lines 1716-1735, then trace the provider initialization path in src/cli/provider_init.rs. Reproduce with a named default_provider and --provider openai-api, and verify that the explicit provider override selects the correct credential route without the OpenRouter error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100