Configure DeepSeek API for Pi Coding Agent
Pi Agent is a lightweight terminal autonomous coding agent. Follow these steps to configure DeepSeek models in models.json and manage API credentials.
On this page
Ensure the pi CLI tool is installed and obtain an API key from the DeepSeek Platform.
Edit the models.json configuration file
Locate or create models.json in your user home directory:
- macOS / Linux:
~/.pi/agent/models.json - Windows:
%USERPROFILE%\.pi\agent\models.json
Add the DeepSeek OpenAI-compatible provider definition:
{
"providers": {
"deepseek": {
"baseUrl": "https://api.deepseek.com",
"api": "openai-completions",
"apiKey": "$DEEPSEEK_API_KEY"
}
}
}Configure API key credentials
Export the key in your shell profile (~/.zshrc or ~/.bashrc):
export DEEPSEEK_API_KEY="sk-your_deepseek_api_key"For Windows PowerShell sessions:
$env:DEEPSEEK_API_KEY="sk-your_deepseek_api_key"Or save the key directly in ~/.pi/agent/auth.json:
{
"deepseek": {
"type": "api_key",
"key": "sk-your_deepseek_api_key"
}
}Launch and select model
- Run
piin your terminal. - Press
Ctrl+Por type/modelto open the selector. - Choose deepseek and select deepseek-chat or deepseek-reasoner.
- Send a non-destructive verification prompt:
Reply only with "DeepSeek connected to Pi Agent successfully." Do not modify files.Status bar balance tracker
Install the community balance widget to inspect remaining API credits in your status line:
pi install git:github.com/carlos-reynosa/pi-deepseek-balance-statusTroubleshooting
MISSING_CREDENTIAL Error
Verify that DEEPSEEK_API_KEY is exported in the active session before launching pi, or verify auth.json.
Connection Refused / Malformed URL
Ensure baseUrl is exactly https://api.deepseek.com with the https:// scheme and no trailing slash.
402 Insufficient Balance
Top up credit balance on the DeepSeek Platform.