- Go 51.1%
- TypeScript 36.7%
- CSS 5.5%
- Python 4.1%
- Go Template 2.3%
- Other 0.3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
All checks were successful
ci / frontend-tests (push) Successful in 38s
ci / integration-tests (push) Successful in 14m3s
ci / backend-tests (push) Successful in 16m12s
ci / mariadb-tests (push) Successful in 54s
ci / build (push) Successful in 7m38s
ci / build-1 (push) Successful in 7m19s
ci / frontend-docker (push) Successful in 0s
ci / backend-docker (push) Successful in 0s
ci / build-2 (push) Successful in 15s
ci / chart (push) Successful in 0s
|
||
| .forgejo/workflows | ||
| backend | ||
| container | ||
| docs/screenshots | ||
| frontend | ||
| helm | ||
| integrations | ||
| .dockerignore | ||
| .gitignore | ||
| compose.yaml | ||
| Dockerfile.backend | ||
| Dockerfile.frontend | ||
| README.md | ||
Tokentracker
A small, self-hostable dashboard for LLM token usage and cost.
- Sign in with OpenID Connect or an anonymous account (a random account key, no email or password).
- Download a share card image of your usage.
- Track Claude Code, LiteLLM, Open WebUI or anything that can send JSON. The Integrations page creates a key and shows the ready to paste configuration.
- Query your usage from an assistant through the MCP server.
- Users can delete their account with all its usage and keys.
- Only token counts, model names, cost and time are stored. Prompts and responses are never stored.
Backend: Go, Gin, Gorm (SQLite or MySQL/MariaDB), swaggo. Frontend: React, Vite.
Screenshots
All screenshots show made-up demo data.
Integrations
API keys
Run with Docker Compose
docker compose up -d --build
Open http://localhost:8181. For anything but local use, put a TLS reverse proxy in front and set PUBLIC_URL.
Run on Kubernetes
helm install tokentracker oci://forgejo.jonasled.dev/jonasled/tokentracker/charts/tokentracker --version <version> \
--set publicUrl=https://tokens.example.com \
--set ingress.enabled=true --set 'ingress.hosts[0].host=tokens.example.com' \
--set 'ingress.hosts[0].paths[0].path=/' --set 'ingress.hosts[0].paths[0].pathType=Prefix'
See helm/values.yaml for TLS, OpenID and external database settings. LiteLLM sends large batches, so raise the ingress body size limit (see the ingress.annotations example).
Multiple replicas
The backend can run with two or more replicas on MySQL or MariaDB (Helm: --set replicaCountBackend=2). Sessions and API keys live in the database, so no sticky sessions are needed. Replicas that start together take turns migrating the schema. SQLite supports only one replica.
Configuration
| Variable | Default | Description |
|---|---|---|
DB_DRIVER |
sqlite |
sqlite or mysql |
DB_NAME |
./database.db |
SQLite file or MySQL database |
DB_USER, DB_PASSWORD, DB_HOST, DB_PORT |
port 3306 |
MySQL only |
PUBLIC_URL |
URL users open. https:// turns on Secure cookies. Required for OpenID |
|
REGISTRATION_ENABLED |
true |
Allow anyone to create an anonymous account |
OIDC_ISSUER_URL, OIDC_CLIENT_ID, OIDC_CLIENT_SECRET |
Enable OpenID login. Redirect URI: <PUBLIC_URL>/api/v1/auth/oidc/callback |
|
PORT |
8080 |
Backend port |
LOG_LEVEL, LOG_FOLDER |
INFO |
Logging (go-libs) |
With OpenID enabled, everybody your identity provider lets through gets an account. Restrict access there. To allow only OpenID, set REGISTRATION_ENABLED=false.
API
Swagger UI: /api/docs/index.html.
| Endpoint | Sender |
|---|---|
POST /api/v1/ingest/usage |
Open WebUI filter, own clients |
POST /api/v1/ingest/litellm |
LiteLLM generic_api callback |
POST /api/v1/ingest/otlp/v1/logs |
Claude Code telemetry (OTLP, http/json) |
/api/v1/mcp |
MCP clients (Streamable HTTP): get_usage_summary, list_recent_requests |
Ponytail history: on the Integrations page, under Import from Ponytail, select the CSV files in ~/.config/ponytail/band/ (/ponytail band import fills them with past Claude Code sessions). Each session becomes one request with source ponytail. The files have no input/cache split, so all non-output tokens count as input. Cost is Ponytail's figure. Project and session names are not uploaded. A session already imported is not updated by a later import. Sessions that Claude Code telemetry also reported are counted twice.
Clients authenticate with Authorization: Bearer <API key>. Keys have one scope: ingest can only send usage, read can only query it through MCP.
Cost is what the client reports. Claude Code and LiteLLM send an estimate, Open WebUI sends none; Tokentracker has no price list.
If two clients see the same request (for example Claude Code routed through LiteLLM and both connected), it is counted once per source.
Development
cd backend && go run . # API on :8080
cd frontend && pnpm install && pnpm dev # UI on :5173, proxies /api
cd backend && go test ./...
cd backend && go generate # after changing API annotations
cd frontend && pnpm test && pnpm build
python3 -m unittest discover integrations # needs pydantic
Set TEST_MYSQL_DSN (for example user:pass@tcp(127.0.0.1:3306)/test?parseTime=True&loc=UTC) to run the backend tests against MariaDB. The tables in that database are dropped.
Features and bugs are tracked as issues. A commit with Closes #<n> closes its issue when it reaches master.
Known limits
- An anonymous account key cannot be recovered or rotated.
- Users can delete only their own account (Account page). There is no admin role. Database backups are not touched.
- Anonymous registration is rate limited per backend process for all visitors together, so the total limit grows with the number of replicas. Add per-IP limits at your proxy for a public instance.
- Usage is kept forever.
- The schema is managed by Gorm
AutoMigrate, which only adds.