1jehuang / 1jehuang/jcode

[Bug] `--provider openai-api` fails with credential selection error when `default_provider` is a named profile

Open
#710 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

autonomous: likely bug priority: medium triage: reproducible
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.

  1. During startup, the active provider slot is correctly initialized to the default_provider from the configuration file. For all custom named profiles, this uses the OpenRouter compatibility runtime under the hood.
  2. When the user passes --provider openai-api, the initialization sequence attempts to configure the credential mode for the new openai-api route.
  3. However, it calls set_credential_mode before properly re-binding the active provider slot to the built-in OpenAI provider.
  4. Because the active slot is still pointing to the custom named profile (OpenRouter), set_credential_mode hits the fallback arm at line 1728 and bails out (since only ActiveProvider::Claude and ActiveProvider::OpenAI support 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.