Track and report AI API spending across multiple providers. Helps users stay within budget and catch unexpected cost spikes.
When to Use
Use when the user asks about API costs, spending, usage, billing, budget, or wants to check how much they've spent on AI providers.
Supported Providers
Anthropic
curl -s https://api.anthropic.com/v1/usage \
-H "x-api-key: ${ANTHROPIC_API_KEY}" \
-H "anthropic-version: 2023-06-01" \
--data '{"start_date":"'"$(date -u -v-30d +%Y-%m-%d 2>/dev/null || date -u -d '30 days ago' +%Y-%m-%d)"'","end_date":"'"$(date -u +%Y-%m-%d)"'"}'If the API doesn't support this endpoint, direct the user to:
- https://console.anthropic.com/settings/usage
OpenAI
open "https://platform.openai.com/usage"Direct the user to check their dashboard at https://platform.openai.com/usage.
OpenRouter
curl -s https://openrouter.ai/api/v1/auth/key \
-H "Authorization: Bearer ${OPENROUTER_API_KEY}" | python3 -m json.toolThis returns usage data including total credits used. Dashboard: https://openrouter.ai/activity
Manual Budget Tracking
If API endpoints aren't available, help the user maintain a simple cost log:
echo "$(date +%Y-%m-%d),anthropic,$(echo 'estimated_cost'),note" >> ~/.openclaw/workspace/cost-log.csvCost estimation by model (approximate per 1M tokens):
| Model | Input | Output |
|---|---|---|
| claude-sonnet-4-6 | $3 | $15 |
| claude-opus-4-6 | $15 | $75 |
| gpt-5.2 | $2.50 | $10 |
| gpt-4.1 | $2 | $8 |
| gemini-3.1-pro | $1.25 | $5 |
Response Format
Present spending as a clean summary:
💰 AI Spending Report (Last 30 days)
━━━━━━━━━━━━━━━━━━━━━━
Anthropic: $32.40 (Sonnet 4.6 primary)
OpenRouter: $8.15 (fallback usage)
Total: $40.55
Budget: $50/month
Remaining: $9.45 (19%)
━━━━━━━━━━━━━━━━━━━━━━
💡 Tip: Heartbeats account for ~$4/mo. Use a cheaper model.Rules
- Never expose or log full API keys — only use environment variables.
- If a provider API doesn't return cost data, direct the user to the web dashboard.
- Proactively warn if spend exceeds 80% of a stated budget.
- Suggest cost optimizations: cheaper heartbeat models, lower fallback frequency, cache-ttl mode.