Cost Tracking
SwarmClaw tracks token usage and estimates costs for every message across all providers.
How It Works
Each message exchanged with an LLM provider includes token counts in the response metadata. SwarmClaw records:
- Input tokens — tokens sent to the provider (system prompt + conversation history + user message)
- Output tokens — tokens generated by the provider
- Total tokens — sum of input and output
- Estimated cost — calculated from the provider's pricing per token
Token counts are stored per-message in the session data and aggregated for reporting.
Usage API
Retrieve usage data via the REST API:
GET /api/usage
Query Parameters
| Parameter | Description |
|---|---|
from | Start date (ISO 8601). Default: 30 days ago |
to | End date (ISO 8601). Default: now |
agent | Filter by agent ID |
provider | Filter by provider name |
session | Filter by session ID |
Response
{
"totalInputTokens": 1250000,
"totalOutputTokens": 340000,
"totalTokens": 1590000,
"estimatedCost": 12.45,
"byAgent": { ... },
"byProvider": { ... },
"daily": [ ... ]
}
UsageBadge
The UsageBadge component in the chat header shows a live token count and estimated cost for the current session. It updates after each message.
Cost Estimation
Costs are estimated using built-in pricing tables for known providers (Anthropic, OpenAI). For custom providers and Ollama, cost is reported as $0 unless you configure custom pricing in the provider settings.