Skip to content

devlog/token-math/a-terminal-check-for-weekly-caps-and-monthly-budget-70.md

A Terminal Check for Weekly Caps and Monthly Budget

A $20 weekly cap inside a $60 monthly budget

A long coding session can eat through spending headroom before the feature ships. For my flow pass workflow, I track two limits: $20 for the current week and $60 for the calendar month. The weekly cap controls pace; the monthly budget controls total spend. Both must have room before I start another run.

This walkthrough builds a local spending check, not a Fluxo account setting. It uses a ledger you maintain from actual charges. It cannot enforce limits across other terminals, shared keys, or requests already running.

Fluxo gives me one key and one base URL, https://api.fluxorelay.com, for Claude, GPT, Gemini, DeepSeek, Kimi, GLM, Qwen, Grok and more. It works with Claude Code, Codex, Gemini CLI and any OpenAI SDK. Billing follows real tokens, including cache reads and writes, with no monthly fee. My $60 figure is therefore my own budget, not a subscription price.

1. Create a ledger with explicit calendar boundaries

You need Bash, Python 3, curl, and sqlite3. This example uses UTC, with weeks beginning Monday and months beginning on the first. A calendar week can cross a month boundary, so the two totals need separate queries.

Run this once from your terminal: — mkdir -p "$HOME/.local/share/fluxo-budget"

export FLUXO_LEDGER="$HOME/.local/share/fluxo-budget/spend.sqlite3" — sqlite3 "$FLUXO_LEDGER" 'CREATE TABLE IF NOT EXISTS charges (recorded_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, cents INTEGER NOT NULL CHECK(cents >= 0));'

Keep amounts in integer cents. That avoids floating-point surprises when checking the last few cents of headroom. Repeat the export command in each new shell, or put it in your shell configuration.

2. Check both limits before launching a session

This command calculates the current UTC week and month, prints both totals, and returns an error when either limit has been reached:

python3 -c 'import datetime as d, os, sqlite3; now=d.datetime.now(d.timezone.utc); today=now.date(); week=today-d.timedelta(days=today.weekday()); month=today.replace(day=1); db=sqlite3.connect(os.environ["FLUXO_LEDGER"]); total=lambda start: db.execute("SELECT COALESCE(SUM(cents),0) FROM charges WHERE recorded_at >= ?", (str(start),)).fetchone()[0]; w,m=total(week),total(month); print(f"Week: {w}/2000 cents; month: {m}/6000 cents"); raise SystemExit(0 if w<2000 and m<6000 else 1)'

For a reusable check, save that command as check-budget.sh and run bash check-budget.sh before opening your coding agent. To gate another command, use bash check-budget.sh && your-command.

If weekly spending is $19 and monthly spending is $42, only $1 remains under the weekly cap. If weekly spending is $8 and monthly spending is $59, the monthly budget leaves that same $1. Monday resets the weekly calculation; it does not restore monthly headroom.

3. Send a small request after the budget check

For a concrete test, choose Claude Sonnet 5.5 or GPT-6 Astra. Copy its exact API model identifier from Fluxo rather than assuming the display name is the identifier. Enter your credentials and that identifier without putting the key directly into shell history:

read -rsp 'Fluxo API key: ' FLUXO_API_KEY; printf '\n'; export FLUXO_API_KEY

read -rp 'Exact API model identifier: ' FLUXO_MODEL; export FLUXO_MODEL

Then send a deliberately small request: — python3 -c 'import json,os; print(json.dumps({"model":os.environ["FLUXO_MODEL"],"messages":[{"role":"user","content":"Suggest one concise name for a budget-checking function."}],"max_tokens":64}))' > /tmp/fluxo-request.json

bash check-budget.sh && curl --fail-with-body https://api.fluxorelay.com/v1/chat/completions -H "Authorization: Bearer $FLUXO_API_KEY" -H 'Content-Type: application/json' --data-binary @/tmp/fluxo-request.json

4. Record actual charges before the next run

After checking the actual charge in Fluxo, record it. For an illustrative charge of exactly $0.03, run:

sqlite3 "$FLUXO_LEDGER" 'INSERT INTO charges (cents) VALUES (3);'

Use your actual amount, rounding upward to a cent when necessary. Record every charge once, including other tools using the same budget. Cache activity affects billing, so request counts alone are insufficient.

This check blocks starts only after a recorded threshold is reached. A single run can overshoot, and concurrent runs can race. Leave headroom and reconcile frequently; this script is useful visibility, not a hard billing guarantee.

If this fits your terminal routine, create a Fluxo account and try one small request. Inviting other developers can also earn you a referral share when they pay; keep that separate from your spending ledger. For help interpreting your flow pass limits, leave a note on the contact page after signing in.

Next in the buffer

Sign up in a minute and get credit to try every model mentioned here. Sign up →