TokenLens

Typed model registry and token/cost utilities for context budgeting in AI apps

Library
npm
v1.3.1
262stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
35/100Needs Attention
Development Activity28
Maintenance0
Community36
Maturity36
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
65/100Good
Architecture68
Code Quality58
Innovation72
Learning Curve62

TokenLens is a typed registry of LLM model metadata — context window sizes, pricing, and provider aliases — paired with utilities that answer the questions AI apps constantly need to ask at runtime: does this input fit the model’s context window, what will this call cost, and how much budget remains for the next turn. It normalizes usage objects across providers and SDKs (including native Vercel AI SDK usage fields) into a consistent shape.

The registry can be fetched live from the community-maintained models.dev dataset or used as a static, bundled snapshot, and model IDs can be given in several flexible forms (provider/model, provider:id, or a bare model name) with automatic normalization. It’s framework-agnostic but designed to slot in naturally alongside the Vercel AI SDK.

What You Get

  • getModels()/fetchModels() for a static or live-fetched catalog of provider/model metadata sourced from models.dev
  • getContext(modelId, providers) returning input/output/total context-window caps for a given model
  • getTokenCosts(modelId, usage, providers) returning a USD cost breakdown (input, output, reasoning, cache read/write)
  • getUsage() combining context and cost into one call for a model + usage object
  • Flexible model ID resolution accepting provider/model, provider:id, or a bare model name, with automatic version-dot normalization
  • listModels() for filtering the catalog by provider and status (e.g. stable models only)

Common Use Cases

  • Checking whether a prompt plus expected completion will fit inside a target model’s context window before sending it
  • Estimating the USD cost of an LLM call from token usage returned by a provider or the Vercel AI SDK
  • Deciding when to compact or summarize a long conversation before it exceeds context limits
  • Computing remaining token budget for the next turn in a multi-turn agent conversation
  • Normalizing usage/cost reporting across multiple LLM providers in one dashboard or logging pipeline

Under The Hood

Architecture: The published tokenlens package (in the packages/tokenlens workspace of a Turborepo monorepo) exposes registry.ts for provider/model catalog access, context.ts for context-window budget calculations, async.ts/source.ts for fetching the live models.dev dataset, and conversation.ts for higher-level conversation-usage utilities; models/ holds the bundled static snapshot used when live fetching isn’t wanted or available. Sibling workspace packages (core, models, fetch, helpers, provider-tests) split out lower-level pieces the main package composes.

Tech Stack: TypeScript throughout (97% of the codebase), built with a pnpm + Turborepo monorepo setup, Biome for linting/formatting, and Lefthook for git hooks. The published package ships as ESM (type: module) with per-provider subpath exports (tokenlens/providers/*).

Code Quality: Test coverage is comparatively light for a young project — 4 .test.ts files at the time of review — and the README documents an in-progress API consolidation: a large set of earlier helpers (normalizeUsage, estimateCost, shouldCompact, and others) are explicitly marked deprecated in favor of three focused functions (getContext, getTokenCosts, getUsage), signaling active API stabilization rather than a settled surface.

API Design: The current focused API (getContext/getTokenCosts/getUsage) is deliberately narrow and composable, each taking a model ID, usage object, and provider catalog and returning a small, typed result object — a clear improvement in ergonomics over the larger, now-deprecated helper set the project is migrating away from.

Used by 12 apps in this directory

TypeScript
59%
Other

agenta

Developer Tools · Devops · AI Development

4,489

The open-source LLMOps platform unifying prompt engineering, evaluation, and observability for teams building reliable LLM applications.

View details
91
Repo Health
77
Technical
67
Dependency
Built with
TypeScript59%
Python39%
Updated today
TypeScript
49%
AGPL 3.0

BrowserOS

Browser · AI Assistants

13,248

The open-source agentic Chromium browser with native AI agents, MCP server, and visual workflow automation — your data never leaves your machine.

View details
87
Repo Health
82
Technical
69
Dependency
Built with
TypeScript49%
Rust22%
Python16%
Updated today
TypeScript
97%
Apache 2.0

Cline

AI Code Assistants

66,453

An open-source AI coding agent that lives in your editor and terminal — reads and edits your codebase, runs commands, browses the web, and requires human approval for every action by default.

View details
90
Repo Health
74
Technical
67
Dependency
Built with
TypeScript97%
Updated today
TypeScript
95%
Other

LLM Gateway

AI Development · Devops

1,555

One API endpoint for 25+ LLM providers — route, track costs, enforce compliance, and switch models without changing your code.

View details
85
Repo Health
80
Technical
72
Dependency
Built with
TypeScript95%
Updated today
JavaScript
98%
Other

Markdrop

Note Taking

358

Visual drag-and-drop markdown editor with GitHub-specific blocks, cloud sync, and offline PWA support

View details
38
Repo Health
57
Technical
69
Dependency
Built with
JavaScript98%
Updated 4 months ago
TypeScript
98%
Other

Novu

Developer Tools

39,615

Open-source communication infrastructure that connects your products and AI agents to every channel your users live on — Inbox, Email, SMS, Push, Chat, and more.

View details
93
Repo Health
80
Technical
65
Dependency
Built with
TypeScript98%
Updated today
TypeScript
99%
Apache 2.0

Onlook

Design Tools · AI Design Tools

26,512

An open-source, AI-first visual editor that lets designers and developers build, style, and deploy React apps directly in code — no handoff required.

View details
66
Repo Health
80
Technical
68
Dependency
Built with
TypeScript99%
Updated 4 weeks ago
TypeScript
99%
Other

Papermark

Digital Signiture · File Storage

8,952

Open-source DocSend alternative with page-by-page analytics, secure data rooms, and custom domains for document sharing.

View details
86
Repo Health
63
Technical
68
Dependency
Built with
TypeScript99%
Updated yesterday
TypeScript
98%
Apache 2.0

rowboat

AI Assistants · AI Development

17,323

Build, test, and deploy multi-agent AI workflows with a visual editor, RAG data sources, MCP tool integration, and a production-ready REST API.

View details
85
Repo Health
72
Technical
65
Dependency
Built with
TypeScript98%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search