Skip to content

Add support for SiliconFlow China region and provider#2588

Closed
BH8GCJ wants to merge 3 commits into
Hmbown:mainfrom
BH8GCJ:fix/siliconflow-china-region-support
Closed

Add support for SiliconFlow China region and provider#2588
BH8GCJ wants to merge 3 commits into
Hmbown:mainfrom
BH8GCJ:fix/siliconflow-china-region-support

Conversation

@BH8GCJ

@BH8GCJ BH8GCJ commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Add siliconflow-cn as a separate provider targeting SiliconFlow's China
endpoint. The variant shares code paths with the global SiliconFlow
provider but uses its own API key and endpoint.

cargo check ✅ cargo test --workspace ✅ 0 failures

Greptile Summary

Introduces siliconflow-cn as a distinct provider variant that defaults to https://api.siliconflow.cn/v1, while sharing the [providers.siliconflow] config block, SILICONFLOW_API_KEY, and the same auth set credential slot as the existing siliconflow provider.

  • ProviderKind::SiliconflowCN (config crate) and ApiProvider::SiliconflowCn (tui crate) are added with every required match arm updated; is_siliconflow() is added as a convenience predicate and both official endpoints are recognized by siliconflow_base_url_is_official.
  • Reasoning-effort handling in client.rs mirrors the existing Siliconflow arms for the new variant; PROVIDER_LIST in the CLI grows from 15 to 16 entries with both variants listed independently.
  • The parse() functions in both crates include dead uppercase match alternatives (\"siliconflow-CN\", \"silicon-flow-CN\", etc.) that can never be reached because the input is fully lowercased before the match.

Confidence Score: 4/5

The change is safe to merge; all credential and config slot sharing is intentional and correctly handled across every match arm in all three crates.

The shared-slot design is well-executed and consistent, and siliconflow_base_url_is_official correctly covers both .com and .cn. The only rough edges are dead uppercase match patterns in both parse() functions (harmless but misleading), the README omitting --provider siliconflow-cn as a first-class example, and the undocumented behavior where SILICONFLOW_BASE_URL can silently redirect siliconflow-cn to the international endpoint.

crates/config/src/lib.rs and crates/tui/src/config.rs each have dead patterns in their parse() functions worth cleaning up. README.md could more prominently feature the new --provider siliconflow-cn shorthand.

Important Files Changed

Filename Overview
crates/config/src/lib.rs Adds SiliconflowCN variant to ProviderKind with shared credential slot, is_siliconflow() helper, and DEFAULT_SILICONFLOW_CN_BASE_URL constant; contains a dead uppercase pattern in parse().
crates/tui/src/config.rs Adds SiliconflowCn variant to ApiProvider with all match arms updated; parse() contains multiple dead uppercase patterns since input is lowercased before matching.
crates/tui/src/client.rs Adds SiliconflowCn alongside Siliconflow in all three reasoning effort match arms (disabled, high, max); straightforward and correct.
crates/cli/src/lib.rs Adds SiliconflowCN to PROVIDER_LIST (now 16) and maps it to the shared siliconflow credential slot and SILICONFLOW_API_KEY; both providers show separately in auth list but share the same auth status.
README.md Adds China regional endpoint example using --provider siliconflow with SILICONFLOW_BASE_URL env var, but never mentions --provider siliconflow-cn as a direct option.
docs/PROVIDERS.md Expands the siliconflow row to document both .com and .cn as official endpoints with SILICONFLOW_BASE_URL override guidance; accurate and complete.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User: --provider siliconflow-cn] --> B{ProviderKind/ApiProvider parse}
    B --> C[SiliconflowCN / SiliconflowCn variant]
    C --> D{SILICONFLOW_BASE_URL set?}
    D -- Yes --> E[apply_env_overrides writes to providers.siliconflow.base_url]
    D -- No --> F[Default: https://api.siliconflow.cn/v1]
    E --> G{Effective base URL}
    F --> G
    G --> H[Shared credential slot: providers.siliconflow]
    H --> I[API key: SILICONFLOW_API_KEY]
    I --> J[HTTP request to resolved base URL]
    K[User: --provider siliconflow] --> B2{parse}
    B2 --> L[Siliconflow variant]
    L --> M{SILICONFLOW_BASE_URL set?}
    M -- Yes --> E
    M -- No --> N[Default: https://api.siliconflow.com/v1]
    N --> G
Loading

Fix All in Codex Fix All in Claude Code Fix All in Cursor

Reviews (1): Last reviewed commit: "fix: complete SiliconFlow China (Silicon..." | Re-trigger Greptile

Greptile also left 4 inline comments on this PR.

BH8GCJ and others added 3 commits June 2, 2026 18:19
- Add DEFAULT_SILICONFLOW_CN_BASE_URL constant for China regional endpoint (https://api.siliconflow.cn/v1)
- Update config example to document both international (.com) and China (.cn) endpoints
- Update README with China region usage example
- Update PROVIDERS.md documentation to clarify regional endpoint support
- Both endpoints are recognized as official and use the same default models

Users in China can now use:
  - SILICONFLOW_BASE_URL=https://api.siliconflow.cn/v1
  - Or set base_url in config file
  - Or use environment variable directly
…t support

- Add SiliconflowCn variant to ApiProvider enum in TUI config
- Add SiliconflowCn variant to ProviderKind enum in core config
- Define DEFAULT_SILICONFLOW_CN_BASE_URL constant: https://api.siliconflow.cn/v1
- Update all 16 match arms for SiliconflowCn in config.rs:
  - Model completion names (uses same models as international)
  - Config table paths (uses providers.siliconflow section)
  - API key env var handling (uses SILICONFLOW_API_KEY)
  - Default base URL resolution (CN variant -> CN endpoint)
  - Error messages (references siliconflow-cn command)
  - Provider parsing and string representations
- Both siliconflow and siliconflow-cn providers share config section
  but use different default base URLs
- Allows --provider siliconflow-cn to target China endpoint directly
- Rename SiliconflowCn to SiliconflowCN for consistent casing
- Add ProviderKind::is_siliconflow() helper covering both variants
- Merge Siliconflow/SiliconflowCN match arms in config, tui, and cli crates
- Share the same credential slot and SILICONFLOW_API_KEY env var
- Fix cli crate: add SiliconflowCN to provider_slot, provider_env_vars,
  and PROVIDER_LIST to resolve missing match arm errors
- Update CHANGELOG Unreleased section
@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

Thanks @BH8GCJ for taking the time to contribute.

This repository is currently observing a maintainer-managed contribution gate in dry-run mode, so this pull request is staying open. When enforcement is enabled, pull requests from contributors who are not listed in .github/APPROVED_CONTRIBUTORS will be closed automatically.

Please read CONTRIBUTING.md for the expected contribution shape. A maintainer can grant PR access by commenting /lgtm on a pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the SiliconflowCN provider variant to support the SiliconFlow China regional endpoint, aligning it with the international endpoint and updating the CLI, config, and TUI crates to handle it uniformly. The reviewer provided feedback on maintaining casing consistency (SiliconflowCN vs SiliconflowCn) in the TUI crate, aligning parsing and deserialization aliases for the new provider across crates, and simplifying the README example by utilizing the new provider directly.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread crates/tui/src/config.rs
Novita,
Fireworks,
Siliconflow,
SiliconflowCn,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The variant is named SiliconflowCn here, but in crates/config/src/lib.rs it is named SiliconflowCN (with an uppercase 'N'). The changelog also states:

Renamed SiliconflowCn provider variant to SiliconflowCN for consistent casing across the codebase.

To ensure consistency across all crates, please rename SiliconflowCn to SiliconflowCN in crates/tui as well.

    SiliconflowCN,

Comment thread crates/config/src/lib.rs
"novita" => Some(Self::Novita),
"fireworks" | "fireworks-ai" => Some(Self::Fireworks),
"siliconflow" | "silicon-flow" | "silicon_flow" => Some(Self::Siliconflow),
"siliconflow-cn" | "siliconflow-CN" => Some(Self::SiliconflowCN),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To ensure consistent parsing of provider names between the CLI/config and the TUI, ProviderKind::parse should support the same set of aliases as ApiProvider::parse in crates/tui/src/config.rs (such as silicon-flow-cn, silicon_flow_cn, and siliconflow-china).

            "siliconflow-cn" | "siliconflow-CN"
            | "silicon-flow-cn" | "silicon-flow-CN"
            | "silicon_flow_cn" | "silicon_flow_CN"
            | "siliconflow-china" => Some(Self::SiliconflowCN),

Comment thread crates/config/src/lib.rs
Fireworks,
#[serde(alias = "silicon-flow", alias = "silicon_flow")]
Siliconflow,
#[serde(alias = "siliconflow-cn", alias = "siliconflow-CN")]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similarly, we should add these aliases to the #[serde(alias = ...)] attributes on ProviderKind::SiliconflowCN so that the config file deserialization is also fully consistent with the parsed aliases.

    #[serde(
        alias = "siliconflow-cn",
        alias = "siliconflow-CN",
        alias = "silicon-flow-cn",
        alias = "silicon-flow-CN",
        alias = "silicon_flow_cn",
        alias = "silicon_flow_CN",
        alias = "siliconflow-china"
    )]

Comment thread README.md

# SiliconFlow (China regional endpoint)
codewhale auth set --provider siliconflow --api-key "YOUR_SILICONFLOW_API_KEY"
SILICONFLOW_BASE_URL="https://api.siliconflow.cn/v1" codewhale --provider siliconflow --model deepseek-ai/DeepSeek-V4-Pro

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since you have introduced the new siliconflow-cn provider variant which automatically defaults to the China regional endpoint (https://api.siliconflow.cn/v1), users no longer need to manually specify the SILICONFLOW_BASE_URL environment variable. We can simplify this example to showcase the new provider directly.

Suggested change
SILICONFLOW_BASE_URL="https://api.siliconflow.cn/v1" codewhale --provider siliconflow --model deepseek-ai/DeepSeek-V4-Pro
codewhale --provider siliconflow-cn --model deepseek-ai/DeepSeek-V4-Pro

Comment thread crates/config/src/lib.rs
"novita" => Some(Self::Novita),
"fireworks" | "fireworks-ai" => Some(Self::Fireworks),
"siliconflow" | "silicon-flow" | "silicon_flow" => Some(Self::Siliconflow),
"siliconflow-cn" | "siliconflow-CN" => Some(Self::SiliconflowCN),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The "siliconflow-CN" pattern is dead code. parse() calls to_ascii_lowercase() before the match, so any mixed-case input like "siliconflow-CN" is already "siliconflow-cn" by the time it reaches this arm and will always match the first alternative. Only the lowercase pattern is reachable.

Suggested change
"siliconflow-cn" | "siliconflow-CN" => Some(Self::SiliconflowCN),
"siliconflow-cn" => Some(Self::SiliconflowCN),

Fix in Codex Fix in Claude Code Fix in Cursor

Comment thread crates/tui/src/config.rs
Comment on lines +168 to +171
"siliconflow-cn" | "siliconflow-CN"
| "silicon-flow-cn" | "silicon-flow-CN"
| "silicon_flow_cn" | "silicon_flow_CN"
| "siliconflow-china" => Some(Self::SiliconflowCn),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 All six uppercase patterns here ("siliconflow-CN", "silicon-flow-CN", "silicon_flow_CN") are dead code for the same reason as in crates/config: parse() applies to_ascii_lowercase() before the match, so every uppercase variant has already been folded to its lowercase equivalent and matched by the preceding arm. Only the lowercase and "siliconflow-china" patterns are reachable.

Suggested change
"siliconflow-cn" | "siliconflow-CN"
| "silicon-flow-cn" | "silicon-flow-CN"
| "silicon_flow_cn" | "silicon_flow_CN"
| "siliconflow-china" => Some(Self::SiliconflowCn),
"siliconflow-cn"
| "silicon-flow-cn"
| "silicon_flow_cn"
| "siliconflow-china" => Some(Self::SiliconflowCn),

Fix in Codex Fix in Claude Code Fix in Cursor

Comment thread README.md
Comment on lines +340 to +342
# SiliconFlow (China regional endpoint)
codewhale auth set --provider siliconflow --api-key "YOUR_SILICONFLOW_API_KEY"
SILICONFLOW_BASE_URL="https://api.siliconflow.cn/v1" codewhale --provider siliconflow --model deepseek-ai/DeepSeek-V4-Pro

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The README documents the China endpoint via SILICONFLOW_BASE_URL, but never mentions --provider siliconflow-cn, which is the primary user-facing addition of this PR. Users who want a dedicated China-endpoint profile (without touching env vars) would not know it exists from the README.

Suggested change
# SiliconFlow (China regional endpoint)
codewhale auth set --provider siliconflow --api-key "YOUR_SILICONFLOW_API_KEY"
SILICONFLOW_BASE_URL="https://api.siliconflow.cn/v1" codewhale --provider siliconflow --model deepseek-ai/DeepSeek-V4-Pro
# SiliconFlow (China regional endpoint) - uses siliconflow-cn provider (defaults to https://api.siliconflow.cn/v1)
codewhale auth set --provider siliconflow-cn --api-key "YOUR_SILICONFLOW_API_KEY"
codewhale --provider siliconflow-cn --model deepseek-ai/DeepSeek-V4-Pro
# Alternatively, override the base URL at runtime for any profile:
SILICONFLOW_BASE_URL="https://api.siliconflow.cn/v1" codewhale --provider siliconflow --model deepseek-ai/DeepSeek-V4-Pro

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Codex Fix in Claude Code Fix in Cursor

Comment thread crates/tui/src/config.rs
@@ -2367,6 +2378,10 @@ impl Config {
"SiliconFlow API key not found. Run 'codewhale auth set --provider siliconflow', \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 SILICONFLOW_BASE_URL silently overrides siliconflow-cn default endpoint

Both Siliconflow and SiliconflowCn write to the same providers.siliconflow.base_url slot in apply_env_overrides, so a pre-existing SILICONFLOW_BASE_URL=https://api.siliconflow.com/v1 in the environment will silently route --provider siliconflow-cn to the international endpoint, defeating its purpose. There is no SILICONFLOW_CN_BASE_URL escape hatch. A note in the error message or the provider description explaining that SILICONFLOW_BASE_URL affects both variants would help users debug this.

Fix in Codex Fix in Claude Code Fix in Cursor

Hmbown added a commit that referenced this pull request Jun 3, 2026
Adds SiliconFlow China regional endpoint (api.siliconflow.cn) as new provider variant.

Credit: @Raid10Without1 (PR #2588)
Co-authored-by: Raid10没有1 <88494433+Raid10Without1@users.noreply.github.com>
Hmbown added a commit that referenced this pull request Jun 3, 2026
Adds SiliconFlow China regional endpoint (api.siliconflow.cn) as new provider variant.

Credit: @Raid10Without1 (PR #2588)

Co-authored-by: Raid10没有1 <88494433+Raid10Without1@users.noreply.github.com>
@Hmbown

Hmbown commented Jun 3, 2026

Copy link
Copy Markdown
Owner

Superseded by #2615 (rebased onto v0.8.51-era main). Closing in favor of the rebased version.

@Hmbown Hmbown closed this Jun 3, 2026
yanghucai pushed a commit to yanghucai/CodeWhale that referenced this pull request Jun 3, 2026
…#2615)

Adds SiliconFlow China regional endpoint (api.siliconflow.cn) as new provider variant.

Credit: @Raid10Without1 (PR Hmbown#2588)

Co-authored-by: Raid10没有1 <88494433+Raid10Without1@users.noreply.github.com>
@Hmbown

Hmbown commented Jun 3, 2026

Copy link
Copy Markdown
Owner

Thanks @BH8GCJ for the SiliconFlow China region work here. I rebased/harvested this into #2615, but the maintainer follow-up missed some compile-exhaustiveness and formatting cleanup, which broke main. That is on me, not on this PR.

I reproduced the break locally and am carrying the narrow compile/auth repair into the v0.8.52 stabilization branch with credit to this original implementation. Sorry for the messy landing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants