9.8kā
by g0head
tokenguard ā OpenClaw Skill
tokenguard is an OpenClaw Skills integration for ai ml workflows. API cost guardian for AI agents. Track spending, enforce limits, prevent runaway costs. Essential for any agent making paid API calls.
Skill Snapshot
| name | tokenguard |
| description | API cost guardian for AI agents. Track spending, enforce limits, prevent runaway costs. Essential for any agent making paid API calls. OpenClaw Skills integration. |
| owner | g0head |
| repository | g0head/tokenguard |
| language | Markdown |
| license | MIT |
| topics | |
| security | L1 |
| install | openclaw add @g0head/tokenguard |
| last updated | Feb 7, 2026 |
Maintainer

name: tokenguard version: 1.0.0 description: API cost guardian for AI agents. Track spending, enforce limits, prevent runaway costs. Essential for any agent making paid API calls. author: PaxSwarm license: MIT homepage: https://clawhub.com/skills/tokenguard keywords: [cost, budget, spending, limit, api, tokens, guard, monitor] triggers: ["cost limit", "spending limit", "budget", "how much spent", "tokenguard", "api cost"]
š”ļø TokenGuard ā API Cost Guardian
Protect your wallet from runaway API costs.
TokenGuard tracks your agent's spending per session, enforces configurable limits, and alerts you before you blow your budget.
Why TokenGuard?
AI agents can rack up serious API costs fast. One runaway loop = hundreds of dollars. TokenGuard gives you:
- Session-based tracking ā Costs reset daily (or on demand)
- Hard limits ā Actions blocked when budget exceeded
- Pre-flight checks ā Verify budget BEFORE expensive calls
- Override controls ā Extend limits or bypass when needed
- Full audit trail ā Every cost logged with timestamps
Installation
clawhub install tokenguard
Or manually:
mkdir -p ~/.openclaw/workspace/skills/tokenguard
# Copy SKILL.md and scripts/tokenguard.py
chmod +x scripts/tokenguard.py
Quick Start
# Check current status
python3 scripts/tokenguard.py status
# Set a $20 limit
python3 scripts/tokenguard.py set 20
# Before an expensive call, check budget
python3 scripts/tokenguard.py check 5.00
# After the call, log actual cost
python3 scripts/tokenguard.py log 4.23 "Claude Sonnet - code review"
# View spending history
python3 scripts/tokenguard.py history
Commands
| Command | Description |
|---|---|
status | Show current limit, spent, remaining |
set <amount> | Set spending limit (e.g., set 50) |
check <cost> | Check if estimated cost fits budget |
log <amount> [desc] | Log a cost after API call |
reset | Clear session spending |
history | Show all logged entries |
extend <amount> | Add to current limit |
override | One-time bypass for next check |
export [--full] | Export data as JSON |
Exit Codes
0ā Success / within budget1ā Budget exceeded (check command)2ā Limit exceeded after logging
Use exit codes in scripts:
if python3 scripts/tokenguard.py check 10.00; then
# proceed with expensive operation
else
echo "Over budget, skipping"
fi
Budget Exceeded Alert
When a check would exceed your limit:
š« BUDGET EXCEEDED
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā®
ā Current spent: $ 4.0000 ā
ā This action: $ 10.0000 ā
ā Would total: $ 14.0000 ā
ā Limit: $ 10.00 ā
ā Over by: $ 4.0000 ā
ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
š” Options:
tokenguard extend 5 # Add to limit
tokenguard set <amt> # Set new limit
tokenguard reset # Clear session
tokenguard override # One-time bypass
Integration Pattern
For agents using paid APIs:
import subprocess
import sys
def check_budget(estimated_cost: float) -> bool:
"""Check if action fits budget."""
result = subprocess.run(
["python3", "scripts/tokenguard.py", "check", str(estimated_cost)],
capture_output=True
)
return result.returncode == 0
def log_cost(amount: float, description: str):
"""Log actual cost after API call."""
subprocess.run([
"python3", "scripts/tokenguard.py", "log",
str(amount), description
])
# Before expensive operation
if not check_budget(5.00):
print("Budget exceeded, asking user...")
sys.exit(1)
# Make API call
response = call_expensive_api()
# Log actual cost
log_cost(4.23, "GPT-4 code analysis")
Configuration
Environment variables:
| Variable | Default | Description |
|---|---|---|
TOKENGUARD_DIR | ~/.tokenguard | Storage directory |
TOKENGUARD_DEFAULT_LIMIT | 20.0 | Default limit in USD |
TOKENGUARD_WARNING_PCT | 0.8 | Warning threshold (0-1) |
Cost Reference
Common API pricing (per 1M tokens):
| Model | Input | Output |
|---|---|---|
| Claude 3.5 Sonnet | $3 | $15 |
| Claude 3 Haiku | $0.25 | $1.25 |
| GPT-4o | $2.50 | $10 |
| GPT-4o-mini | $0.15 | $0.60 |
| GPT-4-turbo | $10 | $30 |
Rule of thumb: 1000 tokens ā 750 words
Storage
Data stored in ~/.tokenguard/ (or TOKENGUARD_DIR):
limit.jsonā Current limit configurationsession.jsonā Today's spending + entriesoverride.flagā One-time bypass flag
Best Practices
- Set realistic limits ā Start with $10-20 for development
- Check before expensive calls ā Always
checkbefore big operations - Log everything ā Even small costs add up
- Use extend, not reset ā Keep audit trail intact
- Monitor warnings ā 80% threshold = time to evaluate
Changelog
v1.0.0
- Initial release
- Core commands: status, set, check, log, reset, history, extend, override
- Environment variable configuration
- JSON export for integrations
- Daily auto-reset
Built by PaxSwarm ā a murmuration-class swarm intelligence
No README available.
Permissions & Security
Security level L1: Low-risk skills with minimal permissions. Review inputs and outputs before running in production.
Requirements
- OpenClaw CLI installed and configured.
- Language: Markdown
- License: MIT
- Topics:
Configuration
Environment variables: | Variable | Default | Description | |----------|---------|-------------| | `TOKENGUARD_DIR` | `~/.tokenguard` | Storage directory | | `TOKENGUARD_DEFAULT_LIMIT` | `20.0` | Default limit in USD | | `TOKENGUARD_WARNING_PCT` | `0.8` | Warning threshold (0-1) |
FAQ
How do I install tokenguard?
Run openclaw add @g0head/tokenguard in your terminal. This installs tokenguard into your OpenClaw Skills catalog.
Does this skill run locally or in the cloud?
OpenClaw Skills execute locally by default. Review the SKILL.md and permissions before running any skill.
Where can I verify the source code?
The source repository is available at https://github.com/openclaw/skills/tree/main/skills/g0head/tokenguard. Review commits and README documentation before installing.
