# Pi + DeepSeek v4 Smoke Lane

**Status:** PASS — lane confirmed working
**Owner:** Opencode / Z.ai Integrator
**Date:** 24.may.2026

## Official API Reference

- Docs: <https://api-docs.deepseek.com/>
- Base URL (OpenAI format): `https://api.deepseek.com`
- Base URL (Anthropic format): `https://api.deepseek.com/anthropic`
- API keys: <https://platform.deepseek.com/api_keys>
- Models & pricing: <https://api-docs.deepseek.com/quick_start/pricing>

### Available Models (from `pi --provider deepseek --list-models`)

| pi model ID       | API model ID      | Context | Max output | Thinking | Images |
| ----------------- | ----------------- | ------- | ---------- | -------- | ------ |
| deepseek-v4-flash | deepseek-v4-flash | 1M      | 384K       | yes      | no     |
| deepseek-v4-pro   | deepseek-v4-pro   | 1M      | 384K       | yes      | no     |

Deprecated names (retired 24.jul.2026): `deepseek-chat` → v4-flash
non-thinking, `deepseek-reasoner` → v4-flash thinking.

### Pricing (per 1M tokens)

| Model             | Input (cache hit) | Input (cache miss) | Output  |
| ----------------- | ----------------- | ------------------ | ------- |
| deepseek-v4-flash | $0.0028           | $0.14              | $0.28   |
| deepseek-v4-pro   | $0.003625\*       | $0.435\*           | $0.87\* |

\* 75% promotional discount ends 31.may.2026, then 1/4 of original.

## Key Management

### Environment variable (recommended for smoke tests)

```sh
export DEEPSEEK_API_KEY="<your-key>"
pi --provider deepseek ...
unset DEEPSEEK_API_KEY
```

### pi auth.json (persistent)

```sh
pi --provider deepseek --api-key "<your-key>"
```

This writes to `~/.pi/agent/auth.json`. Pi prefers auth.json over
env vars when both exist.

### Per-command (no env, no file)

```sh
pi --provider deepseek --api-key "<your-key>" -p "hello"
```

### pi provider prefix shorthand

```sh
pi --model deepseek/deepseek-v4-flash -p "hello"
```

The `provider/model` prefix selects the provider automatically — no
`--provider` flag needed.

## Smoke Result

- **Provider:** `deepseek`
- **Model:** `deepseek-v4-flash`
- **API:** `openai-completions`
- **Content:** `COLIBRI_SMOKE_OK` confirmed
- **Thinking:** enabled (v4-flash defaults to thinking mode)
- **Usage:** 3688 input tokens, 32 output tokens
- **Cost:** $0.00052528
- **Event types:** `session`, `agent_start`, `turn_start`, `message_start`,
  `message_end`, `message_update`, `message_update` (many), `turn_end`,
  `agent_end`
- **Capture:** `tmp/deepseek-v4-smoke.jsonl`
- **Verdict:** PASS

## Confirmed Working Commands

```sh
# List models
DEEPSEEK_API_KEY="<your-key>" pi --provider deepseek --list-models

# One-shot JSONL smoke
DEEPSEEK_API_KEY="<your-key>" pi --provider deepseek --model deepseek-v4-flash -p --mode json "hello"

# Shorthand (no --provider needed)
DEEPSEEK_API_KEY="<your-key>" pi --model deepseek/deepseek-v4-flash -p --mode json "hello"
```

## Where to Replace the Test Key

The test key used for the initial smoke has been rotated. To set up a
permanent key, edit:

```
~/.pi/agent/auth.json
```

Or export in your shell profile:

```sh
export DEEPSEEK_API_KEY="<production-key>"
```

## Verifying Key Deletion / Revocation

### 1. Confirm the key is gone from pi

```sh
cat ~/.pi/agent/auth.json
```

If empty `{}`, no stored key. If it contains a `deepseek` entry, remove
it:

```sh
# Back up first
cp ~/.pi/agent/auth.json ~/.pi/agent/auth.json.bak
# Edit to remove the deepseek entry, or wipe entirely:
echo '{}' > ~/.pi/agent/auth.json
```

### 2. Confirm the env var is unset

```sh
echo "DEEPSEEK_API_KEY is set: ${DEEPSEEK_API_KEY:+yes}"
```

If blank, no env key. If still set:

```sh
unset DEEPSEEK_API_KEY
```

### 3. Confirm the revoked key is rejected by the API

```sh
DEEPSEEK_API_KEY="<revoked-key>" pi --provider deepseek --model deepseek-v4-flash -p "test" 2>&1
```

Expected error:

```
401 Authentication Fails, Your api key: ****XXXX is invalid
```

If you see `401`, the key is properly revoked at DeepSeek's side.

### 4. Confirm clean "no key" state

```sh
pi --provider deepseek --model deepseek-v4-flash -p "test" 2>&1
```

Expected error:

```
No API key found for deepseek.
```

If you see this, pi has no stored or env key for DeepSeek — fully clean.

### Error Reference

| Scenario                     | Error message                                                 |
| ---------------------------- | ------------------------------------------------------------- |
| No key at all                | `No API key found for deepseek.`                              |
| Revoked / invalid key        | `401 Authentication Fails, Your api key: ****XXXX is invalid` |
| Rate limited (too many reqs) | `429 Rate limit reached...`                                   |
| Quota exhausted              | `402 Insufficient balance`                                    |

## Deletion Criteria

- Lane confirmed in agent capability table
- Colibri can consume pi JSONL events from this provider
