Overview
The Tokens API provides comprehensive token usage tracking and cost analysis across all agents, models, and sessions. Track consumption patterns, analyze costs per agent, and export data for billing and optimization.Authentication
All token endpoints require authentication via:- Session Cookie:
mc-session(set after login) - API Key:
x-api-keyheader
- GET: Viewer role
- POST: Operator role
Query Token Usage
GET /api/tokens
Query token usage with multiple action modes for different use cases.
Query Parameters
Query action to perform
Time window for data filtering
Export format (only for
action=export)Action: List
List Token Usage Records
Retrieve recent token usage records with pagination.
Request
Response Fields
Array of token usage records (max 100)
Total number of records matching filters
Applied timeframe filter
Example Request
Example Response
Action: Stats
Get Aggregated Statistics
Retrieve aggregated token usage and cost statistics.
Request
Response Fields
Overall statistics
Statistics broken down by model (key: model name, value: TokenStats)
Statistics broken down by session (key: session ID, value: TokenStats)
Statistics broken down by agent (key: agent name, value: TokenStats)
Applied timeframe filter
Number of records analyzed
Example Request
cURL
Example Response
Action: Agent Costs
Per-Agent Cost Breakdown
Detailed cost analysis per agent with model breakdown and daily timelines.
Request
Response Fields
Cost breakdown per agent (key: agent name)
Applied timeframe filter
Number of records analyzed
Example Request
cURL
Example Response
Action: Export
Export Usage Data
Export complete token usage data in JSON or CSV format.
Request
Response
Returns file download with appropriate Content-Disposition header. JSON Export:- Content-Type:
application/json - Includes: usage records, summary stats, model stats, session stats
- Content-Type:
text/csv - Columns: timestamp, agentName, model, sessionId, operation, inputTokens, outputTokens, totalTokens, cost, duration
Example Request
Action: Trends
Hourly Usage Trends
Get hourly token usage and cost trends for the last 24 hours.
Request
Response Fields
Array of hourly data points
Applied timeframe (always includes recent 24h)
Example Response
Record Token Usage
POST /api/tokens
Manually record token usage for a session.
Request Body
Model identifier (e.g., “claude-sonnet-4”)
Session identifier
Number of input tokens
Number of output tokens
Operation type
Request duration in milliseconds
Response
Whether recording was successful
Created TokenUsageRecord object
Example Request
Example Response
Model Pricing
Supported Models & Pricing
Pricing per 1,000 tokens for supported models.
Pricing Table
| Model | Cost per 1K tokens | Provider |
|---|---|---|
claude-sonnet-4 | $3.00 | Anthropic |
claude-3-5-haiku | $0.25 | Anthropic |
claude-opus-4-5 | $15.00 | Anthropic |
llama-3.1-8b-instant | $0.05 | Groq |
llama-3.3-70b-versatile | $0.59 | Groq |
kimi-k2.5 | $1.00 | Moonshot |
minimax-m2.1 | $0.30 | Minimax |
ollama/deepseek-r1:14b | $0.00 | Ollama (local) |
ollama/qwen2.5-coder:7b | $0.00 | Ollama (local) |
ollama/qwen2.5-coder:14b | $0.00 | Ollama (local) |
Pricing is automatically calculated based on model names. If an exact match isn’t found, Mission Control attempts partial matching (e.g., “claude-sonnet” matches “anthropic/claude-sonnet-4”). Unknown models default to $1.00 per 1K tokens.
Data Sources
Token Data Sources
How Mission Control aggregates token usage data.
Priority Order
-
Token Usage Database (Primary)
- Stored in
token_usageSQLite table - Most authoritative source
- Includes heartbeat data from agents
- Stored in
-
JSON File Storage (Secondary)
- Manually recorded usage via POST endpoint
- File location: configured in
tokensPath - Limited to 10,000 most recent records
-
Gateway Sessions (Fallback)
- Derived from active OpenClaw sessions
- Used when no persistent data exists
- Real-time but less comprehensive
Best Practices
Optimization Tips
Recommendations for token usage monitoring and cost optimization.
Cost Monitoring
- Set up regular exports - Export data weekly for billing analysis
- Monitor agent-costs - Identify high-cost agents for optimization
- Track model usage - Use cheaper models (Haiku) for simple tasks
- Review trends - Identify usage spikes and anomalies
Performance
- Use
timeframeparameter to limit data volume - Export CSV for large datasets (more efficient than JSON)
- Cache stats responses for dashboards
- Use agent-costs for detailed analysis, stats for quick overview
Data Retention
- JSON file storage limited to 10,000 records
- Database storage unlimited (manage via SQL if needed)
- Consider periodic exports for long-term archival