LLM Token Tracker is an open-source tool for tracking OpenAI, Claude, and Gemini API token usage and costs, supports MCP (Model Context Protocol), and aims to pass accurate API costs on to end users.
Purpose
It is used to measure and manage the token consumption and fees generated when calling AI APIs, helping developers understand the actual cost per user or per session.
Main capabilities
- Simple integration: wrap the API client with one line of code.
- Automatic tracking: no manual token counting required.
- Accurate billing: built-in latest pricing for all 2025 models.
- Multiple providers: supports OpenAI, Claude, Gemini.
- User management: track usage by user/session.
- Currency support: US dollars (USD) and South Korean won (KRW).
- MCP server: can be used directly in Claude Desktop.
- Intuitive session tracking: real-time usage and progress bar display.
- File persistence: session data remains after server restart, automatically saved to ~/.llm-token-tracker/sessions.json, effective for both npm and local installations, with no configuration required.
- Real-time exchange rates: automatically converts US dollars to South Korean won, using exchangerate-api.com, with 24-hour caching and automatic background updates.
How to use
Use as a library
Wrap the real OpenAI/Anthropic API client with one line of code to enable automatic tracking. See examples/basic-usage.js in the repository for example run commands.
Use as an MCP server
Add the configuration to the Claude Desktop settings file (~/Library/Application Support/Claude/claude_desktop_config.json). After adding it, you can perform the following actions in Claude:
- "Calculate current session usage": view current session usage.
- "Calculate current conversation cost": get the cost breakdown including input/output tokens.
- "Track my API usage".
- "Compare costs between GPT-4 and Claude".
- "Show my total spending today".
Available tools
- get_current_session (recommended): get current session usage, returning used/remaining tokens, input/output breakdown, cost, and progress bar; the default user_id is current-session, the default budget is 190,000 tokens, suitable for real-time conversation tracking.
- track_usage: track the token usage of one AI API call, with parameters provider, model, input_tokens, output_tokens, user_id.
- get_usage: get a usage summary for a specified user or all users.
- compare_costs: compare costs across different models.
- clear_usage: clear a user's usage data.
- get_exchange_rate: view the current exchange rate.
API reference
- new TokenTracker(config): config.currency is 'USD' or 'KRW' (default 'USD'); config.webhookUrl is an optional usage notification webhook.
- tracker.wrap(client): wrap an OpenAI or Anthropic client for automatic tracking.
- tracker.forUser(userId): create a tracking instance for the specified user.
- tracker.startTracking(userId?, sessionId?): start manually tracking a session, returning a tracking ID.
- tracker.endTracking(trackingId, usage): end tracking and record usage.
- tracker.getUserUsage(userId): get the total usage for a user.
- tracker.getAllUsersUsage(): get a usage summary for all users.
Supported models and pricing
The repository lists pricing information for Anthropic (2025) and Google Gemini (2025), with prices per 1,000 tokens. The Batch API offers a 50% discount, and prompt caching can reduce costs by up to 90%. The specific model pricing table is not provided in the materials in text form.
Use cases
Suitable for developers who need transparent AI API billing, especially for scenarios involving calculating costs per user or per session, comparing spending across different models, and viewing usage and budget progress in real time in Claude Desktop.
Limitations
The materials do not provide installation commands, the full list of supported models, the specific values in the pricing table, the scope of platform compatibility, or details about paid or open-source licensing. These facts are not currently provided.