Local spend cap for AI agents

A hard spend cap for AI coding agents.

AgentCap runs Gemini CLI, Codex / OpenAI-based agents and your own scripts behind a local proxy on 127.0.0.1 and stops the run when the next request would cross your USD budget.

No account. No server. Nothing leaves your machine except your own API calls (and, for Pro, a license check about once a week).

A loop can spend while you are away

A looping agent or a long unattended run can burn money on API keys while you are not watching. Provider budget alerts are delayed and usually do not stop anything — by the time the email arrives, the spend has already happened.

How it works

  1. Wrap the command

    agentcap run --cap 0.50 -- gemini
    agentcap run --cap 0.50 -- codex
    agentcap run --cap 0.50 -- python my_agent.py
  2. Requests go through the proxy

    AgentCap sets OPENAI_BASE_URL and GOOGLE_GEMINI_BASE_URL so requests go through the local proxy. Before each request it reserves the worst-case cost and lowers the output limit to what is left.

  3. The cap stops the run

    At the cap it blocks the request and terminates the agent (SIGTERM, then SIGKILL after 5 s). The run exits with code 3 — or 4 for a detected loop in Pro.

Install

pipx install agentcap

(PyPI release coming soon — until then: install from source)

Then put a cap on a run:

agentcap run --cap 0.50 -- gemini

Free vs Pro

Free

$0

  • Per-run cap
  • Terminal alerts
  • Local only
Install free

Pro

$19 one-time

  • Hourly / daily caps
  • Loop detection
  • Webhook + Telegram alerts
  • License for your machines
Buy Pro — $19

Payments handled by Polar (merchant of record). Not a subscription.

FAQ

Does it see my prompts or keys?

No. Nothing about prompts, responses or keys is stored. Only token counts, costs, model names, timestamps and request hashes are recorded.

Is it a mathematical guarantee?

No. The cap is enforced before each request with a conservative reservation. If a provider bills more input tokens than estimated, final spend can exceed the cap by at most one request's estimation error, and you get an overshoot alert.

Does it work with subscription/OAuth logins?

No. Only API-key traffic through OPENAI_BASE_URL / GOOGLE_GEMINI_BASE_URL is metered.

Which providers does it support?

OpenAI-compatible and Gemini APIs. Prices come from a local table you can override.

Is Pro a subscription?

No, it is a one-time $19 purchase.

Refunds?

Contact kutaykarahan6@gmail.com.

Does it need an account or a server?

No, it runs locally on your machine.