Pi Agent Integrating 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 of integration is just two things: declare the provider and model parameters in models.json, and provide the API Key through an environment variable.
The overall architecture is shown below:
The so-called 'OpenAI-compatible API' means the provider's HTTP interface protocol stays consistent with OpenAI. As long as the protocol is compatible, any tool that supports OpenAI can call it directly, and DeepSeek falls into this category.
Install Pi
Pi depends on the Node.js runtime; before installing, make sure Node.js is ready.
Install Node.js
Download the installer for your system from the Node.js official site and install with the default options.
Install the 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 install with one command using the official install script:
curl -fsSL https://pi.dev/install.sh | sh
Verify the installation
Run the following command; if the version number prints normally, the installation succeeded:
pi --version
Output similar to:
0.83.0
Configure the DeepSeek provider
Pi defines custom model providers through models.json; this section integrates DeepSeek as an OpenAI-compatible API.
Configuration file paths
Configuration paths differ by operating system; choose the one for your system:
| Operating system | Configuration file paths |
|---|---|
| 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 analysis
The main fields used in models.json are explained one by one below:
| Field | Type | Required | Description | Default value |
|---|---|---|---|---|
| baseUrl | string | Required | DeepSeek's OpenAI-compatible API address | https://api.deepseek.com |
| api | string | Required | Integration protocol, declaring use of the OpenAI Completions compatible protocol | openai-completions |
| apiKey | string | Required | Read the secret from the same-named environment variable; no need to write the Key in plain text into the config file | $DEEPSEEK_API_KEY |
| contextWindow | number | Required | Context window size (tokens) | 1000000 |
| maxTokens | number | Required | Maximum single output length (tokens) | 384000 |
| reasoning | boolean | Optional | Declare that the model supports chain-of-thought (reasoning) capability | true |
| cost | object | Optional | Record unit prices for input/output/cache hits, etc., used by the Pi interface to estimate cost | — |
| requiresReasoning | ||||
| ContentOnAssistantMessages | boolean | Recommend | In multi-turn conversations, assistant messages must retain the reasoning_content field, otherwise compatibility issues may occur | true |
| thinkingFormat | string | Recommend | Parse and display the reasoning process according to DeepSeek's specific thinking content format | deepseek |
| reasoningEffortMap | object | Recommend | Map 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 DeepSeek's supported levels; except xhigh mapping to max, all others converge to high.
Model selection
The configuration declares two DeepSeek models; the main differences are as follows:
| Model | Context window | Max output | Input unit price | Output unit price | Cache hit unit price | Applicable scenarios |
|---|---|---|---|---|---|---|
| deepseek-v4-pro | 1,000,000 | 384,000 | 1.74 | 3.48 | 0.145 | Stronger reasoning capability, suitable for complex tasks |
| deepseek-v4-flash | 1,000,000 | 384,000 | 0.14 | 0.28 | 0.028 | Faster response, lower cost |
Unit prices are per million tokens (USD).
Obtain and set the API Key
First apply for an API Key on the DeepSeek open platform:https://platform.deepseek.com/api_keys。

Linux / macOS: export the environment variable in the terminal:
export DEEPSEEK_API_KEY="你的 DeepSeek API Key"
Windows (PowerShell) setup:
$env:DEEPSEEK_API_KEY="你的 DeepSeek API Key"
It's recommended to write the export command into your shell config (such as ~/.bashrc, ~/.zshrc, or PowerShell Profile) to avoid resetting it every time you open a new terminal.
Replace 'your DeepSeek API Key' in the example with the real key. The API Key is sensitive information; keep it safe and never commit it to the repository.
Run and test
Once configured, you can start Pi and switch to the DeepSeek model.
Start Pi
Enter the project directory:
cd ~/runoob-test/
Directly run the pi command:
pi
Switch to the DeepSeek model
After entering the interactive interface, switch with the following steps:
-
Input /model Open the model selector.

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

-
Then ask about the current model

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

Recommended test steps
Verify the integration is fully working item by item using the checklist below:
| Test item | Operation method | Expected result |
|---|---|---|
| Authentication and connectivity | Send a message, e.g. 'hello, please introduce the runoob learning platform' | Get a normal reply with no 401 / 403 authentication errors, indicating apiKey and baseUrl are configured correctly |
| Reasoning capability | Ask a question requiring multi-step reasoning, e.g. have it analyze first then give a solution | Visible thinking process in the output, indicating thinkingFormat and reasoning are effective |
| Multi-turn tool calls | Have Pi call tools consecutively to read files, run commands, modify code, and verify results | Multi-turn conversation is stable, no errors from lost reasoning_content |
| Reasoning effort switching | Switch from medium to xhigh in /model | Behavior matches the reasoningEffortMap mapping, with xhigh corresponding to DeepSeek's max |
| Cost accounting | Run a few rounds of real tasks then check the cost statistics | Interface statistics match the unit prices set in the cost field |
Among these, 'multi-turn tool calls' is the key scenario for verifying whether requiresReasoningContentOnAssistantMessages is configured correctly.
Troubleshooting common problems
If you encounter problems during integration, use the checklist below to quickly locate them.
DeepSeek not visible in the model selector
Check that the models.json path is correct; paths differ between Windows and Linux / macOS.
Also confirm the JSON format has no syntax errors, such as extra commas or unclosed quotes.
Authentication failure
Confirm the DEEPSEEK_API_KEY environment variable is set correctly.
Note: the terminal session running the pi command must be the same one where the environment variable was set.
Multi-turn tool call errors
First check whether requiresReasoningContentOnAssistantMessages and thinkingFormat are fully configured as described above.
Need more customization capability
You can refer to Pi official models documentation, for a more complete set of configuration options.