Pi Agent Integration with DeepSeek

DeepSeek provides an OpenAI-compatible API, so you can reuse Pi's existing OpenAI adapter layer without developing a separate adapter for DeepSeek.

The core work for integration is only two things: declare the provider and model parameters in models.json, and provide the API Key via environment variables.

The overall architecture is shown in the following diagram:

Pi 接入 DeepSeek 架构图

The so-called "OpenAI-compatible API" means the provider's HTTP interface protocol is consistent with OpenAI. As long as the protocol is compatible, any tool that supports OpenAI can call it directly; DeepSeek belongs to this category.


Install Pi

Pi depends on the Node.js runtime. Before installing, please make sure Node.js is ready.

Install Node.js

Download the installer for your system from the official Node.js website and install it with the default options.

Install Pi CLI

Install globally via npm in the terminal:

npm install -g --ignore-scripts @earendil-works/pi-coding-agent

Linux and macOS users can also use the official installation script to install with one command:

curl -fsSL https://pi.dev/install.sh | sh

Verify Installation

Run the following command. If the version number prints normally, the installation was successful:

pi --version

Output similar to:

0.83.0

Configure DeepSeek Provider

Pi defines custom model providers through models.json. This section integrates DeepSeek as an OpenAI-compatible API.

Configuration File Path

Different operating systems have different configuration paths. Please follow the one for your system:

Operating SystemConfiguration File Path
Linux / macOS~/.pi/agent/models.json
Windows%USERPROFILE%\.pi\agent\models.json

Write models.json

Write the following content into the configuration file:

{
  "providers": {
    "deepseek": {
      "baseUrl": "https://api.deepseek.com",
      "api": "openai-completions",
      "apiKey": "$DEEPSEEK_API_KEY",
      "models": [
        {
          "id": "deepseek-v4-pro",
          "name": "DeepSeek V4 Pro",
          "contextWindow": 1000000,
          "maxTokens": 384000,
          "input": ["text"],
          "reasoning": true,
          "cost": {
            "input": 1.74,
            "output": 3.48,
            "cacheRead": 0.145,
            "cacheWrite": 0
          },
          "compat": {
            "requiresReasoningContentOnAssistantMessages": true,
            "thinkingFormat": "deepseek",
            "reasoningEffortMap": {
              "minimal": "high",
              "low": "high",
              "medium": "high",
              "high": "high",
              "xhigh": "max"
            }
          }
        },
        {
          "id": "deepseek-v4-flash",
          "name": "DeepSeek V4 Flash",
          "contextWindow": 1000000,
          "maxTokens": 384000,
          "input": ["text"],
          "reasoning": true,
          "cost": {
            "input": 0.14,
            "output": 0.28,
            "cacheRead": 0.028,
            "cacheWrite": 0
          },
          "compat": {
            "requiresReasoningContentOnAssistantMessages": true,
            "thinkingFormat": "deepseek",
            "reasoningEffortMap": {
              "minimal": "high",
              "low": "high",
              "medium": "high",
              "high": "high",
              "xhigh": "max"
            }
          }
        }
      ]
    }
  }
}

Configuration Item Explanation

The following explains the main fields used in models.json one by one:

FieldTypeRequired?DescriptionDefault Value
baseUrlstringRequiredThe OpenAI-compatible API endpoint for DeepSeekhttps://api.deepseek.com
apistringRequiredIntegration protocol; declares the use of the OpenAI Completions-compatible protocolopenai-completions
apiKeystringRequiredReads the key from an environment variable with the same name; no need to write the key in plain text in the configuration file$DEEPSEEK_API_KEY
contextWindownumberRequiredContext window size (tokens)1000000
maxTokensnumberRequiredMaximum output length per request (tokens)384000
reasoningbooleanOptionalDeclares that the model supports chain-of-thought (reasoning) capabilitytrue
costobjectOptionalRecords unit prices for input/output/cache hits, used by the Pi interface to estimate costs—
requiresReasoning
ContentOnAssistantMessages
booleanRecommendedIn multi-turn conversations, assistant messages need to keep the reasoning_content field; otherwise compatibility issues may occurtrue
thinkingFormatstringRecommendedParses and displays the reasoning process according to DeepSeek's specific thinking content formatdeepseek
reasoningEffortMapobjectRecommendedMaps Pi's reasoning effort levels to the levels actually supported by DeepSeek—

reasoningEffortMap maps Pi's five reasoning levels (minimal / low / medium / high / xhigh) to the levels supported by DeepSeek. Except for xhigh mapping to max, all the others converge to high.

Model Selection

The configuration declares two DeepSeek models. The main differences are as follows:

ModelContext WindowMax OutputInput Unit PriceOutput Unit PriceCache Hit Unit PriceApplicable Scenarios
deepseek-v4-pro1,000,000384,0001.743.480.145Stronger reasoning capability, suitable for complex tasks
deepseek-v4-flash1,000,000384,0000.140.280.028Faster response, lower cost

Unit prices are in US dollars per million tokens.

Obtain and Set API Key

First apply for an API Key on the DeepSeek open platform:https://platform.deepseek.com/api_keys。

For Linux / macOS, export the environment variable in the terminal:

export DEEPSEEK_API_KEY="你的 DeepSeek API Key"

For Windows (PowerShell), set it as follows:

$env:DEEPSEEK_API_KEY="你的 DeepSeek API Key"

It is recommended to write the export command into the shell configuration (such as ~/.bashrc, ~/.zshrc, or PowerShell Profile) to avoid having to set it again every time you open a new terminal.

Please replace "your DeepSeek API Key" in the example with your real key. The API Key is sensitive information; please keep it safe and never commit it to a repository.


Run and Test

Once configured, you can start Pi and switch to the DeepSeek model.

Start Pi

Enter the project directory:

cd ~/example-test/

Directly run the pi command:

pi

Switch to DeepSeek Model

After entering the interactive interface, switch by following these steps:

  1. Input/modelOpen the model selector.

  2. Select the deepseek provider, then choose DeepSeek-V4-Pro or DeepSeek-V4-Flash.

  3. Next, query the current model.

After switching, you can start coding directly in this minimalist terminal framework.

Suggested Test Steps

Verify whether the integration is complete and usable by going through the checklist below:

Test ItemOperation MethodExpected Result
Authentication and ConnectivitySend a sentence, for example, "Hello, please introduce the example learning platform"Receive a normal reply with no 401 / 403 authentication errors, confirming that apiKey and baseUrl are configured correctly
Reasoning CapabilityAsk a question that requires multi-step reasoning, such as asking it to analyze first and then provide a solutionOutput a visible thinking process, indicating that thinkingFormat and reasoning are in effect
Multi-turn Tool CallsHave Pi continuously call tools to read files, run commands, modify code, and verify resultsMulti-turn conversation stays stable without errors caused by missing reasoning_content
Reasoning Effort SwitchingIn /model, switch from medium to xhighBehavior conforms to the reasoningEffortMap mapping; xhigh corresponds to DeepSeek's max
Cost CalculationAfter running a few real tasks, check the cost statisticsThe interface statistics match the unit prices set in the cost field

Among these, "Multi-turn Tool Calls" is the key scenario for verifying whether the requiresReasoningContentOnAssistantMessages configuration is correct.


Common Troubleshooting

If you encounter issues during integration, use the following checklist to quickly locate them.

Can't See DeepSeek in Model Selector

Check whether the models.json path is correct. The paths for Windows and Linux / macOS are different.

Also confirm that the JSON format has no syntax errors, such as trailing commas or unclosed quotes.

Authentication Failed

Confirm that the DEEPSEEK_API_KEY environment variable has been set correctly.

Note: The terminal session where you run the pi command must be the same session where you set the environment variable.

Multi-turn Tool Calls Report Errors

First check whether requiresReasoningContentOnAssistantMessages and thinkingFormat have been fully configured as described above.

Need More Customization Capabilities

You can refer toPi official models documentation, for more comprehensive configuration options.

Other extensions