Skip to content

Usage Tracking

Automate-E tracks token usage and calculates costs for every Claude API call.

How It Works

After each Claude API response, the usage tracker records:

  • Input tokens -- tokens sent to Claude (system prompt + conversation history + tool results)
  • Output tokens -- tokens generated by Claude (text response + tool calls)
  • Model -- which model was used (determines pricing)
  • Timestamp -- when the call was made

Per-Model Pricing

Cost calculation uses per-model token pricing:

Model Input (per 1M tokens) Output (per 1M tokens)
claude-haiku-4-5-20251001 $0.80 $4.00
claude-sonnet-4-20250514 $3.00 $15.00
claude-opus-4-20250514 $15.00 $75.00

Note

Pricing is hardcoded in usage.js. Update when Anthropic changes rates.

Cost Calculation

For each API call:

cost = (input_tokens / 1_000_000 * input_price) +
       (output_tokens / 1_000_000 * output_price)

Example: A Book-E message using Haiku with 2,000 input tokens and 500 output tokens:

cost = (2000 / 1_000_000 * 0.80) + (500 / 1_000_000 * 4.00)
     = 0.0016 + 0.002
     = $0.0036

Dashboard Integration

The usage tracker feeds data to the dashboard via WebSocket:

  • Per-message cost shown next to each response
  • Cumulative daily/monthly totals on the dashboard overview
  • Token breakdown (input vs output) for optimization

Optimization Tips

Strategy Impact
Use Haiku for routine tasks 18x cheaper than Opus
Keep lore entries concise Reduces input tokens per message
Set appropriate conversationRetention Shorter history = fewer input tokens
Use messageExamples sparingly Each example adds to input tokens