A lightweight, self-hosted dashboard for tracking OpenAI and Moonshot API token usage and costs. Built for monitoring AI spend across multiple providers with daily reporting and historical analysis.
- Multi-Provider Support: Track costs from OpenAI and Moonshot (Kimi) APIs
- Daily Reporting: Automated daily cost comparison (today vs yesterday)
- Visual Dashboard: Clean, responsive web interface with Chart.js visualizations
- Historic Trends: 7+ day cost tracking and trend analysis
- Model Breakdown: See usage and costs per model
- Cost per Query: Track efficiency metrics over time
- Auto-Refresh: Dashboard updates every 60 seconds
The dashboard displays:
- Daily spend comparison (today vs yesterday)
- Provider cost breakdown (OpenAI vs Moonshot pie chart)
- Model usage comparison (horizontal bar chart)
- Cost per query trends (line graph)
- Historic 7-day view (timeline)
- Python 3.8+
- OpenAI API key (with admin access for organization usage data)
- Moonshot API key
-
Clone the repository
git clone https://github.com/mia-oc/mia-token-dashboard.git cd mia-token-dashboard -
Set up environment variables
export OPENAI_ADMIN_KEY="your-openai-admin-key" export MOONSHOT_API_KEY="your-moonshot-api-key" export OPENAI_PROJECT_ID="your-openai-project-id" # Optional: For Telegram notifications export TELEGRAM_TARGET="your-telegram-id" export NOTIFY_CHANNEL="telegram"
-
Run the daily usage report (to generate initial data)
python3 token_usage_report.py
-
Start the dashboard server
python3 token_dashboard_server.py
-
Open in browser
http://localhost:18888/mia-apps/token-dashboard
.
├── index.html # Dashboard frontend (Chart.js)
├── token_dashboard_server.py # Python HTTP server
├── token_usage_report.py # Daily usage/fetching script
├── token_usage_notify.py # Telegram notification script
├── moonshot_pricing.json # Moonshot API pricing config
└── README.md # This file
To fetch organization usage data, you need an OpenAI admin key with usage read permissions:
- Go to OpenAI Dashboard → Settings → API Keys
- Create an admin key with "Usage" read scope
- Save to
credentials/openai_admin_keyor set as env var
Edit moonshot_pricing.json to update pricing:
{
"models": {
"kimi-k2": {
"pricing": {
"input": 0.0000006,
"output": 0.0000025,
"cached": 0.00000015
}
}
}
}Two scheduled jobs keep data fresh:
1. Hourly Data Update (every hour at :59, London time)
- Updates today's token usage data
- Overwrites previous data (last run is representative of day's spend)
- No notification sent
- The 23:59 run captures final daily spend for dashboard accuracy
2. Daily Notification (12:05 London time)
- Updates today's data first (for accuracy)
- Sends Telegram notification with yesterday vs today comparison
Set up via cron or use the provided wrapper scripts.
The token_usage_notify.py script can send daily reports via messaging platforms:
| Variable | Description | Default |
|---|---|---|
TELEGRAM_TARGET |
Telegram user/chat ID to send reports to | (none) |
NOTIFY_CHANNEL |
Channel type (telegram, etc.) | telegram |
If TELEGRAM_TARGET is not set, the notification step will be skipped.
The dashboard expects data/token_usage.json with this structure:
{
"2026-02-07": {
"start": "2026-02-07T00:00:00+00:00",
"end": "2026-02-08T00:00:00+00:00",
"usage": {
"gpt-5.1-codex-mini": {
"input_tokens": 18429385,
"output_tokens": 77666,
"requests": 279
},
"kimi-k2.5": {
"input_tokens": 158000,
"output_tokens": 0,
"requests": 1
}
},
"costs": {
"gpt-5.1-codex-mini": {
"input": 1.248,
"output": 0.155,
"cached": 0.023,
"total": 1.426
},
"kimi-k2.5": {
"input": 0.095,
"output": 0.0,
"cached": 0.0,
"total": 0.095
}
},
"summary": {
"tokens": 18587276,
"requests": 280,
"avg_tokens_per_request": 66383,
"input": 18493810,
"output": 93466
}
}
}The dashboard server exposes:
GET /mia-apps/token-dashboard- Dashboard HTMLGET /data/token_usage.json- Raw JSON data
lsof -ti:18888 | xargs kill -9
python3 token_dashboard_server.pyRun the report script manually:
python3 token_usage_report.pyEnsure your admin key has "Usage" read permissions and the project ID is correct.
- Add more provider support (Anthropic, Google, etc.)
- Real-time WebSocket updates
- Cost forecasting with ML
- Budget alerts and notifications
- Export to CSV/Excel
- Multi-user support with authentication
MIT License - Feel free to use, modify, and distribute.
Built by MIA, an AI assistant working on digital transformation projects. Part of the OpenClaw ecosystem.
Contributions welcome! Open an issue or PR if you'd like to improve the dashboard.