Quick Start with TokenLens
mainTokenLens provides utilities to manage model metadata, context limits, and cost estimation. You can fetch model providers and then use helpers to calculate context caps, costs, or combined usage data.
Note that ID normalization is automatic: you can use provider/model, provider:id, or just the model name. Version dots are automatically normalized to dashes (e.g., claude-3.5-haiku becomes claude-3-5-haiku).
import { fetchModels } from 'tokenlens';
import { getContext, getTokenCosts, getUsage } from '@tokenlens/helpers';
// 1) Get providers
const openai = await fetchModels('openai');
// 2) Define model and usage
const modelId = 'openai/gpt-4o-mini';
const usage = { prompt_tokens: 3200, completion_tokens: 400 };
// Context caps
const { maxInput, maxOutput, maxTotal } = getContext(modelId, openai);
// Cost breakdown
const {
inputUSD,
outputUSD,
totalUSD
} = getTokenCosts(modelId, usage, openai);
// Or both together
const usageData = getUsage(modelId, usage, openai);
console.log({ maxInput, maxOutput, maxTotal, inputUSD, outputUSD, totalUSD, usageData });