Skip to main content

A small, local token viewer for LLM API calls. Runs a tiny proxy on your laptop; shows the exact cost of every Claude / OpenAI / Gemini call in a dashboard. That's it.

Project description

tokview

A small, local token viewer for LLM API calls.

It runs a tiny proxy on your laptop. Point your apps at it (one env var) and it shows the exact token usage and cost of every call you make to Claude, OpenAI, Gemini, and any other provider you configure, in a simple dashboard.

That's it. No accounts. No cloud. No Docker. One pipx install.

CI PyPI License: MIT Python

Quick start

pipx install tokview
tokview start

You'll see:

+--------------------------------------------------------------------------+
| tokview v0.0.1                                               |
|                                                                          |
|   started in background (pid 12345)                                      |
+--------------------------------------------------------------------------+

Logs: /Users/you/.tokview/tokview.log
Proxy: http://127.0.0.1:4000
Dashboard: http://127.0.0.1:3000

Point any app at the proxy:

export ANTHROPIC_BASE_URL=http://localhost:4000
export OPENAI_BASE_URL=http://localhost:4000/v1
export GOOGLE_BASE_URL=http://localhost:4000

Open the dashboard: http://localhost:3000.

Now make calls as usual (Anthropic SDK, OpenAI SDK, curl, Claude Code, whatever). They flow through the proxy. The dashboard fills in within milliseconds.

Track Claude Code itself

ANTHROPIC_BASE_URL=http://localhost:4000 claude

Every Claude Code interaction lands in the dashboard.

What it shows

  • $ spent today / this week / month-to-date, updating live via SSE — no refresh
  • Per-provider, per-model, per-session, per-tag breakdowns
  • Session waterfall — click any session to see every call in it on a timeline, with cost, tokens, latency and TTFT (a trace view for your agent loops)
  • Savings coach — deterministic, local tips: repeated prompts you could cache, caching savings already realized, cheaper-model what-ifs. No model is called to produce these; it's arithmetic over your own data.
  • Latency & TTFT — time-to-first-token, total latency, and tokens/sec per model (p50/p95), plus per-call in the live tail
  • Cache-hit visibility (Anthropic prompt caching, OpenAI cached input tokens, Gemini context cache) and reasoning-token costs (o-series, Claude extended thinking)

What it doesn't do (intentionally)

  • No team / multi-user features. Single user, localhost only.
  • No virtual API keys. Your real provider keys are read from env vars and forwarded straight to the provider.
  • No alerting / Slack integration. Not yet.
  • No data leaves your machine. Everything in ~/.tokview/db.sqlite.
  • No prompt content stored by default. (Opt-in with redaction; see Privacy below.)

Want any of these? Open an issue. The architecture is designed to evolve into a Postgres + Docker + auth setup later — see the design spec for the "🅑 path".

How it works

Your apps ──► tokview ──► Provider APIs
                       │
                       ├─ writes a row → SQLite
                       └─ pushes a spend event → SSE → Dashboard

The proxy reads the exact token usage and cost from each provider's response object — Anthropic's cache_creation_input_tokens / cache_read_input_tokens, OpenAI's prompt_tokens_details.cached_tokens, Gemini's usageMetadata, the reasoning-tokens fields on o-series and Claude extended-thinking — and applies the right pricing tier for each. Cost is provider-truth, not a tokenizer estimate.

Your SDK doesn't know it's talking to a proxy. The response bytes are forwarded unchanged; the proxy tees the stream as it flies by so token capture never adds latency to your request.

CLI

tokview start [-f]            start the proxy + dashboard (daemonizes; -f for foreground)
tokview stop                  graceful SIGTERM
tokview status                pid, uptime, request counts, errors, diagnostics
tokview logs [-f] [-n N]      tail the server log
tokview export --since DATE   csv/json dump of all calls since DATE
tokview reset                 wipe the SQLite database (with confirmation)
tokview version
tokview config-path

Configuration

~/.tokview/config.yaml is auto-generated on first start. Defaults are localhost-only on ports 3000 / 4000.

proxy:        { port: 4000, bind: 127.0.0.1 }
dashboard:    { port: 3000, bind: 127.0.0.1 }
storage:      { path: ~/.tokview/db.sqlite }
retention:    { days: 90 }
capture:      { prompts: false, responses: false }

Provider API keys come from environment variables (ANTHROPIC_API_KEY, OPENAI_API_KEY, GOOGLE_API_KEY). tokview never reads or persists them.

Privacy

Default: only token counts + cost + metadata. No prompt text. No response text.

If you want full request/response logging, enable it in the config — regex-based redaction runs before persistence, so the DB never holds raw secrets:

capture:
  prompts: true
  responses: true
  redact_patterns:
    - '(sk|pk)-[A-Za-z0-9]{20,}'
    - '[\w.+-]+@[\w-]+\.[\w.-]+'

Security stance

  • All dependencies on the data path (proxy engine, web framework, ASGI server) are version-pinned. Patches arrive automatically on pipx upgrade; major-version jumps require a tokview release.
  • Runtime fetching of model-pricing data is disabled — prices come from the pinned wheel, not a network fetch.
  • Default bind is 127.0.0.1; non-loopback binds require explicit tokview start --allow-remote and the matching config setting.

Full threat model in SECURITY.md.

Status

v0.0.x — alpha. Single-user laptop tool. Works against Claude, OpenAI, Gemini, and 100+ other providers.

Roadmap lives in CHANGELOG.md. Near-term:

  • Cost-map refresh with hash verification
  • tokview test-providers — smoke each configured provider with a $0.001 token
  • Optional Postgres backend for multi-user use

Contributing

PRs welcome. The loop is:

pip install -e ".[dev]"
ruff check src tests
pytest -q

See CONTRIBUTING.md.

License

MIT. © 2026 Tejas Chopra.

Bundled open-source dependencies are credited in NOTICES.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

token_viewer-0.0.1.tar.gz (462.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

token_viewer-0.0.1-py3-none-any.whl (427.0 kB view details)

Uploaded Python 3

File details

Details for the file token_viewer-0.0.1.tar.gz.

File metadata

  • Download URL: token_viewer-0.0.1.tar.gz
  • Upload date:
  • Size: 462.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for token_viewer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 e855e0c0a5f8791ff4bdf822b2389771026146d9573fe15cc3d81e0093da8448
MD5 453589d6f6acaa711c7f1c0fd9e0a7b1
BLAKE2b-256 6ef254e5342d8280a420778136aae19b8d200e860a006d8ae7a59963c043cbd1

See more details on using hashes here.

File details

Details for the file token_viewer-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: token_viewer-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 427.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for token_viewer-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3a9bff8ff4ee9c948268b884b4df81e41304929405e03d7863c8be4fe7d51416
MD5 df767a15cf07a71b54783d4caf5cbf4a
BLAKE2b-256 47858dad37a8d93886d00ac3a62c48608f4a89a4c34b0e305f2f70eb9eb1fbd4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page