# Credit budget

Cap spend before the first tool call. No unbounded agent runs.

## Required numbers (ask once, then refuse)
- **Max USD** or **max tokens** for the whole mission
- **Max iterations** (plan → act cycles)
- **Escalation ceiling** — how many strong-model turns allowed

## Credit sources
| Source | Best for | Link |
|--------|----------|------|
| OneAIPass | Multi-model chat, quick probes | https://oneaipass.com/chat.html?utm_source=agentstackkit&utm_medium=site&utm_campaign=hub |
| cheaperllm API | Production routes, Claude via API | https://cheaperllm.com/?utm_source=agentstackkit&utm_medium=site&utm_campaign=hub |
| Cursor subscription | IDE agent turns | https://cursor.com/referral?code=BVN3MVJH9SDO |

## Metering commands
```bash
# Gate secrets before spending
node tools/bin/env-gate.mjs CHEAPERLLM_API_KEY

# Estimate prompt size before a call
cat prompt.md | node tools/bin/token-meter.mjs --price-per-1m 0.50

# Route hint (cheap vs strong)
node tools/bin/model-router.mjs --task classify
node tools/bin/model-router.mjs --task plan

# Append spend log each turn (customize path)
echo '{"turn":1,"model":"cheap","est_tokens":1200}' >> spend.jsonl

# Tape each turn for postmortem
echo '{"turn":1,"spend_usd":0.02}' | node tools/bin/session-tape.mjs record --out ./tapes/run.jsonl
```

## Hard stops
- **80% of budget** → finish current step, write status report, stop
- **Two failed strong-tier retries** → stop; do not loop
- **Missing `CHEAPERLLM_API_KEY` / OneAIPass token** → run env-gate pattern; never invent keys

## Status report template (when stopping on budget)
```
## Budget stop
- Spent: $X / cap $Y (or ~T / cap tokens)
- Iterations: N / max N
- Completed: [success checks met]
- Blocked: [what remains]
- Cheapest next step: [one action under $0.05]
```

Pair with `05-cost-governor.md` for model-tier routing.
