DeepSeek Harness: Model Configuration

Last updated: 2026-08-31

Models are the Agent's "brain" — choose the right model and configure the connection properly, and the Agent can work efficiently. DSH's model-agnostic design lets you freely switch LLMs — from DeepSeek to GPT-4o to local Ollama — by simply modifying configuration with no code changes.

💡 Tip: DSH supports two model access methods: the official DeepSeek API and OpenAI-compatible endpoints. The latter means any service compatible with the OpenAI API format can be connected — including Ollama, vLLM, Azure OpenAI, and more.

📋 Prerequisites: Completed 03-first-use.md, Web UI running normally

1. What You'll Learn


2. DeepSeek API Key Configuration

(1) Obtaining an API Key

Visit the DeepSeek open platform to get an API Key:

Obtain API Key

TEXT 📖 Display only
2. Register/log in to your account
3. Go to the API Keys page
4. Click "Create API Key"
5. Copy the generated Key (starts with sk-)

Note: The API Key is only shown once at creation time. Save it immediately. If lost, you'll need to create a new one.

(2) Configuring the API Key

Three configuration methods, in order of priority from high to low:

Method 1: Web UI Settings Page (Recommended)

TEXT 📖 Display only
Top control bar → ⚙️ Settings → Models → DeepSeek API Key
┌─────────────────────────────────────────┐
│ DeepSeek API Key                         │
│ sk-•••••••••••••••••••••••••••xxxx       │
│ [Test Connection]  [Save]                │
└─────────────────────────────────────────┘

Click Test Connection to verify connectivity:

Configure API Key

TEXT 📖 Display only
✅ Connection successful!
   Model: deepseek-chat
   Latency: 120ms

Method 2: Environment Variable

BASH
# Configure in .env file or shell
export DEEPSEEK_API_KEY="sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

Method 3: Configuration File

YAML
# dsh.config.yaml
models:
  deepseek:
    api_key: "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    base_url: "https://api.deepseek.com/v1"

(3) Available DeepSeek Models

Model ID Description Context Window Use Cases
deepseek-chat General conversation model 64K tokens Daily programming, Q&A
deepseek-reasoner Reasoning-enhanced model 64K tokens Complex logic, mathematical reasoning
deepseek-coder Code-specific model 16K tokens Code generation, debugging

3. Settings Page Details

(1) ▶ Example 1

Settings Page

TEXT 📖 Display only
┌──────────────────────────────────────────────┐
│ 📡 Model Providers                            │
│                                                │
│ ┌─ DeepSeek ────────────────────────────────┐ │
│ │ API Key: sk-•••••••••xxxx                 │ │
│ │ Base URL: https://api.deepseek.com/v1     │ │
│ │ Default Model: deepseek-chat              │ │
│ │ [Test] [Save]                             │ │
│ └───────────────────────────────────────────┘ │
│                                                │
│ ┌─ OpenAI Compatible ───────────────────────┐ │
│ │ API Key: sk-•••••••••xxxx                 │ │
│ │ Base URL: https://api.openai.com/v1       │ │
│ │ Default Model: gpt-4o                     │ │
│ │ [Test] [Save]                             │ │
│ └───────────────────────────────────────────┘ │
│                                                │
│ [+ Add Provider]                               │
└──────────────────────────────────────────────┘

(2) Configuration Item Descriptions

Configuration Item Description Example
API Key LLM service authentication key sk-xxxxxxxx
Base URL API endpoint address https://api.deepseek.com/v1
Default Model Default model to use deepseek-chat
Max Tokens Maximum tokens per response 4096
Temperature Generation temperature (0-2) 0.7

(3) ▶ Example 3

YAML
# dsh.config.yaml
models:
  deepseek:
    api_key: "${DEEPSEEK_API_KEY}"
    default_model: deepseek-chat
    params:
      temperature: 0.7
      max_tokens: 4096
      top_p: 0.95
  openai:
    api_key: "${OPENAI_API_KEY}"
    default_model: gpt-4o
    params:
      temperature: 0.5
      max_tokens: 8192

Recommended parameters for different scenarios:

Scenario Temperature Max Tokens Notes
Code generation 0.2-0.4 4096+ Low temperature ensures code consistency
Documentation writing 0.5-0.7 4096 Moderate creativity
Creative brainstorming 0.8-1.0 8192+ High temperature encourages diversity
Precise Q&A 0.0-0.2 2048 Most deterministic output

4. OpenAI-Compatible Endpoint Configuration

(1) ▶ Example 1

YAML
# dsh.config.yaml
models:
  openai:
    api_key: "${OPENAI_API_KEY}"
    base_url: "https://api.openai.com/v1"
    default_model: gpt-4o

(2) Azure OpenAI Endpoint

YAML
# dsh.config.yaml
models:
  azure:
    api_key: "${AZURE_OPENAI_API_KEY}"
    base_url: "https://your-resource.openai.azure.com/openai/deployments/your-deployment"
    default_model: gpt-4o
    headers:
      api-key: "${AZURE_OPENAI_API_KEY}"

(3) Local Ollama Endpoint

YAML
# dsh.config.yaml
models:
  ollama:
    api_key: "ollama"           # Ollama doesn't need a real Key
    base_url: "http://localhost:11434/v1"
    default_model: llama3.2

(4) Custom Endpoint

Any service compatible with the OpenAI API format can be connected:

YAML
# dsh.config.yaml
models:
  custom:
    api_key: "${CUSTOM_API_KEY}"
    base_url: "https://your-llm-service.com/v1"
    default_model: your-model-name
    headers:
      X-Custom-Header: "custom-value"

Plugin Architecture

LLM Adapter

(5) Multi-Endpoint Architecture

100%
graph TB
    DSH[DeepSeek Harness] -->|Provider 1| DS[DeepSeek API<br/>deepseek-chat]
    DSH -->|Provider 2| OAI[OpenAI<br/>gpt-4o]
    DSH -->|Provider 3| OLL[Ollama<br/>llama3.2]
    DSH -->|Provider 4| AZ[Azure OpenAI<br/>gpt-4o]

5. Model Routing and Multi-Model Selection

(1) Switching Models in Web UI

Switch models using the dropdown in the top control bar:

TEXT 📖 Display only
[deepseek-chat ▼]
┌──────────────────────────┐
│ ● deepseek-chat          │
│   DeepSeek · 64K ctx     │
│                          │
│ ○ gpt-4o                 │
│   OpenAI · 128K ctx      │
│                          │
│ ○ llama3.2               │
│   Ollama · 8K ctx        │
└──────────────────────────┘

(2) Model Routing Strategy

DSH supports automatically routing to different models based on task type:

YAML
# dsh.config.yaml
routing:
  rules:
    - match:
        mode: ptc            # PTC mode
      model: deepseek-reasoner   # Use reasoning model for planning
    
    - match:
        tool: file_edit      # File editing
      model: deepseek-coder  # Use code model
    
    - match:
        mode: creative       # Creative mode
      model: gpt-4o          # Use GPT-4o
    
    - match:
        default: true        # Default route
      model: deepseek-chat

(3) Routing Flow

100%
graph TD
    INPUT[User Input] --> CHECK{Match Routing Rules}
    CHECK -->|PTC Mode| R1[deepseek-reasoner]
    CHECK -->|file_edit Tool| R2[deepseek-coder]
    CHECK -->|Creative Mode| R3[gpt-4o]
    CHECK -->|Default| R4[deepseek-chat]

(4) Specifying Models in CLI Mode

BASH
# Specify model at startup
npx @deepseek-ai/dsh cli --model gpt-4o

# Switch models during a session (CLI internal command)
/model deepseek-reasoner

6. API Key Security Management

(1) Security Principles

Principle Description
No hardcoding API Keys should not be written directly in code
Don't commit to Git Add .env file to .gitignore
Least privilege Only configure necessary service access permissions
Regular rotation Periodically replace API Keys
Audit logs Monitor API Key usage

(2) Environment Variable Management

BASH
# .env file (not committed to Git)
DEEPSEEK_API_KEY=sk-xxxxxxxxxxxxxxxx
OPENAI_API_KEY=sk-yyyyyyyyyyyyyyyy

# .env.example file (committed to Git, for team reference)
DEEPSEEK_API_KEY=your-deepseek-api-key
OPENAI_API_KEY=your-openai-api-key
BASH
# .gitignore
.env
.env.local
.env.*.local

(3) Variable References in Configuration Files

DSH configuration files support environment variable references to avoid hardcoding:

YAML
# dsh.config.yaml — Use ${VAR} to reference environment variables
models:
  deepseek:
    api_key: "${DEEPSEEK_API_KEY}"    # Read from environment variable at runtime
    base_url: "https://api.deepseek.com/v1"
  openai:
    api_key: "${OPENAI_API_KEY}"
    base_url: "https://api.openai.com/v1"

(4) Secret Management Service Integration

For enterprise deployments, professional secret management services are recommended:

Key Management

YAML
models:
  deepseek:
    api_key:
      vault: aws-secrets-manager
      secret_id: "dsh/deepseek-api-key"
      region: "us-east-1"

(5) Key Leak Emergency Response

TEXT 📖 Display only
1. Immediately disable/delete the leaked Key on the API provider's platform
2. Generate a new Key and update configuration
3. Check API call logs to confirm no abnormal usage
4. Review Git history to ensure the Key hasn't been committed (if committed, use git filter-branch to remove it)

7. Connection Troubleshooting

(1) Common Errors and Solutions

Error Message Cause Solution
Invalid API key Key is wrong or expired Regenerate Key and configure

Connection Troubleshooting

| Connection refused | Endpoint address is wrong | Check Base URL | | Rate limit exceeded | API call frequency exceeded | Reduce request frequency or upgrade plan | | Model not found | Model ID is wrong | Check model name spelling | | Timeout | Network unreachable | Check proxy settings or firewall |

(2) Connection Test Commands

BASH
# Test DeepSeek API
curl -s https://api.deepseek.com/v1/models \
  -H "Authorization: Bearer $DEEPSEEK_API_KEY"

# Test OpenAI-compatible endpoint
curl -s https://api.openai.com/v1/models \
  -H "Authorization: Bearer $OPENAI_API_KEY"

# Test local Ollama
curl -s http://localhost:11434/v1/models

(3) Proxy Configuration

If you need to access the API through a proxy:

BASH
# Set HTTP proxy
export HTTP_PROXY="http://proxy.example.com:8080"
export HTTPS_PROXY="http://proxy.example.com:8080"

# Or specify in configuration file
# dsh.config.yaml
models:
  deepseek:
    api_key: "${DEEPSEEK_API_KEY}"
    base_url: "https://api.deepseek.com/v1"
    proxy: "http://proxy.example.com:8080"

❓ FAQ

Q Can I configure multiple model providers simultaneously?
A Yes. DSH supports configuring DeepSeek, OpenAI, Ollama, and other providers simultaneously, with one-click switching in the Web UI.
Q Is the free API Key enough?
A DeepSeek new users typically get free credits, suitable for learning and testing. However, for long-term use, we recommend purchasing a formal plan; free credits may not be sufficient for complex Agent tasks.
Q How do I know which model is currently in use?
A The Web UI top control bar displays the current model name. In CLI mode, enter /model to view the current model.
Q Is context preserved after switching models?
A Session context (conversation history) is preserved, but different models have different context window sizes — if history exceeds the window, earlier messages will be truncated.
Q Are Ollama local models effective?
A It depends on model size and quantization level. 7B parameter models are suitable for simple tasks; 70B+ models approach cloud performance but require significant GPU resources.
Q My API Key is configured but I still get connection errors. What should I do?
A Troubleshoot in order: 1) Is the Key correct (no extra spaces); 2) Is the Base URL correct; 3) Is the network connected; 4) Is a proxy needed.

📖 Summary


📝 Exercises

1. ⭐ Basic: Configure a DeepSeek API Key, successfully send a message in the Web UI and receive a reply. Save a screenshot of the connection test results.

2. ⭐⭐ Intermediate: Configure both DeepSeek and OpenAI model providers, switch between the two models in the same session, and compare the differences in responses to the same question.

3. ⭐⭐⭐ Challenge: Configure an Ollama local model endpoint, and write model routing rules — route code editing operations to DeepSeek Coder, creative tasks to GPT-4o, and use DeepSeek Chat as the default. Verify that routing works as expected.

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏