Add support for SiliconFlow China region and provider#2588
Conversation
- 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
|
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 Please read |
There was a problem hiding this comment.
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.
| Novita, | ||
| Fireworks, | ||
| Siliconflow, | ||
| SiliconflowCn, |
There was a problem hiding this comment.
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
SiliconflowCnprovider variant toSiliconflowCNfor consistent casing across the codebase.
To ensure consistency across all crates, please rename SiliconflowCn to SiliconflowCN in crates/tui as well.
SiliconflowCN,| "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), |
There was a problem hiding this comment.
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),| Fireworks, | ||
| #[serde(alias = "silicon-flow", alias = "silicon_flow")] | ||
| Siliconflow, | ||
| #[serde(alias = "siliconflow-cn", alias = "siliconflow-CN")] |
There was a problem hiding this comment.
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"
)]|
|
||
| # 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 |
There was a problem hiding this comment.
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.
| 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 |
| "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), |
There was a problem hiding this comment.
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.
| "siliconflow-cn" | "siliconflow-CN" => Some(Self::SiliconflowCN), | |
| "siliconflow-cn" => Some(Self::SiliconflowCN), |
| "siliconflow-cn" | "siliconflow-CN" | ||
| | "silicon-flow-cn" | "silicon-flow-CN" | ||
| | "silicon_flow_cn" | "silicon_flow_CN" | ||
| | "siliconflow-china" => Some(Self::SiliconflowCn), |
There was a problem hiding this comment.
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.
| "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), |
| # 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 |
There was a problem hiding this comment.
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.
| # 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!
| @@ -2367,6 +2378,10 @@ impl Config { | |||
| "SiliconFlow API key not found. Run 'codewhale auth set --provider siliconflow', \ | |||
There was a problem hiding this comment.
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.
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>
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>
|
Superseded by #2615 (rebased onto v0.8.51-era main). Closing in favor of the rebased version. |
…#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>
|
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. |
Add
siliconflow-cnas a separate provider targeting SiliconFlow's Chinaendpoint. 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-cnas a distinct provider variant that defaults tohttps://api.siliconflow.cn/v1, while sharing the[providers.siliconflow]config block,SILICONFLOW_API_KEY, and the sameauth setcredential slot as the existingsiliconflowprovider.ProviderKind::SiliconflowCN(config crate) andApiProvider::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 bysiliconflow_base_url_is_official.client.rsmirrors the existingSiliconflowarms for the new variant;PROVIDER_LISTin the CLI grows from 15 to 16 entries with both variants listed independently.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
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 --> GReviews (1): Last reviewed commit: "fix: complete SiliconFlow China (Silicon..." | Re-trigger Greptile