- Rust 100%
Replace the activity endpoint with POST /api/v1/analytics/query, which returns today's partial-day data, a model dimension, and api_key_id key names. Fixes: today missing from 7d/30d views, models like Luna dropped from the cost chart (lower COST_THRESHOLD to $0.01), and API Keys view showing 'unknown'. Also fixes the 30d window truncation (endpoint honors time_range not timeRange) and renders empty days in the chart, and spreads the OpenRouter/ Anthropic chart palettes so stacked segments are visually distinct. |
||
|---|---|---|
| .github/workflows | ||
| src | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| CHANGELOG.md | ||
| LICENSE | ||
| README.md | ||
| release-plz.toml | ||
__ __ __
| \ | \ | \
_| $$_ ______ | $$ __ _| $$_ ______ ______
| $$ \ / \ | $$ / \| $$ \ / \ / \
\$$$$$$ | $$$$$$\| $$_/ $$ \$$$$$$ | $$$$$$\| $$$$$$\
| $$ __ | $$ | $$| $$ $$ | $$ __ | $$ | $$| $$ | $$
| $$| \| $$__/ $$| $$$$$$\ | $$| \| $$__/ $$| $$__/ $$
\$$ $$ \$$ $$| $$ \$$\ \$$ $$ \$$ $$| $$ $$
\$$$$ \$$$$$$ \$$ \$$ \$$$$ \$$$$$$ | $$$$$$$
| $$
| $$
\$$
htop but for llm tokens
toktop is a terminal-based dashboard for OpenAI, Anthropic and OpenRouter token usage and costs. It allows user (admin of their openai, anthropic and openrouter accounts) to monitor their usage inside terminal without constantly jumping into different websites.
Installation
cargo install toktop --locked
Usage
# 1. Set Environment Variables
export OPENAI_ADMIN_KEY="your-openai-key"
export ANTHROPIC_ADMIN_KEY="your-anthropic-key"
export OPENROUTER_API_KEY="your-openrouter-key"
toktop
# 2. Use env file
toktop -e .env
# 3. Don't set env var, toktop will prompt for api key
toktop
Hotkeys
←/→- Switch between options columns (Provider, Metrics, Date Range, Group By)↑/↓- Choosing optionsh/l- Scrolling charts if scroll bar is presentr- Refresh dataq- Quit the application
API Keys
OPENAI
It requires $OPENAI_ADMIN_KEY from https://platform.openai.com/settings/organization/admin-keys with READ permission to Management API Scope and Usage API Scope.
It tracks two data:
- Cost:
GET /v1/organization/costs - Usage:
GET v1/organization/usage/completionsGET v1/organization/usage/embeddingsGET v1/organization/usage/images
To group by API Keys, it also needs read access to the following endpoint:
- Get project ids:
GET v1/organization/projects - Get api key names from projects:
GET v1/organization/projects/{project_id}/api_keys
ANTHROPIC
It requires $ANTHROPIC_ADMIN_KEY from https://console.anthropic.com/settings/admin-keys.
It tracks two data:
- Cost:
GET /v1/organizations/cost_report - Usage:
GET /v1/organizations/usage_report/messages
OPENROUTER
It requires $OPENROUTER_API_KEY, which must be an API Management key (not a regular API key), from https://openrouter.ai/settings/management-keys. Regular sk-or-v1-... keys cannot access the analytics endpoint this tool uses. Management keys are for administrative operations only (they cannot make inference requests), and can be scoped to read-only access.
It tracks two data from a single endpoint:
- Cost:
POST /api/v1/analytics/query(per-day USD cost, grouped by model and API key) - Usage:
POST /api/v1/analytics/query(per-day prompt/completion/reasoning tokens and request counts, grouped by model and API key)
OpenRouter usage comes from POST /api/v1/analytics/query, which returns per-day cost, prompt/completion/reasoning tokens, and request counts grouped by model and API key, including the current day.
Others
I would love to track my other LLM spends from Gemini and Cursor as well. Unfortunately, Cursor Admin API requires enterprise plan, which I don't have at the moment. Gemini does not seem to expose usage/cost in API in the same manner.