SuperAPI AI Directory

llm-usage-mcp

Local LLM API cost tracking for Anthropic, OpenAI, Qwen and DeepSeek: SQLite usage ledger, spend queries, provider comparison and CNY to USD conversion.

Open website

About this tool

Purpose

llm-usage-mcp is used to track the API costs incurred by calling multiple LLM providers (Anthropic, OpenAI, DeepSeek, Qwen) in local development. It solves the problems of scattered multi-platform billing, inconsistent currencies, and hard-to-understand cached token discounts, letting developers view all call costs in one local place. This tool is a cost meter, not a router; it does not modify or intercept your API calls, and can coexist with routers or model leaderboard tools.

Main capabilities

  • Multi-provider support: Anthropic, OpenAI, DeepSeek, Qwen, all supporting streaming and non-streaming calls; DeepSeek and Qwen use the same capture path as Anthropic/OpenAI.
  • Local storage: all call records are written to ~/.llm-usage/usage.db (SQLite), including token counts, costs, latency, and request_id for idempotency.
  • Two query methods: ask a coding agent in natural language through the MCP server, or query directly using CLI commands.
  • MCP tools: seven tools exposed via stdio, including query_spend, usage_summary, etc., excluding failed/partial stream records by default.
  • CLI commands: eight subcommands, such as llm-usage spend (break down this week's spending by provider), llm-usage compare (compare the cost of each model by n input/m output calls), llm-usage recommend (recommend the cheapest model based on budget), llm-usage status (show database, proxy, provider, pricing status), llm-usage config (show each provider's configuration), llm-usage catalog (browse model rates).
  • Supports --json output, --color color control, --provider/--model filter flags, and --install-completion to install shell completion.
  • Pricing data comes from a trimmed snapshot of the LiteLLM pricing JSON, refreshed weekly by a GitHub Action; missing models can be supplemented locally via pricing_overrides.json.
  • The proxy binds to the loopback address 127.0.0.1:5525, the API key is stored on the proxy side, and the client does not need to hold the key.

How to use

  1. Installation: Install via PyPI using uv or pipx to get three console scripts: llm-usage (CLI), llm-usage-mcp (stdio MCP server), llm-usage-proxy (compatibility alias). Or clone and sync from source.
  2. Configure API keys: Only set keys for the providers you actually use; provider routes missing a key return 503 configuration_error. Configuration is done through environment variables or a .env file; see docs/configuration.md.
  3. Start the capture proxy: Run the proxy, which only listens on the local loopback address.
  4. Point the coding agent at the proxy: Set the corresponding *_BASE_URL environment variable for each provider. For example, start Claude Code through the proxy.
  5. Confirm capture: After making a call through the proxy, check whether there is a record in ~/.llm-usage/usage.db.
  6. Query spending: Register the MCP server (e.g. claude mcp add llm-usage -- llm-usage-mcp), then ask questions in natural language during the session; or run CLI commands directly in the terminal.

Use cases

  • Individuals or teams developing with multiple LLM providers who want a unified view of API spending.
  • Need to summarize spending by week, month, or year period (UTC calendar boundaries), grouped by provider or model.
  • Need to compare the cost of a specific input/output token volume across different providers before choosing a model.
  • Need RMB to USD exchange rate conversion to understand billing from Chinese model providers.
  • Privacy-focused, and do not want data to leave the local machine or sign up for a SaaS service.

Limitations

  • Currently only supports four providers: Anthropic, OpenAI, DeepSeek, and Qwen; Gemini, Bedrock, Moonshot, Zhipu GLM, MiniMax, etc. are planned.
  • The v1 recommend command ranks only by cost; the --task parameter does not affect the selection.
  • Prices are periodic snapshots of the LiteLLM pricing JSON and may not be real-time prices.
  • The tool does not modify or route calls; it only records calls made through the proxy.
  • The Dockerfile is only used for automated MCP registration verification; local use is recommended with uvx llm-usage-mcp.
  • Other feature details or the future roadmap are not fully provided in the materials.