Early access · OpenAI Chat Completions
A hard dollar cap for every agent run.
Capstop is a local proxy between your agent and OpenAI. When a run reaches its cap, the next call gets an HTTP 402 your code can catch, and a streaming reply is cut off. Your API key goes only to OpenAI. It's never stored or logged.
View on GitHub (opens in a new tab) ↗ · source under Apache-2.0
Try it: press CALL five times (Space or Enter works when it's focused).
Each call costs $0.00045 in this demo. Cap: $0.002.
Demo numbers are computed from the built-in fake OpenAI server's defaults (1,000 prompt + 500 completion tokens at gpt-4o-mini prices), not a recording.
Show the full log
$ capstop fake --port 9999 &
$ capstop serve --upstream http://127.0.0.1:9999
INFO listening on 127.0.0.1:8787 -> http://127.0.0.1:9999
$ python agent.py
run nightly-42 · cap $0.002
step 1 → 200 OK proxy │ settled cost_usd=0.00045 over_cap=False
step 2 → 200 OK proxy │ settled cost_usd=0.00045 over_cap=False
step 3 → 200 OK proxy │ settled cost_usd=0.00045 over_cap=False
step 4 → 200 OK proxy │ settled cost_usd=0.00045 over_cap=False
step 5 → 402 Payment Required
proxy │ refused (worst-case estimate would cross the cap)
{"error": {"type": "run_budget_exceeded",
"run_id": "nightly-42",
"spent_usd": 0.0018,
"cap_usd": 0.002}}
agent: budget hit, stopping cleanly.
$ capstop runs nightly-42
{"run_id": "nightly-42", "spent_usd": 0.0018, "cap_usd": 0.002,
"calls": 4, "over_cap": false}
Call 5 is refused before it reaches OpenAI because it could cross the cap, so over_cap stays false. All figures here are demo figures from the fake server.
The gap
Spend limits are monthly. Loops are not.
Provider spend limits are monthly, not per run. OpenAI's own docs say enforcement “is not instantaneous”. A looping agent can keep spending in that window.
How it works
Three parts. Nothing hosted.
- 01
Run it locally
capstop servestarts a proxy on127.0.0.1:8787. Spend is kept in a local SQLite file. Install steps are below.127.0.0.1:8787 - 02
Tag each run
Send
X-Run-Id(required) andX-Run-Cap-USD(default $1.00) with your OpenAI client.X-RUN-ID: NIGHTLY-42 - 03
It stops at the cap
Every call is priced from OpenAI's reported usage. If the next call could cross the cap, it gets a 402
run_budget_exceededand never reaches OpenAI. A stream that would cross it is cut off.HTTP 402
Run it locally
Needs Linux, bash and Python 3.11+ with venv. It's not on PyPI yet, so install from the GitHub source (opens in a new tab). ./run.sh creates a .venv and installs the pinned, hash-checked dependencies.
git clone https://github.com/abhirampatel/capstop
cd capstop
# only set up the environment
./run.sh setup
# no-key demo: fake OpenAI on :9999, proxy on :8787
./run.sh fake
# real use: forwards to https://api.openai.com
./run.sh
client = OpenAI(
base_url="http://127.0.0.1:8787/v1",
default_headers={"X-Run-Id": "nightly-42", "X-Run-Cap-USD": "2.00"},
)
Point base_url at the proxy and tag the run. No other code changes. Unknown models are refused, not guessed. Check any run with capstop runs <id> or GET /runs/<id>.
Who it's for
For runs you don't babysit.
For
Solo builders and small teams running agent loops and tool calls on paid OpenAI APIs. Anyone who'd rather an agent fail fast than run all night.
Not for (yet)
Anthropic, Gemini, embeddings, images, audio or the Responses API. Team or monthly budgets, alerts, dashboards. Hosted or managed setups.
That's you?
Join anyway and tell us. It decides what comes next.
Early access
What exists today.
Works now
Tested locally on Linux against a fake OpenAI server.
- Per-run caps with 402 refusal
- Streaming cut-off
- Key passes through, never stored or logged
- Spend ledger in local SQLite, survives restarts
- CLI
capstop runs
Not yet
Listed so you know what you're signing up for.
- A PyPI package (install from the GitHub source for now)
- Other providers
- Checked against a real OpenAI invoice (prices from OpenAI's pricing page, 29 Oct 2026; accuracy vs a real bill unverified)
- Tested on Linux only; macOS and Windows untested.
Waitlist
Get early access
We'll email you when there's a build to try. No spam, no sales calls.
Pricing isn't decided. We'll ask the waitlist before charging anyone.
The form is hosted by Tally. We only collect your email to tell you when Capstop is ready, plus your answer to one optional question about agent costs if you choose to give it.
FAQ
Questions.
Does my API key go through your servers?
No. Capstop runs on your machine; the key passes straight to OpenAI and is never stored or logged.
How do I contact you?
Through the waitlist form (opens Tally form in a new tab). It is the only contact path for now.
Which providers?
OpenAI Chat Completions, streaming and non-streaming. Others only if people ask.
What does my agent see at the cap?
HTTP 402 with {"error":{"type":"run_budget_exceeded","run_id","spent_usd","cap_usd"}}.
Can a run go slightly over?
Yes, a little. A call already in flight is still returned (you've been billed for it), and a cut stream can pass the cap by about one chunk. After that, every call on the run is refused.
Why did it refuse a call that would have fit?
The check assumes the worst case (your max_tokens, or 4,096 by default). Set max_tokens to get closer to the cap.
Which operating systems?
Tested on Linux only; macOS and Windows untested.
What will it cost?
Pricing isn't decided. We'll ask the waitlist before charging anyone.
Can I see the source?
Yes. The source is public on GitHub (opens in a new tab) under the Apache-2.0 licence (opens in a new tab). It isn't on PyPI yet.