# A Coding Agent for a Third of a Dollar: Pi, DeepSeek and Qwen on OpenRouter

> I pointed the pi coding agent at five open-weight models through OpenRouter (DeepSeek V4 Flash and Pro, Qwen3-Coder-Next, Qwen3.8-27B and Qwen3.6-35B-A3B) and graded them on the same tasks with hidden tests. 18 agent sessions cost $0.31. The interesting findings were about upstream providers, quantization and sandboxing, not the leaderboard.

Author: Kevin Cearns · Published: 2026-11-08 · Source: https://kcearns.tech/writing/pi-coding-agent-open-weight-models-openrouter
Most of what I've written about open-weight models assumes you host them yourself: [vLLM on Kubernetes](/writing/self-hosting-llms-kubernetes), a [hybrid router](/writing/hybrid-ai-local-cloud-models) in front, GPUs you pay for whether or not anyone is typing. That is the right answer at team scale. For one developer who wants a capable coding agent that is not tied to a single frontier lab, there is a much shorter path: a model-agnostic harness and an aggregator that already hosts every open-weight model worth trying.

This post uses [pi](https://pi.dev), a small terminal coding agent, with [OpenRouter](https://openrouter.ai) as the model provider. I ran five DeepSeek and Qwen models through the same two tasks, graded the results with tests the models never saw, and logged every token. Eighteen agent sessions cost **$0.31** in total.

The leaderboard turned out to be the least interesting part. What mattered more was which company actually served each request, what precision it ran at, and one agent that quietly started working in the wrong directory.

## Why pi

Pi is a deliberately minimal harness. Out of the box the model gets four tools (`read`, `bash`, `edit`, `write`) and a system prompt short enough to read in one sitting. Everything else (MCP, skills, extra tools, custom UI) is opt-in through extensions. That suits model comparison well: a smaller harness adds less of its own behaviour, so differences between runs come mostly from the model.

The parts that matter here:

- **Model-agnostic by design.** Pi speaks to dozens of providers, and `--model provider/id` switches between them per run. OpenRouter is a built-in provider.
- **Print and JSON modes.** `pi -p` runs a prompt to completion and exits. `--mode json` streams every agent event (each assistant message with its token usage and cost, every tool call) as JSONL. That is all you need to benchmark.
- **Sessions as files.** Interactive sessions are JSONL trees you can resume, fork or export to HTML.

Install it and log in to OpenRouter:

```bash
npm install -g @earendil-works/pi-coding-agent
pi            # then: /login openrouter
# or: export OPENROUTER_API_KEY=sk-or-...
```

With a key configured, pi lists only the OpenRouter models that key is allowed to use, along with context size and pricing:

```bash
$ pi --list-models qwen3.8
provider    model                  context  max-out  thinking  images
openrouter  qwen/qwen3.8-27b       1M       131.1K   yes       yes
openrouter  qwen/qwen3.8-flash     1M       131.1K   yes       yes
...
```

Then pick one per session:

```bash
pi --model openrouter/deepseek/deepseek-v4-flash
pi --model openrouter/qwen/qwen3-coder-next "why is this test flaky?"
```

Inside the TUI, `/model` switches mid-session, and `--models "openrouter/deepseek/*,openrouter/qwen/qwen3.8-*"` limits `Ctrl+P` cycling to a shortlist.

## The test bench

Both tasks use a small token-bucket rate limiter in plain JavaScript, tested with `node --test`. Neither has dependencies or a build step.

**Task 1: fix three bugs.** The limiter treats milliseconds as seconds when it refills, never caps the bucket at capacity, and reports `retryAfterMs` in seconds. Five visible tests fail. The prompt: *find and fix the bugs, don't touch the tests, run them to confirm.*

**Task 2: implement a spec.** Starting from a fixed limiter, a `SPEC.md` asks for five things: LRU eviction behind a `maxKeys` option, a side-effect-free `peek()`, `Infinity` for requests larger than capacity, whole-millisecond rounding, and a `RangeError` for invalid costs. The agent writes its own tests. I then grade the result with **eleven hidden tests** copied in only after the agent exits. Several of them target edge cases a careless implementation gets wrong: a denied request still counts as a "use" for LRU, `peek()` must not reorder the LRU, and an invalid cost must not evict anything.

Every run gets a fresh copy of the repo and the same flags, so the harness adds as little as possible:

```bash
#!/usr/bin/env bash
# run.sh <openrouter-model-id> <run-number>
set -u
M="$1"; R="$2"; N=$(echo "$M" | tr '/:~' '___')_r$R
D=runs/$N; rm -rf "$D"; cp -r task "$D"; cd "$D"

pi -p --mode json --no-session \
   --no-skills --no-extensions --no-context-files \
   --model "openrouter/$M" \
   "Implement SPEC.md. Run npm test when you are done and make sure everything passes." \
   < /dev/null > "../$N.jsonl"

mkdir -p hidden && cp ../../hidden/hidden.test.js hidden/   # imports ../src/limiter.js
node --test --test-reporter=tap hidden/ | grep '^# pass'
```

Note the `< /dev/null`. Without it, `pi -p` waits for stdin and a background job sits there until it times out. That cost me one ten-minute run.

Cost and token counts come straight from the event stream. Pi records OpenRouter's reported cost on every assistant message:

```bash
jq -s '[.[] | select(.type=="message_end" and .message.role=="assistant")
        | .message.usage.cost.total] | add' run.jsonl
```

## Results

**Task 1 was too easy to separate anyone.** All five models found all three bugs and passed in 13 to 34 seconds. Their fixes were nearly identical: `Math.min(capacity, ...)` around the refill, `/ 1000` on the elapsed time, `* 1000` on the retry. The most expensive run cost 1.4¢ and the cheapest 0.14¢.

**Task 2** is where they diverged. Each model ran twice, unpinned, letting OpenRouter pick the upstream provider:

| Model | Hidden tests (run 1, run 2) | Cost per run | Wall time | Served by |
|---|---|---|---|---|
| DeepSeek V4 Flash | 11/11, 11/11 | $0.004, $0.004 | 50–60 s | Wafer (MXFP4), GMICloud (FP8) |
| DeepSeek V4 Pro | 11/11, 11/11 | $0.038, $0.020 | 160–190 s | Baidu + SiliconFlow, Baidu (FP8) |
| Qwen3-Coder-Next | 11/11, 11/11 | $0.029, $0.014 | 80–180 s | Parasail (BF16) |
| Qwen3.8-27B | 11/11, 11/11 | $0.021, $0.075 | 45–75 s | DekaLLM, Phala (undisclosed) |
| Qwen3.6-35B-A3B | **10/11, 9/11** | $0.019, $0.014 | 60–90 s | DekaLLM (undisclosed) |

Two runs per model is an anecdote, not a benchmark, so read this as a field report. A few things still stand out.

**DeepSeek V4 Flash is absurdly cheap for what it does.** It passed every hidden test for under half a cent per task, which is about a tenth of what Pro cost for the same result. On tasks this size, Pro's extra reasoning bought nothing measurable.

**Cost variance comes from the provider as much as the model.** The two V4 Pro runs used similar token counts (about 50k uncached input and 12k output each) and cost $0.038 and $0.020. The expensive run moved from Baidu to SiliconFlow partway through the session. Qwen3.8-27B's $0.075 run is a different story: that run produced 25k output tokens, mostly reasoning. Pi defaults to a `high` thinking level for reasoning models. If that is more than you need, `--thinking low` or a `:low` suffix on the model ID lowers it.

**The small MoE made a real-world mistake.** Qwen3.6-35B-A3B activates only about 3B parameters per token, and its misses were instructive. One run returned `remaining: 0` for an impossible request instead of the real balance. The other tracked LRU order using each bucket's last-refill timestamp:

```js
#evictIfNecessary() {
  let lruKey = null, lruTime = Infinity;
  for (const [k, b] of this.buckets) {
    if (b.last < lruTime) { lruKey = k; lruTime = b.last; }
  }
  if (lruKey !== null) this.buckets.delete(lruKey);
}
```

That works until two requests arrive in the same millisecond, which happens constantly in production and on every call in a test with a frozen clock. Both timestamps tie, and the wrong key gets evicted. The model's own tests passed because it never tested a tie. The models that got it right used the `Map`'s insertion order instead, deleting a key and re-inserting it on every use:

```js
const existing = this.buckets.get(key);
if (existing) {
  this.buckets.delete(key);       // move to most-recently-used
  this.buckets.set(key, existing);
  return existing;
}
if (this.buckets.size >= this.maxKeys) {
  this.buckets.delete(this.buckets.keys().next().value); // oldest
}
```

This is why the hidden tests exist. An agent that writes its own tests and reports "all passing" has only shown that its tests agree with its code.

## You are not choosing a model, you are choosing a host

The "Served by" column is the part of the table most people never look at. Because the weights are public, OpenRouter does not run these models itself. It routes each request to one of many inference companies. At the time of writing, OpenRouter's endpoint list showed 14 hosts for DeepSeek V4 Flash and 24 for Qwen3.8-27B, at precisions ranging from FP4 to BF16. Some hosts do not disclose their precision at all.

```bash
curl -s https://openrouter.ai/api/v1/models/qwen/qwen3.8-27b/endpoints \
  | jq -r '.data.endpoints[] | "\(.provider_name)\t\(.quantization)"'
```

Unpinned, the model ID decides only *which* model you get. The host, the precision and the price can all change from one session to the next, and even between turns within one session.

So I re-ran Qwen3.6-35B-A3B pinned to FP8 or BF16 hosts with fallbacks disabled. Pi passes OpenRouter's [provider routing](https://openrouter.ai/docs/guides/routing/provider-selection) options through a per-model override in `~/.pi/agent/models.json`:

```json
{
  "providers": {
    "openrouter": {
      "modelOverrides": {
        "qwen/qwen3.6-35b-a3b": {
          "compat": {
            "openRouterRouting": {
              "quantizations": ["fp8", "bf16"],
              "data_collection": "deny",
              "allow_fallbacks": false
            }
          }
        }
      }
    }
  }
}
```

Every request then went to Parasail at FP8, and the two valid pinned runs both scored 11/11. Three samples cannot prove that the undisclosed-precision host caused the earlier misses, and I'm not claiming it did. But it does mean the unpinned results were not a fair test of the *model*, and that applies to every comparison like this one, including leaderboards.

To see which host served a given turn, take the `responseId` that pi logs on each assistant message and ask OpenRouter:

```bash
curl -s -H "Authorization: Bearer $OPENROUTER_API_KEY" \
  "https://openrouter.ai/api/v1/generation?id=$GEN_ID" | jq '.data.provider_name'
```

`data_collection: "deny"` is worth setting regardless. It excludes hosts that may store or train on your prompts, which matters once the agent is reading a real codebase rather than a toy rate limiter.

## The run that worked on someone else's code

The third pinned run reported success. It said it had found and fixed a failing test called "H8", then announced "all 22 tests pass." The hidden tests are named H1 to H11, and that agent should never have seen them. Its own working directory was untouched.

The JSONL showed what happened. Pi's system prompt correctly gave the agent its working directory:

```
<cwd>
/…/scratchpad/runs2/qwen_qwen3.6-35b-a3b_r3
</cwd>
```

The model's first tool call read `/…/runs2/qwen_qwen3.6-35b-a3b_r1/SPEC.md`. It got one character wrong while copying a long absolute path, and `_r1` happened to be a real directory: an earlier, already-graded run that included the hidden tests. From then on the agent worked entirely there. It read the hidden tests, ran them, and edited the other run's source code until they passed. It never noticed it was in the wrong place, because everything it found looked like the task it had been given.

I caught it only because the grader checked the agent's own directory. That was one escape in 18 sessions, and it was harmless here because everything was a scratch copy. But the same slip in a real environment, `~/work/api-v2` instead of `~/work/api-v3` for example, means an agent confidently editing the wrong repository.

Pi's documentation is upfront about this. It does not sandbox tool calls: `bash` and `edit` run with the permissions of the user who started pi, and it does not ask before each call. That is a reasonable choice for a minimal harness, but it means isolation is your job, especially when the model in the loop is a cheap one you are evaluating:

- **Run the whole process in a container** that mounts only the project. The pi docs ship a short `Dockerfile` for this. Do not mount `~/.pi/agent` into it unless you want the container to have your keys.
- **Use a sandbox that keeps credentials on the host**, such as Docker Sandboxes or OpenShell, which the docs compare side by side.
- **For read-only work, remove the write tools entirely:** `pi --tools read,grep,find,ls`.
- **For evaluations, isolate each run** so sibling directories are not reachable at all. A per-run container or a [Firecracker microVM](/writing/eve-agent-firecracker-aws-cdk) is enough.

I covered the server-side version of this in [securing self-hosted LLM agents](/writing/securing-self-hosted-llm-agents-kubernetes). The same reasoning applies on a laptop: assume the agent will eventually act on the wrong file, and limit what it can reach.

## What I'd actually use

For day-to-day coding with open-weight models through pi:

- **Default to DeepSeek V4 Flash.** It passed every graded test I gave it at well under a cent per task. At that price you can afford to run it twice and compare the results.
- **Use Qwen3-Coder-Next for long, tool-heavy sessions.** It took the most turns of any model (about 20 per task), checking its work in small steps. That suits agent loops well, and its only host serves full BF16.
- **Use DeepSeek V4 Pro or a reasoning-heavy Qwen when the task needs judgement**, and cap the thinking level when it doesn't.
- **Pin every model you rely on** to known precisions with `data_collection: "deny"`. Unpinned routing is convenient for exploring, but not something to depend on.
- **Grade with tests the agent cannot see**, and confirm the files it changed are the ones you meant.

The total for this experiment, including the run that graded itself in the wrong directory, was 31 cents. Trying a new open-weight model now costs a one-line `--model` change and a few cents. The lessons cost nothing extra, but they only show up if you log every turn and read what the agent actually did.