tokenlens weekly downloads statistics
A lightweight registry of LLM model information, like name and context sizes, for building AI-powered apps.
tokenlens has 926,216 recorded weekly downloads on npm, a decrease of 15.9% over the past 30 days, ranking #303 of 3,247 tracked listings.
About tokenlens
TokenLens
Typed model metadata and context/cost utilities that help AI apps answer: Does this fit? What will it cost? Should we compact now? How much budget is left for the next turn?
Works great with the Vercel AI SDK out of the box, and remains SDK‑agnostic.

Highlights
- Canonical model registry with alias resolution and minimal metadata you can trust.
- Strong TypeScript surface:
ModelIdautocomplete and safe helpers. - Usage normalization across providers and SDKs (incl. Vercel AI SDK fields).
- Context budgeting: remaining tokens, percent used, and next-turn budget.
- Compaction helpers: when to compact and how many tokens to remove.
- Cost estimation: fast, rough USD costs using source‑linked pricing when available.
- Conversation utilities: sum usage, estimate conversation cost, measure context rot.
Install
- npm:
npm i tokenlens - pnpm:
pnpm add tokenlens - yarn:
yarn add tokenlens
Quick Start
import {
type ModelId,
modelMeta,
percentOfContextUsed,
tokensRemaining,
costFromUsage,
} from 'tokenlens';
const id: ModelId = 'openai:gpt-4.1';
// Works with provider usage or Vercel AI SDK usage
const usage = { prompt_tokens: 3200, completion_tokens: 400 };
const meta = modelMeta(id);
const used = percentOfContextUsed({ id, usage, reserveOutput: 256 });
const remaining = tokensRemaining({ id, usage, reserveOutput: 256 });
const costUSD = costFromUsage({ id, usage });
console.log({ meta, used, remaining, costUSD });
Core Helpers
- Registry:
resolveModel,listModels,MODEL_IDS,isModelId,assertModelId - Usage:
normalizeUsage,breakdownTokens,consumedTokens - Context:
getContextWindow,remainingContext,percentRemaining,fitsContext,pickModelFor - Cost:
estimateCost - Compaction:
shouldCompact,contextHealth,tokensToCompact - Conversation:
sumUsage,estimateConversationCost,computeContextRot,nextTurnBudget - Sugar:
modelMeta,percentOfContextUsed,tokensRemaining,costFromUsage
Provider‑Agnostic Usage
import { normalizeUsage, breakdownTokens } from 'tokenlens';
// Works with many shapes, including Vercel AI SDK fields
const u1 = normalizeUsage({ prompt_tokens: 1000, completion_tokens: 150 });
const u2 = normalizeUsage({ inputTokens: 900, outputTokens: 200, totalTokens: 1100 });
const b = breakdownTokens({ inputTokens: 900, cachedInputTokens: 300, reasoningTokens: 120 });
Async Fetch (models.dev)
import {
fetchModels,
FetchModelsError,
type ModelCatalog,
type ProviderInfo,
type ProviderModel,
} from 'tokenlens';
// 1) Fetch the full catalog (Node 18+ or modern browsers with global fetch)
const catalog: ModelCatalog = await fetchModels();
// 2) Fetch by provider key (e.g. 'openai', 'anthropic', 'deepseek')
const openai: ProviderInfo | undefined = await fetchModels({ provider: 'openai' });
// 3) Fetch a specific model within a provider
const gpto: ProviderModel | undefined = await fetchModels({ provider: 'openai', model: 'gpt-4o' });
// 4) Search for a model across providers when provider is omitted
const matches: Array<{ provider: string; model: ProviderModel }> = await fetchModels({ model: 'gpt-4.1' });
// 5) Error handling with typed error codes
try {
await fetchModels();
} catch (err) {
if (err instanceof FetchModelsError) {
// err.code is one of: 'UNAVAILABLE' | 'NETWORK' | 'HTTP' | 'PARSE'
console.error('Fetch failed:', err.code, err.status, err.message);
} else {
throw err;
}
}
// 6) Provide a custom fetch (for Node < 18 or custom runtimes)
// import fetch from 'cross-fetch' or 'undici'
// const catalog = await fetchModels({ fetch });
Picking Model Metadata
import { getModels, getModelMeta } from 'tokenlens';
// Build a static catalog (or use fetchModels() dynamically)
const providers = getModels();
// Provider info
const openai = getModelMeta({ providers, provider: 'openai' });
// Single model
const gpto = getModelMeta({ providers, provider: 'openai', model: 'gpt-4o' });
// Multiple models
const picks = getModelMeta({ providers, provider: 'openai', models: ['gpt-4o', 'o3-mini'] });
// Providerless id
const viaId = getModelMeta({ providers, id: 'openai:gpt-4o' }); // or 'openai/gpt-4o'
Context Budgeting & Compaction
import { remainingContext, shouldCompact, tokensToCompact, contextHealth } from 'tokenlens';
const rc = remainingContext({ modelId: 'anthropic:claude-3-5-sonnet-20240620', usage: u1, reserveOutput: 256 });
if (shouldCompact({ modelId: 'anthropic:claude-3-5-sonnet-20240620', usage: u1 })) {
const n = tokensToCompact({ modelId: 'anthropic:claude-3-5-sonnet-20240620', usage: u1 });
// summarize oldest messages by ~n tokens
}
const badge = contextHealth({ modelId: 'openai:gpt-4.1', usage: u2 }); // { status: 'ok'|'warn'|'compact' }
Advanced
- Caps strategy:
remainingContextsupportsstrategy: 'provider-default' | 'combined' | 'input-only'.provider-default(default): preferscombinedMaxwhen available; otherwise usesinputMax.combined: always usescombinedMax(falls back toinputMaxif missing).input-only: uses onlyinputMaxfor remaining/percent calculations.
- Defaults:
shouldCompactdefaults tothreshold: 0.85;contextHealthdefaults towarnAt: 0.75,compactAt: 0.85.
Conversation Utilities
import { sumUsage, estimateConversationCost, computeContextRot, nextTurnBudget } from 'tokenlens';…
Description from the npm listing.
- ai
- llm
- ai models
- model registry
- context window
- token usage
- tokens
- pricing
- cost estimation
- usage normalization
- prompt cache
- vercel ai
- vercel ai gateway
- ai-sdk
- openai
- anthropic
- mistral
- cohere
- xai
README badge
Show your rank in a README or on your website. The badge updates automatically.
Charts
Images: 30d · 1y · all time · 1600×900 dark
Adoption over time
7/30/90-day growth
Ranking history
Listing placement
Listing placement
Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.
Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.
Recent observations
Full history (592)Similar npm AI SDKs plugins
All 20 tokenlens alternativesData source
Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.
Listing: https://www.npmjs.com/package/tokenlens. First seen Oct 16, 2026; last successful collection Dec 6, 2026. See the methodology.