API · v0.10.0
HTTP API reference
Put coding-agent subscription usage into your own apps, scripts and status bars. Every endpoint, the canonical response schema field by field, one-shot JSON, and copy-paste integrations.
Overview
While Agent Tank runs it serves a JSON API next to the dashboard at:
http://127.0.0.1:3456
- Local only by default. It listens on
127.0.0.1(plus the Docker bridge when available) on port 3456. Change both with --port and --host; see Server and network. - JSON responses. Every endpoint except
/returns JSON; errors are JSON too, such as{ "error": "Not found" }for an unknown route. - CORS enabled. Every response carries
Access-Control-Allow-Origin: *andAccess-Control-Allow-Methods: GET, POST, OPTIONS, so a browser app on another local port can call it (see Browser fetch). - Every provider, one shape. Claude, Codex and Antigravity all return the same canonical provider object, with the original payload kept under
raw.
Authentication
Authentication is off by default: anyone who can reach the port can read the API. Turn it on with --auth-user and --auth-pass for HTTP Basic auth, or --auth-token for a Bearer token (also AGENT_TANK_USER, AGENT_TANK_PASS and AGENT_TANK_TOKEN; see Authentication options). With both set, either one is accepted.
agent-tank runs in the foreground, so start it in one terminal and send requests from a second one. A VAR=value agent-tank prefix sets the variable for the server process only, so the client terminal exports the same token itself:
# Basic auth, terminal 1: the server
agent-tank --auth-user me --auth-pass change-me
# Basic auth, terminal 2: a client
curl -s -u me:change-me http://127.0.0.1:3456/status
# Bearer token, terminal 1: the server
AGENT_TANK_TOKEN=change-me agent-tank
# Bearer token, terminal 2: a client
export AGENT_TANK_TOKEN=change-me
curl -s -H "Authorization: Bearer $AGENT_TANK_TOKEN" http://127.0.0.1:3456/status
When a token is set, it is also accepted as a token query parameter, which is the only option for a browser page (see Browser fetch). Query strings end up in logs and history, so prefer the header elsewhere. From the client terminal above, where AGENT_TANK_TOKEN is exported:
curl -s "http://127.0.0.1:3456/status?token=$AGENT_TANK_TOKEN"
A request without valid credentials gets 401 with a WWW-Authenticate: Basic header and this body:
{"error":"Unauthorized"}
Endpoints
All paths are relative to http://127.0.0.1:3456. :id is a configured account id: the provider name, or the alias of a multi-account entry such as work.
| Method | Path | Description | Returns |
|---|---|---|---|
| GET | / |
HTML status page | HTML dashboard |
| GET | /status |
Canonical usage for all agents | { "providers": [...] } |
| GET | /status/:id |
Canonical usage for one configured account | One canonical provider object (404 when the id is unknown) |
| GET | /config |
Auto-refresh and history config | Config object; history is reported as history: { enabled, store, path, retentionDays, chart } |
| GET | /history |
History summary, including the backend (store: sqlite or none) | Per-account row counts plus store and path |
| GET | /history/:id |
Metric series for one configured account | { "agent", "store", "retention_days", "series": [...] } |
| POST | /refresh |
Refresh all agents | { "success": true, "providers": [...] } |
| POST | /refresh/:id |
Refresh one configured account | { "success": true, "provider": {...} } |
GET/status
Canonical usage for all agents.
Every configured account as one canonical provider object, in a providers list. This is the same JSON that agent-tank --once --json prints. Each object is described field by field under Response schema.
Parameters
No parameters.
Example
curl -s http://127.0.0.1:3456/status
{
"providers": [
{
"id": "claude",
"provider": "claude",
"plan": "max",
"status": "ok",
"last_updated": "2026-10-17T12:00:00.000Z",
"error": null,
"windows": [
{
"type": "session",
"label": "Current session",
"model": null,
"used_percent": 25,
"remaining_percent": 75,
"resets_at": "2026-10-17T14:00:00.000Z",
"resets_in_seconds": 7200,
"pace": {
"ratio": 0.42,
"burning_fast": false
}
},
{
"type": "weekly",
"label": "Current week (all models)",
"model": null,
"used_percent": 28,
"remaining_percent": 72,
"resets_at": "2026-10-22T09:00:00.000Z",
"resets_in_seconds": 421200,
"pace": {
"ratio": 0.92,
"burning_fast": false
}
},
{
"type": "weekly",
"label": "Current week (Fable)",
"model": "Fable",
"used_percent": 15,
"remaining_percent": 85,
"resets_at": "2026-10-22T09:00:00.000Z",
"resets_in_seconds": 421200,
"pace": {
"ratio": 0.49,
"burning_fast": false
}
}
],
"context_window": {
"total_tokens": 1000000,
"used_tokens": null,
"used_percent": null,
"remaining_percent": null,
"model": "claude-opus-5-5",
"source": "known-model"
},
"credits": null,
"raw": {
"…": "original per-provider payload"
}
},
{
"id": "work",
"provider": "codex",
"plan": "pro",
"status": "ok",
"last_updated": "2026-10-17T12:00:00.000Z",
"error": null,
"windows": [
{
"type": "five_hour",
"label": "5h limit",
"model": null,
"used_percent": 11,
"remaining_percent": 89,
"resets_at": "2026-10-17T15:00:00.000Z",
"resets_in_seconds": 10800,
"pace": {
"ratio": 0.28,
"burning_fast": false
}
},
{
"type": "weekly",
"label": "Weekly limit",
"model": null,
"used_percent": 39,
"remaining_percent": 61,
"resets_at": "2026-10-20T07:00:00.000Z",
"resets_in_seconds": 241200,
"pace": {
"ratio": 0.65,
"burning_fast": false
}
},
{
"type": "five_hour",
"label": "GPT-5.3-Codex-Spark 5h limit",
"model": "GPT-5.3-Codex-Spark",
"used_percent": 6,
"remaining_percent": 94,
"resets_at": "2026-10-17T13:00:00.000Z",
"resets_in_seconds": 3600,
"pace": {
"ratio": 0.08,
"burning_fast": false
}
},
{
"type": "weekly",
"label": "GPT-5.3-Codex-Spark Weekly limit",
"model": "GPT-5.3-Codex-Spark",
"used_percent": 23,
"remaining_percent": 77,
"resets_at": "2026-10-20T07:00:00.000Z",
"resets_in_seconds": 241200,
"pace": {
"ratio": 0.38,
"burning_fast": false
}
}
],
"context_window": {
"total_tokens": 258000,
"used_tokens": 14240,
"used_percent": 5.52,
"remaining_percent": 94.48,
"model": "gpt-5.3-codex",
"source": "cli"
},
"credits": {
"remaining": 48405,
"unit": "credits"
},
"raw": {
"…": "original per-provider payload"
}
},
{
"id": "personal",
"provider": "codex",
"plan": "plus",
"status": "ok",
"last_updated": "2026-10-17T12:00:00.000Z",
"error": null,
"windows": [
{
"type": "five_hour",
"label": "5h limit",
"model": null,
"used_percent": 11,
"remaining_percent": 89,
"resets_at": "2026-10-17T16:00:00.000Z",
"resets_in_seconds": 14400,
"pace": {
"ratio": 0.55,
"burning_fast": false
}
},
{
"type": "weekly",
"label": "Weekly limit",
"model": null,
"used_percent": 12,
"remaining_percent": 88,
"resets_at": "2026-10-23T19:00:00.000Z",
"resets_in_seconds": 543600,
"pace": {
"ratio": 1.19,
"burning_fast": false
}
}
],
"context_window": {
"total_tokens": 272000,
"used_tokens": null,
"used_percent": null,
"remaining_percent": null,
"model": "gpt-5.3-codex",
"source": "known-model"
},
"credits": {
"remaining": 1250,
"unit": "credits"
},
"raw": {
"…": "original per-provider payload"
}
},
{
"id": "agy",
"provider": "antigravity",
"plan": "google ai pro",
"status": "ok",
"last_updated": "2026-10-17T12:00:00.000Z",
"error": null,
"windows": [
{
"type": "five_hour",
"label": "Gemini · Five Hour Limit Remaining",
"model": "Gemini",
"used_percent": 12.63,
"remaining_percent": 87.37,
"resets_at": "2026-10-17T13:00:00.000Z",
"resets_in_seconds": 3600,
"pace": {
"ratio": 0.16,
"burning_fast": false
}
},
{
"type": "weekly",
"label": "Gemini · Weekly Limit Remaining",
"model": "Gemini",
"used_percent": 40.76,
"remaining_percent": 59.24,
"resets_at": "2026-10-19T16:00:00.000Z",
"resets_in_seconds": 187200,
"pace": {
"ratio": 0.59,
"burning_fast": false
}
},
{
"type": "five_hour",
"label": "Claude and GPT · Five Hour Limit Remaining",
"model": "Claude and GPT",
"used_percent": 0,
"remaining_percent": 100,
"resets_at": null,
"resets_in_seconds": null,
"pace": null
},
{
"type": "weekly",
"label": "Claude and GPT · Weekly Limit Remaining",
"model": "Claude and GPT",
"used_percent": 16.58,
"remaining_percent": 83.42,
"resets_at": "2026-10-19T16:00:00.000Z",
"resets_in_seconds": 187200,
"pace": {
"ratio": 0.24,
"burning_fast": false
}
},
{
"type": "weekly",
"label": "Gemini 4 Argon Weekly Limit",
"model": "Gemini 4 Argon",
"used_percent": 15.03,
"remaining_percent": 84.97,
"resets_at": "2026-10-21T00:00:00.000Z",
"resets_in_seconds": 302400,
"pace": {
"ratio": 0.3,
"burning_fast": false
}
}
],
"context_window": {
"total_tokens": 1048576,
"used_tokens": null,
"used_percent": null,
"remaining_percent": null,
"model": "Gemini 3.1 Pro",
"source": "known-model"
},
"credits": null,
"raw": {
"…": "original per-provider payload"
}
}
]
}
GET/status/:id
Canonical usage for one configured account.
One configured account, the same object as its entry in GET /status.
Parameters
| Parameter | In | Description |
|---|---|---|
id | path | Configured account id: the provider name (claude, codex, agy) or the alias of a multi-account entry. |
Example
curl -s http://127.0.0.1:3456/status/claude
{
"id": "claude",
"provider": "claude",
"plan": "max",
"status": "ok",
"last_updated": "2026-10-17T12:00:00.000Z",
"error": null,
"windows": [
{
"type": "session",
"label": "Current session",
"model": null,
"used_percent": 25,
"remaining_percent": 75,
"resets_at": "2026-10-17T14:00:00.000Z",
"resets_in_seconds": 7200,
"pace": {
"ratio": 0.42,
"burning_fast": false
}
},
{
"type": "weekly",
"label": "Current week (all models)",
"model": null,
"used_percent": 28,
"remaining_percent": 72,
"resets_at": "2026-10-22T09:00:00.000Z",
"resets_in_seconds": 421200,
"pace": {
"ratio": 0.92,
"burning_fast": false
}
},
{
"type": "weekly",
"label": "Current week (Fable)",
"model": "Fable",
"used_percent": 15,
"remaining_percent": 85,
"resets_at": "2026-10-22T09:00:00.000Z",
"resets_in_seconds": 421200,
"pace": {
"ratio": 0.49,
"burning_fast": false
}
}
],
"context_window": {
"total_tokens": 1000000,
"used_tokens": null,
"used_percent": null,
"remaining_percent": null,
"model": "claude-opus-5-5",
"source": "known-model"
},
"credits": null,
"raw": {
"…": "original per-provider payload"
}
}
404: the id is not configured.
{"error":"Agent not found"}
GET/config
Auto-refresh and history config.
Effective auto-refresh and history settings, and when the last full refresh finished. autoRefresh.interval and refreshCooldown are in seconds. history.chart is false whenever history is off. All of them are set on the Configuration page.
Parameters
No parameters.
Example
curl -s http://127.0.0.1:3456/config
{
"autoRefresh": {
"enabled": true,
"interval": 60,
"refreshCooldown": 30
},
"history": {
"enabled": true,
"store": "sqlite",
"path": "/home/you/.agent-tank/history.db",
"retentionDays": 14,
"chart": true
},
"lastRefreshedAt": "2026-10-17T12:00:00.000Z"
}
GET/history
History summary, including the backend (store: sqlite or none).
A summary of the history database: the backend in store ("sqlite", or "none" when history is disabled or node:sqlite is unavailable), its path, and row counts per configured account.
Parameters
No parameters.
Example
curl -s http://127.0.0.1:3456/history
{
"store": "sqlite",
"enabled": true,
"path": "/home/you/.agent-tank/history.db",
"retentionDays": 14,
"totalRows": 2465,
"agents": {
"claude": {
"provider": "claude",
"rows": 435,
"snapshots": 145,
"metrics": 3,
"oldest": "2026-10-11T12:00:00.000Z",
"newest": "2026-10-17T12:00:00.000Z"
},
"…": "one entry per configured account"
}
}
GET/history/:id
Metric series for one configured account.
The recorded metric series for one account, one series per metric. percent is always percent used. series is [] for an account with no recorded metrics. Without view=chart each point is { "t", "percent", "value" } and every series has a unit.
Parameters
| Parameter | In | Description |
|---|---|---|
id | path | Configured account id. |
since | query | Only points at or after this time (ISO 8601 or epoch ms). |
until | query | Only points at or before this time (ISO 8601 or epoch ms). |
metric | query | Only the series with this metric_key. |
view | query | view=chart returns only plottable series (percent units with at least two points), each point reduced to { "t", "percent" }. |
Example
curl -s "http://127.0.0.1:3456/history/claude?view=chart"
# One metric since a point in time
curl -s "http://127.0.0.1:3456/history/work?metric=weekly&since=2026-10-16T00:00:00Z"
{
"agent": "claude",
"store": "sqlite",
"retention_days": 14,
"series": [
{
"key": "session",
"label": "Current session",
"model": null,
"cycle": "session",
"points": [
{
"t": "2026-10-17T10:00:00.000Z",
"percent": 10
},
{
"t": "2026-10-17T11:00:00.000Z",
"percent": 19
},
{
"t": "2026-10-17T12:00:00.000Z",
"percent": 25
}
]
},
{
"key": "weeklyAll",
"label": "Current week (all models)",
"model": null,
"cycle": "weekly",
"points": [
{
"t": "2026-10-17T10:00:00.000Z",
"percent": 27
},
{
"t": "2026-10-17T11:00:00.000Z",
"percent": 27
},
{
"t": "2026-10-17T12:00:00.000Z",
"percent": 28
}
]
},
{
"key": "weeklyFable",
"label": "Current week (Fable)",
"model": "Fable",
"cycle": "weekly",
"points": [
{
"t": "2026-10-17T10:00:00.000Z",
"percent": 14
},
{
"t": "2026-10-17T11:00:00.000Z",
"percent": 14
},
{
"t": "2026-10-17T12:00:00.000Z",
"percent": 15
}
]
}
]
}
POST/refresh
Refresh all agents.
Refreshes every configured account, waits for all of them and returns the same providers list as GET /status, with "success": true.
Each account has a refresh cooldown (--refresh-cooldown, default 30 seconds): an account refreshed less than that long ago is skipped and keeps its cached usage, and a refresh already running is reused rather than started again. Check last_updated to see whether the usage is new.
Parameters
No parameters.
Example
curl -s -X POST http://127.0.0.1:3456/refresh
{
"success": true,
"providers": [
{
"…": "same provider objects as GET /status"
}
]
}
POST/refresh/:id
Refresh one configured account.
Refreshes one account (subject to the same cooldown) and returns its provider object, the same as GET /status/:id.
Parameters
| Parameter | In | Description |
|---|---|---|
id | path | Configured account id. |
Example
curl -s -X POST http://127.0.0.1:3456/refresh/claude
{
"success": true,
"provider": {
"id": "claude",
"provider": "claude",
"…": "same object as GET /status/claude"
}
}
404: the id is not configured.
{"error":"Agent not found: nope"}
Response schema
Every provider returns the same canonical shape, described below object by object.
Rules
- Percentages are rounded to two decimals and clamped to 0–100.
remaining_percentis always100 − used_percent, so the two add up to 100.modeltells apart windows that share atype: Claude reports a weekly window for all models (model: null) and a weekly Fable window (model: "Fable").statusis"refreshing"while a refresh runs and"error"when the last one failed, even ifwindowsstill holds cached usage; checklast_updatedfor its age.- All resets are ISO 8601 in
resets_at. An Antigravity limit reporting "Quota available" hasresets_at: nullandresets_in_seconds: null. paceisnullwhen there is no pace signal.rawis the untouched per-agent payload (the 0.9.x shape), kept for anything the canonical fields do not cover.
Window types
type | Window |
|---|---|
session | Session limit |
five_hour | Five-hour limit |
weekly | Weekly limit, for all models or for one model (group) |
Provider object
One per configured account: each entry of providers in GET /status, and the body of GET /status/:id.
| Field | Type | Description |
|---|---|---|
id | string | Configured account id (the alias for multi-account setups); the key used by /status/:id, /history/:id and /refresh/:id. |
provider | string | Provider family: "claude", "codex" or "antigravity". |
plan | string | null | Plan the CLI reports, lowercased: the Codex plan type ("plus"), Claude's /status login method ("max"), or the plan next to the account in Antigravity's startup banner ("google ai pro"). If Claude doesn't report a plan, it falls back to "max" when a weekly Fable window is present, and null otherwise. |
status | "ok" | "error" | "refreshing" | "pending" | "refreshing" while a refresh is running and "error" when the last refresh failed, even if windows still holds cached usage. "pending" before the first refresh and "ok" otherwise. |
last_updated | string | null | When the usage in windows was captured (ISO 8601). A refresh that fails but keeps the cached usage does not move it. |
error | string | null | Last refresh error message, if any. |
windows | Window[] | Usage limits, one entry per limit window. |
context_window | ContextWindow | null | Best-effort model context window, or null when unknown. |
credits | Credits | null | Codex credit balance; null for other providers or when Codex doesn't report one. |
raw | object | The untouched per-agent payload (the 0.9.x shape). |
Window
Each entry of windows.
| Field | Type | Description |
|---|---|---|
type | "session" | "five_hour" | "weekly" | Window type. |
label | string | Human-readable label, such as "Current week (all models)". |
model | string | null | The model (or model group) the window is specific to, such as "Fable" or "GPT-5.3-Codex-Spark"; null for windows covering all models. Use it to tell apart windows that share a type. Antigravity's grouped limits use the group name. |
used_percent | number | Percent used, rounded to two decimals and clamped to 0–100. |
remaining_percent | number | Always 100 - used_percent, so the two add up to 100. Antigravity's reported remaining percentage is kept as-is and used_percent is derived from it. |
resets_at | string | null | Reset time in ISO 8601; null when unknown, such as an Antigravity limit reporting "Quota available". |
resets_in_seconds | number | null | Whole seconds until reset; null when unknown. |
pace | Pace | null | Pace signal for the window; null when there is no pace signal. |
Pace
A window's pace, or null.
| Field | Type | Description |
|---|---|---|
ratio | number | Usage rate vs elapsed-time rate (above 1 means usage is out-pacing the window). |
burning_fast | boolean | Whether usage is on track to exhaust the window early. |
Context window
context_window, or null when unknown.
| Field | Type | Description |
|---|---|---|
total_tokens | number | Window size in tokens. |
used_tokens | number | null | Tokens in use; only set when source is "cli". |
used_percent | number | null | Only set when source is "cli". |
remaining_percent | number | null | Only set when source is "cli". |
model | string | null | Model the window belongs to. |
source | "cli" | "override" | "known-model" | "cli" when the CLI reported it (Codex /status or its app-server), "override" when it came from the contextWindows config key, or "known-model" when the reported model matched Agent Tank's built-in table. |
Credits
credits, or null.
| Field | Type | Description |
|---|---|---|
remaining | number | Codex credit balance. It is a balance, not a time window, so it isn't in windows. |
unit | "credits" | Always "credits". Claude's extra usage is a dollar budget, not credits, and stays under raw.usage.extraUsage. |
History response
The body of GET /history/:id.
| Field | Type | Description |
|---|---|---|
agent | string | Configured account id. |
store | "sqlite" | "none" | History backend; "none" when history is disabled or node:sqlite is unavailable (Node.js older than 22.5). |
retention_days | number | Days of history kept (default 14). |
series | Series[] | One series per metric; [] for an account with no recorded metrics. |
History series
Each entry of series.
| Field | Type | Description |
|---|---|---|
key | string | Stable series id (metric_key), e.g. session, weeklyAll, fiveHour, model:Gemini · Weekly Limit, GPT-5.3-Codex-Spark:fiveHour; Codex also records contextUsedPercent and credits. |
label | string | Human-readable label (may change without forking the series). |
model | string | null | Model (group) the limit applies to. |
cycle | string | null | session, five_hour or weekly. |
unit | string | "percent" for percentage rows; "credits" for the Codex credit balance. |
points | { t, percent, value }[] | t is the capture time, percent is always percent used, and value holds non-percentage metrics such as credits. With ?view=chart each point is reduced to { t, percent }. |
One-shot JSON
agent-tank --once --json refreshes every agent once, prints the same { "providers": [...] } body as GET /status and exits. No server is started and nothing listens on a port, so it suits cron jobs, CI steps and scripts that run on demand (see --once and --json).
agent-tank --once --json > usage.json
# Every window of one account
agent-tank --once --json | jq '.providers[] | select(.id == "claude") | .windows'
Integration examples
Complete scripts you can copy as they are. Each reads the API base URL from a TANK_URL environment variable (the scripts’ own, not an Agent Tank setting) and falls back to http://127.0.0.1:3456. If you turned on authentication, add the -u or Authorization option to each request.
tmux status bar
Prints the highest used_percent of each account, such as claude 28% · work 54%. --max-time 2 keeps a stalled request from freezing the status line, and when Agent Tank is not running the script prints tank off instead. Needs curl and jq.
#!/bin/sh
# Highest used_percent per account, e.g. "claude 28% · work 54%".
URL="${TANK_URL:-http://127.0.0.1:3456}"
json=$(curl -sf --max-time 2 "$URL/status") || { echo "tank off"; exit 0; }
printf '%s' "$json" | jq -r '
[.providers[]
| select(.windows | length > 0)
| "\(.id) \([.windows[].used_percent] | max | round)%"]
| join(" · ")'
set -g status-interval 60
set -g status-right '#(~/.local/bin/agent-tank-tmux.sh) | %H:%M'
Make the script executable (chmod +x ~/.local/bin/agent-tank-tmux.sh) and reload tmux with tmux source-file ~/.tmux.conf.
Waybar custom module (Linux)
Emits the JSON object Waybar reads with "return-type": "json": the highest usage as text, every window in the tooltip, and class set to warning above 80% (offline when Agent Tank is not running, and pending with the text n/a before any account has usage).
#!/bin/sh
# Waybar custom module: {"text", "tooltip", "class"}; class "warning" above 80%,
# "pending" with "n/a" while no account has usage yet.
URL="${TANK_URL:-http://127.0.0.1:3456}"
json=$(curl -sf --max-time 2 "$URL/status") || {
echo '{"text":"tank off","tooltip":"Agent Tank is not running","class":"offline"}'
exit 0
}
printf '%s' "$json" | jq -c '
[.providers[].windows[].used_percent] as $all
| if ($all | length) == 0 then
{text: "n/a", tooltip: "No usage yet: waiting for the first refresh", class: "pending"}
else
($all | max) as $top
| {
text: "\($top | round)%",
tooltip: ([.providers[] | .id as $id | .windows[]
| "\($id) · \(.label): \(.used_percent)%"] | join("\n")),
class: (if $top > 80 then "warning" else "normal" end)
}
end'
"modules-right": ["custom/agent-tank", "clock"],
"custom/agent-tank": {
"exec": "~/.config/waybar/agent-tank.sh",
"return-type": "json",
"interval": 60,
"format": "AT {}"
}
#custom-agent-tank.warning { color: #ecc94b; }
#custom-agent-tank.offline,
#custom-agent-tank.pending { opacity: 0.5; }
Make the script executable (chmod +x ~/.config/waybar/agent-tank.sh) and restart Waybar to load the module.
SwiftBar / xbar plugin (macOS)
One line in the menu bar, the highest usage (AT n/a before any account has usage), and a dropdown with one line per window, a link to the dashboard and a refresh item. The 5m in the file name sets the refresh interval. Install jq with brew install jq.
#!/bin/bash
# SwiftBar / xbar plugin, refreshed every 5 minutes (the "5m" in the file name).
export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"
URL="${TANK_URL:-http://127.0.0.1:3456}"
if ! json=$(curl -sf --max-time 2 "$URL/status"); then
echo "AT off"
echo "---"
echo "Agent Tank is not running"
exit 0
fi
printf '%s' "$json" | jq -r --arg url "$URL" '
[.providers[].windows[].used_percent] as $all
| if ($all | length) > 0 then "AT \($all | max | round)%" else "AT n/a" end,
"---",
if ($all | length) == 0 then "No usage yet: waiting for the first refresh" else empty end,
(.providers[] | .id as $id | .windows[]
| "\($id) · \(.label): \(.used_percent)% | font=Menlo size=12"),
"---",
"Open dashboard | href=\($url)/",
"Refresh | refresh=true"'
Save it in your SwiftBar or xbar plugin folder and make it executable with chmod +x agent-tank.5m.sh.
Node.js alert script
Uses the built-in fetch (Node.js 18+) and exits with code 1 when any weekly window is above the threshold, so a CI job or a shell && chain can gate on it. A request that fails (Agent Tank not running) also exits non-zero.
// Exit 1 when any weekly window is above the threshold (default 80%).
// Usage: node check-weekly.mjs [threshold] (Node.js 18+)
const url = process.env.TANK_URL ?? 'http://127.0.0.1:3456';
const threshold = Number(process.argv[2] ?? 80);
const res = await fetch(`${url}/status`, { signal: AbortSignal.timeout(5000) });
if (!res.ok) throw new Error(`GET /status returned ${res.status}`);
const { providers } = await res.json();
const over = providers.flatMap((p) => p.windows
.filter((w) => w.type === 'weekly' && w.used_percent > threshold)
.map((w) => `${p.id} · ${w.label}: ${w.used_percent}%`));
if (over.length > 0) {
console.error(`Weekly usage above ${threshold}%:\n${over.join('\n')}`);
process.exit(1);
}
console.log(`All weekly windows at or below ${threshold}%.`);
node check-weekly.mjs 80
Python alert script
The same check with urllib.request, so it needs nothing beyond the Python standard library.
"""Exit 1 when any weekly window is above the threshold (default 80%).
Usage: python3 check_weekly.py [threshold] (standard library only)
"""
import json
import os
import sys
import urllib.request
url = os.environ.get("TANK_URL", "http://127.0.0.1:3456")
threshold = float(sys.argv[1]) if len(sys.argv) > 1 else 80
with urllib.request.urlopen(f"{url}/status", timeout=5) as res:
providers = json.load(res)["providers"]
over = [
f"{p['id']} · {w['label']}: {w['used_percent']}%"
for p in providers
for w in p["windows"]
if w["type"] == "weekly" and w["used_percent"] > threshold
]
if over:
print(f"Weekly usage above {threshold:g}%:", *over, sep="\n", file=sys.stderr)
sys.exit(1)
print(f"All weekly windows at or below {threshold:g}%.")
python3 check_weekly.py 80
Cron and CI with --once --json
No server needed: --once --json refreshes every agent, prints the GET /status body and exits. jq -e exits 1 when the expression is false, so this line fails when any window is above 90%.
agent-tank --once --json | jq -e '[.providers[].windows[] | select(.used_percent > 90)] | length == 0'
# crontab -e: every 30 minutes, keep the latest snapshot and log when a window is above 90%
*/30 * * * * agent-tank --once --json > ~/.cache/agent-tank.json && jq -e '[.providers[].windows[] | select(.used_percent > 90)] | length == 0' ~/.cache/agent-tank.json > /dev/null || echo "$(date -Is) Agent Tank check failed or a window is above 90 percent" >> ~/.cache/agent-tank-alerts.log
Browser fetch from a local dashboard
Agent Tank answers every request with Access-Control-Allow-Origin: *, so a page served from another local port (or opened as a file) can call it directly.
<!doctype html>
<meta charset="utf-8">
<title>Agent usage</title>
<ul id="usage"><li>Loading…</li></ul>
<script type="module">
const url = 'http://127.0.0.1:3456';
const list = document.querySelector('#usage');
try {
const { providers } = await fetch(`${url}/status`).then((r) => r.json());
list.replaceChildren(...providers.flatMap((p) => p.windows.map((w) => {
const li = document.createElement('li');
li.textContent = `${p.id} · ${w.label}: ${w.used_percent}% used`;
return li;
})));
} catch {
list.textContent = 'Agent Tank is not running.';
}
</script>
With --auth-token set, append ?token=… to the URL instead of sending an Authorization header: Agent Tank does not send Access-Control-Allow-Headers, so the browser’s preflight for a custom header fails.
Programmatic use from Node.js
The agent-tank package also exports the AgentTank class, so a Node.js app can run the monitor in-process. getNormalizedStatus() and getNormalizedAgentStatus(id) return the canonical shape (the same as GET /status and GET /status/:id); getStatus() still returns the raw payloads. Call stop() when done so the history database is closed. The README example below is wrapped in an async function so it runs as a CommonJS script: save it as tank.cjs (or as a .js file in a package without "type": "module") and run node tank.cjs.
const { AgentTank } = require('agent-tank');
async function main() {
const watcher = new AgentTank({
agents: [
{ provider: 'codex', id: 'work', configPath: '/srv/accounts/codex-work' },
{ provider: 'codex', id: 'personal', configPath: '/srv/accounts/codex-personal' },
'agy'
],
port: 3456,
autoDiscover: true
});
await watcher.start();
try {
// Canonical shape shared by every provider (same as GET /status)
const { providers } = watcher.getNormalizedStatus();
for (const { id, provider, windows } of providers) {
for (const w of windows) {
console.log(`${id} (${provider}) ${w.label}: ${w.used_percent}% used, resets ${w.resets_at}`);
}
}
await watcher.refreshAgent('work');
// One configured account (same as GET /status/work), or null if unknown
console.log(watcher.getNormalizedAgentStatus('work'));
// Raw per-provider payloads are still available
console.log(watcher.getStatus());
} finally {
watcher.stop();
}
}
main().catch((err) => {
console.error(err);
process.exitCode = 1;
});
Built something with it? Built on Agent Tank: ProPR shows a production integration.