Tokoscope wraps your existing LLM client in two lines and gives you full token visibility, automatic compression, semantic caching, and cost attribution — with zero infrastructure changes.
The fastest way to get started:
// 1. Install // npm install tokoscope // 2. Wrap your client import OpenAI from 'openai' import { wrap } from 'tokoscope' const client = wrap(new OpenAI(), { apiKey: 'ts_live_...' }) // 3. Use exactly as before const res = await client.chat.completions.create({ model: 'gpt-4o', messages: [{ role: 'user', content: 'Hello' }] })
That's it. Every API call is now tracked automatically. Visit your dashboard to see live data.
npm install tokoscope # or yarn add tokoscope
pip install tokoscope
Get your API key from app.tokoscope.com/settings. It starts with ts_live_.
Store it as an environment variable — never hardcode it in your source:
TOKOSCOPE_API_KEY=ts_live_...
const client = wrap(new OpenAI(), { apiKey: process.env.TOKOSCOPE_API_KEY })
import OpenAI from 'openai' import { wrap } from 'tokoscope' const client = wrap(new OpenAI(), { apiKey: process.env.TOKOSCOPE_API_KEY, userId: 'user_123' // optional }) const res = await client.chat.completions.create({ model: 'gpt-4o', messages: [{ role: 'user', content: 'Hello' }] })
import Anthropic from '@anthropic-ai/sdk' import { wrap } from 'tokoscope' const client = wrap(new Anthropic(), { apiKey: process.env.TOKOSCOPE_API_KEY }) const res = await client.messages.create({ model: 'claude-sonnet-4-6', max_tokens: 1024, messages: [{ role: 'user', content: 'Hello' }] })
import { GoogleGenerativeAI } from '@google/generative-ai' import { wrap } from 'tokoscope' const genAI = wrap(new GoogleGenerativeAI(process.env.GEMINI_KEY), { apiKey: process.env.TOKOSCOPE_API_KEY }) const model = genAI.getGenerativeModel({ model: 'gemini-2.5-flash' }) const result = await model.generateContent('Hello')
Pass a userId to attribute token usage to individual end users of your app. Users appear in the Users tab with individual token usage, cost, and waste scores.
const client = wrap(new OpenAI(), { apiKey: process.env.TOKOSCOPE_API_KEY, userId: currentUser.id // any string identifier })
Tokoscope automatically caches responses using two layers:
Cache TTL is 7 days. Clear cache anytime from Settings.
⚡ Tokoscope cache hit [semantic (89.3% match)] — saved 93 tokens ($0.000049)
Prompts with a waste score above 30% are automatically compressed before being tracked. The compressed version is stored alongside the original and visible in the Prompts tab.
Compression uses Claude Haiku and typically reduces prompt length by 40–90% without changing model behavior.
Streaming is fully supported across OpenAI, Anthropic, and Gemini. Set stream: true (or stream=True in Python) as usual. Tokoscope passes every chunk through unchanged and tracks token usage once the stream completes.
const stream = await client.chat.completions.create({ model: 'gpt-4o', messages: [{ role: 'user', content: 'Hello' }], stream: true }) for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content || '') } // Tracking fires automatically once the stream ends
Both messages.create(stream=True) and the messages.stream() helper are supported.
# Option 1 — create(stream=True) stream = client.messages.create( model='claude-sonnet-4-6', max_tokens=1024, messages=[{'role': 'user', 'content': 'Hello'}], stream=True ) for event in stream: if event.type == 'content_block_delta': print(event.delta.text, end='', flush=True) # Option 2 — the .stream() helper (context manager) with client.messages.stream( model='claude-sonnet-4-6', max_tokens=1024, messages=[{'role': 'user', 'content': 'Hello'}] ) as stream: for text in stream.text_stream: print(text, end='', flush=True) # Tracking fires from the final message usage
stream = model.generate_content( 'Hello', stream=True ) for chunk in stream: print(chunk.text, end='', flush=True) # Tracking reads usage_metadata from the final chunk
Both chat.complete() and chat.stream() are supported. Pass stream() directly — Tokoscope wraps it automatically.
// Non-streaming const result = await client.chat.complete({ model: 'mistral-large-latest', messages: [{ role: 'user', content: 'Hello' }] }) // Streaming const stream = await client.chat.stream({ model: 'mistral-large-latest', messages: [{ role: 'user', content: 'Hello' }] }) for await (const chunk of stream) { process.stdout.write(chunk.data?.choices[0]?.delta?.content || '') } // Tracking fires automatically once the stream ends
Set a monthly spend threshold in Settings. When your spend crosses the threshold, Tokoscope fires an email alert and — if configured — a webhook POST to any HTTPS endpoint. Alerts fire once per calendar month.
https://hooks.slack.com/services/...)Tokoscope automatically detects Slack URLs and sends a formatted block message with spend, threshold, provider, and a link to your dashboard.
Any HTTPS URL works. Tokoscope sends a POST request with a JSON payload when your budget threshold is crossed:
{
"event": "budget_alert",
"userId": "usr_...",
"email": "you@example.com",
"budgetThreshold": 10,
"monthlySpend": 10.0142,
"triggeredAt": "2026-07-14T12:00:00.000Z",
"provider": "openai",
"model": "gpt-4o-mini"
}
Use the Send test button in Settings to fire a test payload with "test": true immediately, without waiting for your budget threshold to be crossed. The test payload uses your configured threshold value with a spend $0.01 above it.
| Option | Type | Required | Description |
|---|---|---|---|
| apiKey | string | Yes | Your Tokoscope API key from Settings |
| userId | string | No | End-user ID for per-user attribution |
Python uses snake_case: api_key and user_id.
| Provider | Model | Input (per 1K tokens) | Output (per 1K tokens) |
|---|---|---|---|
| openai | gpt-4o | $0.005 | $0.015 |
| openai | gpt-4o-mini | $0.00015 | $0.0006 |
| openai | gpt-4-turbo | $0.01 | $0.03 |
| anthropic | claude-opus-4-6 | $0.015 | $0.075 |
| anthropic | claude-sonnet-4-6 | $0.003 | $0.015 |
| anthropic | claude-haiku-4-5 | $0.00025 | $0.00125 |
| gemini | gemini-2.5-flash | $0.0001 | $0.0004 |
| gemini | gemini-2.5-pro | $0.00125 | $0.01 |
| gemini | gemini-1.5-flash | $0.000075 | $0.0003 |
| gemini | gemini-1.5-pro | $0.00125 | $0.005 |
The Tokoscope VS Code extension lets you see token counts, waste scores, and cost estimates for any LLM prompt directly in your editor — without leaving VS Code.
# 1. Open Command Palette Cmd+Shift+P (Mac) / Ctrl+Shift+P (Windows) # 2. Run Tokoscope: Set API Key # 3. Paste your key from app.tokoscope.com/settings ts_live_...
Tokoscope is available as a VS Code extension. See token counts, waste scores, and cost estimates for any prompt or file — without leaving your editor.
Tokoscope in the VS Code Extensions panel, or install from the marketplace:1. Cmd+Shift+P → Tokoscope: Set API Key 2. Enter your key from app.tokoscope.com/settings 3. Done — token counts appear in the status bar
| Command | Description |
|---|---|
| Tokoscope: Analyze Current File | Full file analysis with waste score and suggestions |
| Tokoscope: Analyze Selected Text | Analyze highlighted text only |
| Tokoscope: Set API Key | Save your Tokoscope API key |
| Tokoscope: Open Dashboard | Open app.tokoscope.com/dashboard |
chat.complete(), chat.stream(), chat.complete_async(), and chat.stream_async(). Full token tracking and non-streaming cache support.create(stream=True) and the .stream() context manager. Gemini supports generate_content(stream=True).