No description
  • Go 51.1%
  • TypeScript 36.7%
  • CSS 5.5%
  • Python 4.1%
  • Go Template 2.3%
  • Other 0.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jonas Leder 91aeac8abb
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
update screenshots and add favicon
2026-11-26 00:21:38 +01:00
.forgejo/workflows Fix invalid CI workflow YAML 2026-11-25 23:25:00 +01:00
backend update screenshots and add favicon 2026-11-26 00:21:38 +01:00
container Add Docker images and compose file 2026-11-25 23:03:12 +01:00
docs/screenshots update screenshots and add favicon 2026-11-26 00:21:38 +01:00
frontend update screenshots and add favicon 2026-11-26 00:21:38 +01:00
helm Add Helm chart, image and chart publishing, and README 2026-11-25 23:24:11 +01:00
integrations Add React dashboard and client integrations 2026-11-25 23:03:12 +01:00
.dockerignore Add Docker images and compose file 2026-11-25 23:03:12 +01:00
.gitignore Add project skeleton and CI test pipeline 2026-11-25 22:35:01 +01:00
compose.yaml Add Docker images and compose file 2026-11-25 23:03:12 +01:00
Dockerfile.backend Add Docker images and compose file 2026-11-25 23:03:12 +01:00
Dockerfile.frontend Add Docker images and compose file 2026-11-25 23:03:12 +01:00
README.md update screenshots and add favicon 2026-11-26 00:21:38 +01:00

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.

Usage dashboard with totals, trend lines, a stacked chart of daily usage by model, an activity calendar, and tables by source and model

Dark mode

The dashboard follows the system color scheme.

Usage dashboard in dark mode

Integrations

Integrations page with the Claude Code configuration

API keys

API key page with ingest and read 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.