Pygg: an LLM gateway that journals each attempt to disk before sending it
Pygg sits between coding agents and LLM providers on 127.0.0.1. A few design choices that might interest this sub:
- Write-ahead journal: an attempt is written to SQLite before the request leaves, and settled with its ledger entry in one transaction, so a crash still leaves a record of every request that went out.
- Budget holds: a key with a monthly limit reserves the attempt's estimated cost first, so concurrent requests cannot pass the limit together.
- Three wire formats (OpenAI Chat Completions, OpenAI Responses, Anthropic Messages), streamed with tool calls; the same format passes through untouched, other pairs are translated and say what they dropped.
- Fallback only before the first byte reaches the agent; a timeout is never resent by default.
- About 4 ms of overhead per short request and ~230 req/s with 16 clients on one PC, measured against a fake provider.
Setup: 12 harder coding tasks, 3 runs each, checks the agent cannot edit. Claude Code, same prompts, routed through a local gateway so I could log every request's tokens and cost.
- Haiku 5.5 instead of Sonnet 5.5: 79% less per solved task (95% CI 74–84%).
- On six tasks from a real production repo: Haiku solved 6/6 for $1.50, with 96% of input read from the prompt cache. Sonnet solved 4/5 for $1.19.
- Codex on Haiku with Anthropic's prompt cache turned on by the gateway: 30% less in all, 68% less on input.
What it does not show: a quality ranking of models (a handful of tasks each), or your bill (costs are the ledger at list prices). Total spend for all of it was about $17.
The gateway is Pygg, open source (MIT): https://github.com/nambean/Pygg. Claude Code keeps your Claude sign-in; pygg run claude starts it through the gateway for one launch, no file changes.
Reports: https://github.com/nambean/Pygg/blob/main/docs/BENCHMARKS.md
Feedback on the journal and settlement design is very welcome.

All rights reserved