Skip to content
PluginStats

tokenlens weekly downloads statistics

By xn1cklas · npm · AI SDKs

A lightweight registry of LLM model information, like name and context sizes, for building AI-powered apps.

View on npm Fresh · Dec 6, 2026

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.

Weekly downloads
926,216
Official API · Dec 5, 2026
7-day growth
+5.3%
+46.3K weekly downloads
30-day growth
-15.9%
-175.4K weekly downloads
90-day growth
+37.7%
+253.5K weekly downloads
Rank
#303
▼ 9 in 7 days

About tokenlens

TokenLens

npm version npm downloads License: MIT TypeScript

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.

TokenLens overview

Highlights

  • Canonical model registry with alias resolution and minimal metadata you can trust.
  • Strong TypeScript surface: ModelId autocomplete 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: remainingContext supports strategy: 'provider-default' | 'combined' | 'input-only'.
    • provider-default (default): prefers combinedMax when available; otherwise uses inputMax.
    • combined: always uses combinedMax (falls back to inputMax if missing).
    • input-only: uses only inputMax for remaining/percent calculations.
  • Defaults: shouldCompact defaults to threshold: 0.85; contextHealth defaults to warnAt: 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
  • google
  • 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

tokenlens weekly downloads on npm, last 90 days: 926,216 weekly downloads as of Dec 5, 2026, +37.7% over 90 days.tokenlensWeekly downloads on npm · Last 90 days926,216downloads / week+37.7% over 90 days0200K400K600K800K1M1.2MSep 6Sep 21Oct 6Oct 21Nov 5Nov 20Dec 5downloads / weekobservedarchived (Internet Archive)no observationsSep 7, 2026 – Dec 5, 2026 · 90 observations · Updated Dec …pluginstats.com
tokenlens weekly downloads on npm, last 90 days: 926,216 weekly downloads as of Dec 5, 2026, +37.7% over 90 days.

7/30/90-day growth

tokenlens weekly downloads growth on npm: +5.3% over 7 days, -15.9% over 30 days, +37.7% over 90 days.tokenlensWeekly downloads growth on npm926,216downloads / week now7-day growth+46,347 weekly downloads+5.3%30-day growth-175,428 weekly downloads-15.9%90-day growth+253,457 weekly downloads+37.7%Growth vs. nearest observation to each baseline date · Updated Dec 5, 2026pluginstats.com
tokenlens weekly downloads growth on npm: +5.3% over 7 days, -15.9% over 30 days, +37.7% over 90 days.

Ranking history

tokenlens npm ranking history: currently #303 (by weekly downloads).tokenlensnpm ranking · by weekly downloads · Last 90 days#303current rank#50#100#150#200#250#300#350Sep 7Sep 22Oct 7Oct 22Nov 6Nov 21Dec 6rankOct 17, 2026 – Dec 6, 2026 · 45 observations · Updated Dec 5, 2026pluginstats.com
tokenlens npm ranking history: currently #303 (by weekly downloads).

Listing placement

All npm3,247 listings · 163 pages · 1,084 shown · page 16, #3 (overall #303)
All npm: every listing in weekly downloads order

Listing placement

AI SDKs378 listings · 19 pages · page 1, #13 (overall #13)
AI SDKs: every listing in weekly downloads order

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)
Recent weekly downloads observations for tokenlens
Date (UTC)Weekly downloadsChange vs. previous
926,216+25.3K
900,869+29.8K
871,077+24.9K
846,189+12.2K
833,961-4.6K
838,553-21.1K
859,630-20.2K
879,869-24.2K
904,026-37.6K
941,642-71.5K
1,013,185-30.8K
1,043,996-16.5K
1,060,508+2.2K
1,058,318—

Similar npm AI SDKs plugins

All 20 tokenlens alternatives

Data 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.