Documentation

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.

Quick start

The fastest way to get started:

app.js
// 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.

Installation

JavaScript / Node.js

bash
npm install tokoscope
# or
yarn add tokoscope

Python

bash
pip install tokoscope
Requirements: Node.js 18+ or Python 3.8+. No additional dependencies required.

API key

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:

.env
TOKOSCOPE_API_KEY=ts_live_...
app.js
const client = wrap(new OpenAI(), {
  apiKey: process.env.TOKOSCOPE_API_KEY
})

OpenAI

openai.js
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' }]
})

Anthropic

anthropic.js
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' }]
})

Gemini

gemini.js
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')

Per-user tracking

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.

app.js
const client = wrap(new OpenAI(), {
  apiKey: process.env.TOKOSCOPE_API_KEY,
  userId: currentUser.id // any string identifier
})

Caching

Tokoscope automatically caches responses using two layers:

Cache TTL is 7 days. Clear cache anytime from Settings.

Cache hit log: When a cache hit fires, Tokoscope logs it to the console:
⚡ Tokoscope cache hit [semantic (89.3% match)] — saved 93 tokens ($0.000049)

Prompt compression

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

Streaming responses are supported for OpenAI. Set stream: true (or stream=True in Python) as usual — Tokoscope passes every chunk through unchanged and tracks token usage once the stream completes.

stream.js
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
Note: Streaming responses skip the cache lookup and are not cached in this version. Semantic and exact match caching only apply to non-streaming calls. Anthropic and Gemini streaming support is coming soon.

Budget alerts

Set a monthly spend threshold in Settings. When your spend crosses the threshold, Tokoscope sends an email alert automatically. Alerts fire once per calendar month.

wrap() options

OptionTypeRequiredDescription
apiKeystringYesYour Tokoscope API key from Settings
userIdstringNoEnd-user ID for per-user attribution

Python uses snake_case: api_key and user_id.

Supported models & pricing

ProviderModelInput (per 1K tokens)Output (per 1K tokens)
openaigpt-4o$0.005$0.015
openaigpt-4o-mini$0.00015$0.0006
openaigpt-4-turbo$0.01$0.03
anthropicclaude-opus-4-6$0.015$0.075
anthropicclaude-sonnet-4-6$0.003$0.015
anthropicclaude-haiku-4-5$0.00025$0.00125
geminigemini-2.5-flash$0.0001$0.0004
geminigemini-2.5-pro$0.00125$0.01
geminigemini-1.5-flash$0.000075$0.0003
geminigemini-1.5-pro$0.00125$0.005

VS Code Extension

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.

Install from VS Code Marketplace
marketplace.visualstudio.com

Features

Setup

Command Palette
# 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_...
Tip: After installing, the token counter appears in the status bar (bottom right) whenever you have a file open. Click it to analyze the current file.

VS Code extension

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.

Install: Search Tokoscope in the VS Code Extensions panel, or install from the marketplace:

VS Code Marketplace →  ·  Open VSX (Cursor, Windsurf, VSCodium) →

What it does

Setup

Command Palette
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

Commands

CommandDescription
Tokoscope: Analyze Current FileFull file analysis with waste score and suggestions
Tokoscope: Analyze Selected TextAnalyze highlighted text only
Tokoscope: Set API KeySave your Tokoscope API key
Tokoscope: Open DashboardOpen app.tokoscope.com/dashboard

Changelog