tokviz 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Waldek Mastykarz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # tokviz
2
+
3
+ See where your LLM tokens go.
4
+
5
+ ![tokviz dashboard](assets/screenshot.png)
6
+
7
+ One command. Real-time token usage and cost dashboard. No database, no Docker, no config.
8
+
9
+ ```bash
10
+ npx tokviz
11
+ ```
12
+
13
+ tokviz receives standard [OpenTelemetry](https://opentelemetry.io/) traces, filters for LLM spans (`gen_ai.*` attributes), and displays token consumption and costs in a live dashboard. When you stop it, it's gone. Nothing persists.
14
+
15
+ ## Why
16
+
17
+ You're building an app that calls LLMs. You want to know:
18
+
19
+ - How many tokens each request burns
20
+ - What it costs per interaction
21
+ - Which models are actually being used (routing, fallbacks)
22
+ - Whether something is silently eating your budget
23
+
24
+ Existing tools are either too heavy (Langfuse, OpenLIT — databases, Docker, SDKs) or too generic (Aspire Dashboard — shows everything, highlights nothing). tokviz shows you LLM spend and nothing else.
25
+
26
+ ## Quick start
27
+
28
+ ```bash
29
+ npx tokviz
30
+ ```
31
+
32
+ Point your OTLP exporter at `http://localhost:4318` and you're done.
33
+
34
+ Works with [Dev Proxy](https://aka.ms/devproxy), the OpenTelemetry SDKs, and anything that emits `gen_ai.*` span attributes following the [OpenTelemetry Gen AI semantic conventions](https://opentelemetry.io/docs/specs/semconv/gen-ai/).
35
+
36
+ ### With Dev Proxy
37
+
38
+ ```json
39
+ {
40
+ "plugins": [{
41
+ "name": "OpenAITelemetryPlugin",
42
+ "enabled": true,
43
+ "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll"
44
+ }]
45
+ }
46
+ ```
47
+
48
+ ### With OpenTelemetry SDK
49
+
50
+ ```bash
51
+ export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
52
+ ```
53
+
54
+ ## What you see
55
+
56
+ **Overview** — Token usage and cost over time, summary cards for total tokens, cost, requests, and unique models.
57
+
58
+ **Models** — Breakdown per response model: request count, input/output tokens, total cost.
59
+
60
+ **Requests** — Every request with timestamp, model, operation, tokens, cost, and duration. Click any row to see all span attributes.
61
+
62
+ ## Options
63
+
64
+ ```
65
+ npx tokviz [options]
66
+
67
+ --port <number> Port to listen on (default: 4318)
68
+ --no-open Don't auto-open the browser
69
+ ```
70
+
71
+ ## How it works
72
+
73
+ tokviz is an OTLP HTTP receiver that:
74
+
75
+ 1. Accepts traces on `POST /v1/traces` (protobuf and JSON)
76
+ 2. Filters spans — only processes those with `gen_ai.*` attributes
77
+ 3. Stores everything in memory — no database, no disk writes
78
+ 4. Pushes updates to the browser over WebSocket — zero polling
79
+
80
+ Supports both `application/x-protobuf` and `application/json` content types.
81
+
82
+ ## Development
83
+
84
+ ```bash
85
+ git clone https://github.com/waldekmastykarz/tokviz.git
86
+ cd tokviz
87
+ npm install
88
+ npm run dev
89
+ ```
90
+
91
+ Opens the Vite dev server at `http://localhost:5173` with hot reload. The Express backend runs on port 4318.
92
+
93
+ ## License
94
+
95
+ MIT
@@ -0,0 +1 @@
1
+ :root{--bg: #ffffff;--bg-secondary: #f5f5f5;--text: #1a1a1a;--text-secondary: #666666;--border: #e0e0e0;--accent: #2563eb;--accent-hover: #1d4ed8;--card-bg: #ffffff;--card-shadow: 0 1px 3px rgba(0, 0, 0, .1);--chart-input: #3b82f6;--chart-output: #f59e0b;--chart-cost: #8b5cf6}@media(prefers-color-scheme:dark){:root{--bg: #0a0a0a;--bg-secondary: #1a1a1a;--text: #e5e5e5;--text-secondary: #999999;--border: #333333;--accent: #3b82f6;--accent-hover: #60a5fa;--card-bg: #1a1a1a;--card-shadow: 0 1px 3px rgba(0, 0, 0, .3);--chart-input: #60a5fa;--chart-output: #fbbf24;--chart-cost: #a78bfa}}*{margin:0;padding:0;box-sizing:border-box}body{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;background:var(--bg);color:var(--text);line-height:1.5}.app{max-width:1200px;margin:0 auto;padding:24px}.header{display:flex;align-items:center;justify-content:space-between;margin-bottom:24px}.header h1{font-size:24px;font-weight:600}.connection-status{display:flex;align-items:center;gap:6px;font-size:13px;color:var(--text-secondary)}.status-dot{width:8px;height:8px;border-radius:50%;background:#ef4444}.status-dot.connected{background:#22c55e}.tabs{display:flex;gap:4px;border-bottom:1px solid var(--border);margin-bottom:24px}.tab{padding:8px 16px;border:none;background:none;color:var(--text-secondary);font-size:14px;font-weight:500;cursor:pointer;border-bottom:2px solid transparent;transition:color .15s,border-color .15s}.tab:hover{color:var(--text)}.tab.active{color:var(--accent);border-bottom-color:var(--accent)}.cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:16px;margin-bottom:24px}.card{background:var(--card-bg);border:1px solid var(--border);border-radius:8px;padding:16px;box-shadow:var(--card-shadow)}.card-label{font-size:12px;text-transform:uppercase;letter-spacing:.5px;color:var(--text-secondary);margin-bottom:4px}.card-value{font-size:24px;font-weight:600}.chart-container{background:var(--card-bg);border:1px solid var(--border);border-radius:8px;padding:20px;margin-bottom:24px;box-shadow:var(--card-shadow)}.chart-title{font-size:14px;font-weight:500;margin-bottom:16px;color:var(--text-secondary)}table{width:100%;border-collapse:collapse;font-size:13px}th{text-align:left;padding:10px 12px;border-bottom:2px solid var(--border);font-weight:600;color:var(--text-secondary);font-size:12px;text-transform:uppercase;letter-spacing:.5px}td{padding:10px 12px;border-bottom:1px solid var(--border)}tr.clickable{cursor:pointer}tr.clickable:hover{background:var(--bg-secondary)}.empty-state{display:flex;flex-direction:column;align-items:center;justify-content:center;min-height:400px;text-align:center;color:var(--text-secondary)}.empty-state h2{font-size:20px;margin-bottom:12px;color:var(--text)}.empty-state p{max-width:500px;margin-bottom:8px}.empty-state code{background:var(--bg-secondary);padding:2px 6px;border-radius:4px;font-size:13px}.detail-overlay{position:fixed;top:0;right:0;bottom:0;left:0;background:#00000080;display:flex;align-items:center;justify-content:center;z-index:100}.detail-panel{background:var(--card-bg);border:1px solid var(--border);border-radius:12px;padding:24px;max-width:600px;width:90%;max-height:80vh;overflow-y:auto;box-shadow:0 20px 60px #0000004d}.detail-panel h3{margin-bottom:16px;font-size:16px}.detail-panel .close-btn{float:right;border:none;background:none;font-size:20px;cursor:pointer;color:var(--text-secondary);padding:4px 8px}.detail-panel .close-btn:hover{color:var(--text)}.attr-table{width:100%}.attr-table td{padding:6px 8px;vertical-align:top}.attr-table td:first-child{font-weight:500;white-space:nowrap;width:40%;color:var(--text-secondary)}.attr-table td:last-child{word-break:break-all}.mono{font-family:SF Mono,Fira Code,monospace;font-size:12px}