How to Configure DeepSeek Provider in CodeWhale: Complete Setup Guide
Set provider = "deepseek" in your config.toml, define the base_url endpoint, and populate the [providers.deepseek] table with your chosen model and optional API key to route LLM requests through DeepSeek's API.
CodeWhale is an open-source LLM orchestration tool that uses a TOML-based configuration system to manage provider connections. To configure DeepSeek provider in CodeWhale, you must edit the central configuration file to specify endpoints, models, and authentication credentials according to the structures defined in Hmbown/CodeWhale. This guide walks through the exact implementation details found in the source code.
Configuration File Structure
CodeWhale relies on either config.toml in your working directory or the provided config.example.toml template. The crates/config module parses these files into the internal ProvidersToml structure, mapping TOML keys to the Rust Config struct defined at line 294 of crates/config/src/lib.rs.
Step-by-Step DeepSeek Configuration
Complete these steps to enable DeepSeek as your LLM backend:
1. Select DeepSeek as the Default Provider
Set the top-level provider field to deepseek (or deepseek-cn for Chinese endpoints) to instruct CodeWhale which provider configuration to load at runtime. As documented in config.example.toml at line 22:
provider = "deepseek"
2. Configure the DeepSeek API Endpoint
Define the base_url field to point to your desired DeepSeek endpoint. You can use the beta endpoint (https://api.deepseek.com/beta) or the classic endpoint (https://api.deepseek.com). This value is referenced by the runtime when constructing request URLs.
According to config.example.toml at line 24:
base_url = "https://api.deepseek.com/beta"
3. Set the Model and API Key
Create a [providers.deepseek] table to contain DeepSeek-specific settings. Required fields include model (e.g., deepseek-v4-pro or deepseek-v4-flash), as shown at line 256 of config.example.toml. Optionally, supply an api_key for authentication; the configuration parser at crates/config/src/lib.rs (lines 657–669) reads this value securely without logging it to output.
[providers.deepseek]
api_key = "YOUR_DEEPSEEK_API_KEY"
model = "deepseek-v4-pro"
4. Add Custom HTTP Headers (Optional)
For enterprise deployments requiring proxy headers or custom metadata, define the http_headers field as a table within [providers.deepseek]. The configuration parser at crates/config/src/lib.rs line 530 handles these key-value pairs:
[providers.deepseek]
http_headers = { "X-Custom-Header" = "value", "X-Request-ID" = "abc123" }
Complete Configuration Example
Combine these settings into a single configuration block. This example demonstrates a production-ready DeepSeek provider configuration:
# Top-level provider selection
provider = "deepseek"
# Global endpoint configuration (beta or classic)
base_url = "https://api.deepseek.com/beta"
[providers.deepseek]
# Authentication credentials
api_key = "YOUR_DEEPSEEK_API_KEY"
# Model selection (e.g., deepseek-v4-pro, deepseek-v4-flash)
model = "deepseek-v4-pro"
# Optional custom headers for enterprise proxies
# http_headers = { "X-Forwarded-For" = "10.0.0.1" }
How CodeWhale Reads DeepSeek Settings
The configuration system uses the Config struct defined at line 294 of crates/config/src/lib.rs. This struct contains a providers: ProvidersToml field that stores your DeepSeek configuration after parsing.
When the runtime initializes, CodeWhale accesses these values through getter methods such as self.providers.deepseek.base_url and self.providers.deepseek.api_key. The TOML key mapping logic resides between lines 657 and 669 of crates/config/src/lib.rs, ensuring that your config.toml values correctly populate the internal structure.
Runtime Implementation
Once configured, the DeepSeek CLI sub-command—handled by crates/cli/src/bin/deepseek_legacy_shim.rs—consumes these settings to build HTTP requests. The runtime constructs the final request URL by combining the base_url with the /v1/chat/completions endpoint and injects the Authorization header using your configured API key.
The implementation pattern follows this structure:
let cfg = Config::load().await?;
let deepseek_cfg = cfg.providers.deepseek;
// Construct request URL using configured base_url
let url = format!(
"{}/v1/chat/completions",
deepseek_cfg.base_url.unwrap_or_else(|| "https://api.deepseek.com/beta".to_string())
);
// Select model from configuration
let model = deepseek_cfg.model.unwrap_or_else(|| "deepseek-v4-pro".to_string());
// Build request with Bearer token authentication
let mut req = http::Request::post(&url)
.header("Authorization", format!("Bearer {}", deepseek_cfg.api_key.unwrap()));
// Apply custom headers if defined in config
if let Some(headers) = &deepseek_cfg.http_headers {
for (k, v) in headers {
req = req.header(k, v);
}
}
Summary
- Primary configuration file: Edit
config.tomlor copy fromconfig.example.tomlin the repository root. - Provider selection: Set
provider = "deepseek"at the top level to enable DeepSeek routing (supportsdeepseek-cnvariant as well). - Endpoint configuration: Use
base_urlto specify either the beta (https://api.deepseek.com/beta) or classic DeepSeek API endpoint. - Authentication and models: Populate
[providers.deepseek]with yourapi_keyand desiredmodel(e.g.,deepseek-v4-pro), referencing line 256 of the example configuration. - Optional headers: Define
http_headerswithin the provider table for proxy or enterprise requirements, parsed at line 530 of the config crate. - Source locations: Configuration parsing occurs in
crates/config/src/lib.rs(lines 294, 657–669), while the runtime implementation resides incrates/cli/src/bin/deepseek_legacy_shim.rs.
Frequently Asked Questions
What is the correct format for the DeepSeek API key in CodeWhale?
Store your API key as a string value assigned to api_key inside the [providers.deepseek] table. The configuration parser in crates/config/src/lib.rs reads this value via the providers.deepseek.api_key mapping and treats it as a sensitive string that never appears in logs or console output.
Can I switch between different DeepSeek models without restarting CodeWhale?
No. CodeWhale loads the model value from [providers.deepseek] during initialization via self.providers.deepseek.model. To switch models (e.g., from deepseek-v4-pro to deepseek-v4-flash), you must modify config.toml and restart the application so the crates/config module re-parses the TOML into the Config struct.
Where does CodeWhale store the parsed DeepSeek configuration?
The TOML values are deserialized into the ProvidersToml struct, specifically within the deepseek field at line 294 of crates/config/src/lib.rs. The mapping logic at lines 657 through 669 translates your configuration keys into Rust struct members used by the runtime.
How do I configure DeepSeek for enterprise environments with custom proxies?
Add the http_headers table inside [providers.deepseek] to inject custom headers such as X-Forwarded-For or proxy authentication tokens. The parser at line 530 of crates/config/src/lib.rs converts these TOML tables into HashMap entries that the runtime iterates over when building the HTTP request in deepseek_legacy_shim.rs.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →