Monitor what your AI coding agents are spending. In real-time.
A lightweight local proxy that sits between your AI tools and the API providers, logging every token and dollar. Comes with a terminal dashboard (TUI) and a web dashboard — both update live as requests flow through.
Works with Claude Code, Cursor, Copilot, Continue, Aider, OpenAI API, Anthropic API, Google AI, DeepSeek — anything that calls an LLM API over HTTP.
╔══════════════════════════════════════════════════════════════════════════╗
║ agentcost — AI Agent Spend Monitor ║
║ ║
║ Today: $3.4721 (142 reqs, 847.2K tokens) | All Time: $28.91 (1,204) ║
╠══════════════════════════════════════════════════════════════════════════╣
║ Today's Spend by Hour ($) ║ By Provider ║
║ ▆ ║ ╭──────────╮ ║
║ █ ▃ ║ │ ████░░░░ │ Anthropic 72% ║
║ █ █ ▅ ║ │ ██░░░░░░ │ OpenAI 21% ║
║ █ █ █ ▂ ▁ ║ │ █░░░░░░░ │ Google 7% ║
║ █ █ █ █ █ ▁ · · · · · · ║ ╰──────────╯ ║
║ 09 10 11 12 13 14 ║ ║
╠═══════════════════════════════════╬════════════════════════════════════╣
║ Top Models Today ║ Live Request Log ║
║ ───────────────────────────── ║ claude-sonnet-4 | 12.4K | $0.05 ║
║ claude-sonnet-4 89 $2.41 ║ gpt-4o-mini | 1.2K | $0.00 ║
║ gpt-4o 31 $0.82 ║ claude-sonnet-4 | 8.7K | $0.03 ║
║ gemini-2.5-flash 18 $0.11 ║ gpt-4o | 4.1K | $0.02 ║
║ claude-3-5-haiku 4 $0.09 ║ claude-sonnet-4 | 15.2K | $0.07 ║
╠═══════════════════════════════════╩════════════════════════════════════╣
║ Last 30 Days ($) ║
║ ▁▂▃▂▄▅▆▅▃▅▆▇▆▅▆█▇▆▅▇▆▇█▇▆▅▆▇█ ║
╚════════════════════════════════════════════════════════════════════════╝
AI coding agents are brilliant but expensive. They make hundreds of API calls per session, and it's nearly impossible to know how much you're spending in real-time. Your provider dashboard updates with a delay, and doesn't break down by session, tool, or project.
agentcost gives you:
- Real-time cost tracking as requests happen
- Per-model, per-provider, per-session breakdowns
- Budget alerts ("you've burned $10 today")
- Historical trends (daily/hourly)
- Zero config — works as a drop-in proxy
- Transparent proxy — intercepts and forwards API calls, logs usage
- Multi-provider — OpenAI, Anthropic, Google AI, DeepSeek, any OpenAI-compatible API
- Terminal dashboard — blessed-contrib TUI with charts, tables, live log
- Web dashboard — browser UI with WebSocket real-time updates
- Accurate pricing — built-in price table for all major models (June 2026)
- Budget alerts — set a daily budget, get warned when you exceed it
- Session tracking — group costs by session/conversation
- SQLite storage — lightweight, no external database needed
- Offline history — query past usage anytime
- Zero dependencies on external services — everything runs locally
# Install
npx agentcost
# Or clone and run
git clone https://github.com/betty02/agentcost.git
cd agentcost
npm install
npm startThis starts:
- Proxy on
http://localhost:4000 - Web dashboard on
http://localhost:4001 - Terminal dashboard in your current terminal
Point your AI tool at the proxy instead of the real API:
export ANTHROPIC_BASE_URL=http://localhost:4000/anthropic
# Then use Claude Code normallyexport OPENAI_BASE_URL=http://localhost:4000/v1
# Or in your code:
# client = OpenAI(base_url="http://localhost:4000/v1")In Cursor settings → Models → OpenAI API Base URL:
http://localhost:4000/v1
aider --openai-api-base http://localhost:4000/v1In .continue/config.json:
{
"models": [{
"apiBase": "http://localhost:4000/v1",
"provider": "openai",
"model": "gpt-4o"
}]
}export GOOGLE_AI_BASE_URL=http://localhost:4000/googleJust change the base URL to http://localhost:4000/v1. The proxy auto-detects the provider from the request path and headers.
Open http://localhost:4001 in your browser for a live dashboard showing:
- Today's spend with request count and token usage
- Hourly bar chart — see when your agents are most active
- Model breakdown — which models are costing you most
- 30-day trend — daily spend over time
- Live request log — every API call as it happens
The dashboard updates in real-time via WebSocket — no polling, no refresh needed.
If you prefer staying in the terminal, the built-in TUI shows the same data:
# Run TUI only (if proxy is already running separately)
npx agentcost --tui-only
# Run everything together
npx agentcostPress q to quit the TUI.
Config is stored at ~/.agentcost/config.json. Created automatically on first run.
{
"proxyPort": 4000,
"webPort": 4001,
"dailyBudget": 10.00,
"alertThreshold": 5.00,
"pricing": {
"gpt-4o": { "input": 2.50, "output": 10.00 },
"claude-sonnet-4-20250514": { "input": 3.00, "output": 15.00 }
}
}| Key | Default | Description |
|---|---|---|
proxyPort |
4000 | Port for the proxy server |
webPort |
4001 | Port for the web dashboard |
dailyBudget |
null | Daily budget in USD (null = no limit) |
alertThreshold |
5.00 | Warn in TUI when daily spend exceeds this |
pricing |
(built-in) | Override pricing per 1M tokens for any model |
If a new model comes out or prices change, add it to config:
{
"pricing": {
"my-custom-model": { "input": 1.00, "output": 5.00 }
}
}Prices are per 1 million tokens.
Usage: agentcost [options]
Options:
--proxy-only Run only the proxy server
--tui-only Run only the terminal dashboard
--web-only Run only the web dashboard
--all Run proxy + TUI + web (default)
-p, --port <port> Proxy port (default: 4000)
-w, --web-port Web dashboard port (default: 4001)
--no-tui Run proxy + web without TUI
-V, --version Output version number
-h, --help Display help
┌─────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ Your AI │────▶│ agentcost │────▶│ OpenAI / │
│ Tool │◀────│ proxy (:4000) │◀────│ Anthropic / │
│ (Cursor, │ │ │ │ Google API │
│ Claude, │ │ ┌────────────┐ │ └──────────────────┘
│ Aider) │ │ │ Log to DB │ │
└─────────────┘ │ └────────────┘ │
│ │ │
└────────┼─────────┘
│
┌────────▼─────────┐
│ SQLite DB │
│ (~/.agentcost/ │
│ usage.db) │
└────────┬─────────┘
│
┌──────────────┼──────────────┐
│ │ │
┌────────▼───┐ ┌──────▼─────┐ ┌────▼──────┐
│ TUI │ │ Web │ │ JSON API │
│ Dashboard │ │ Dashboard │ │ /api/* │
│ (terminal)│ │ (:4001) │ │ │
└────────────┘ └────────────┘ └───────────┘
- You point your AI tool's base URL at the agentcost proxy
- The proxy forwards requests to the real API transparently
- When the response comes back, it extracts token usage from the response body
- It calculates cost using the built-in pricing table
- Logs everything to a local SQLite database
- The TUI and web dashboards query the DB and show real-time stats
Your API keys stay on your machine. The proxy just passes headers through — it doesn't store or inspect your API key.
The web server exposes a JSON API you can query programmatically:
| Endpoint | Description |
|---|---|
GET /api/stats |
All-time totals |
GET /api/today |
Today's spend, tokens, request count |
GET /api/hourly |
Hourly breakdown for today |
GET /api/models |
Top models by cost today |
GET /api/providers |
Cost by provider today |
GET /api/recent?limit=50 |
Recent requests |
GET /api/daily?days=30 |
Daily totals over N days |
GET /api/sessions |
Session summaries |
| Provider | Models |
|---|---|
| OpenAI | gpt-4o, gpt-4o-mini, o1, o1-mini, o3, o3-mini, gpt-4-turbo, gpt-3.5-turbo |
| Anthropic | claude-opus-4, claude-sonnet-4, claude-3.5-sonnet, claude-3.5-haiku, claude-3-opus, claude-3-haiku |
| gemini-2.5-pro, gemini-2.5-flash, gemini-2.0-flash, gemini-1.5-pro | |
| DeepSeek | deepseek-chat, deepseek-coder |
Unknown models default to a mid-range estimate. Add custom pricing in config for accuracy.
All data is stored locally in ~/.agentcost/usage.db (SQLite). No data leaves your machine.
# View raw data
sqlite3 ~/.agentcost/usage.db "SELECT * FROM requests ORDER BY id DESC LIMIT 10"
# Export to CSV
sqlite3 -header -csv ~/.agentcost/usage.db "SELECT * FROM requests" > export.csv
# Reset all data
rm ~/.agentcost/usage.db| Problem | Solution |
|---|---|
| Tool ignores base URL | Some tools only respect env vars on fresh start — restart the tool |
| SSL/TLS errors | The proxy speaks HTTP. Tools expecting HTTPS need HTTPS=false or similar |
| Port in use | Change port: agentcost -p 5000 -w 5001 |
| No usage in response | Some streaming responses don't include usage — we log the request but cost shows $0 |
| Wrong cost shown | Update pricing in ~/.agentcost/config.json |
| TUI looks broken | Ensure terminal is at least 120×30 chars. Try --no-tui and use web dashboard |
PRs welcome! Ideas:
- Docker container version
- Grafana/Prometheus export
- Per-project tracking (based on working directory)
- Cost predictions ("at this rate you'll spend $X this month")
- Slack/Discord webhook alerts
- Browser extension for web-based AI tools
- Support for streaming response token counting
- Multi-user support with separate API keys
MIT