
LLM Usage
io.github.zhaoyue722由 GitHub 帳號 zhaoyue722 發布v0.1.3更新於 Oct 24, 2026
Local-first, multi-provider tool that captures LLM API spend and exposes it to coding agents via MCP
概覽
本地優先的 LLM 花費追蹤器,把 API 用量記錄到 SQLite,讓助理查詢花費、比較供應商並推薦更便宜的模型。
- 可以做什麼
- 查詢已記錄花費:依供應商、模型、專案、標籤或日期彙總,並提供今日、本週、本月、本年的概況
- 比較供應商:依指定的輸入/輸出 token 工作量,為所有已定價模型排序
- 推薦模型:在指定預算內挑出最便宜的已定價模型並列出備選
- 檢視目錄:列出供應商、其模型與 OpenAI 相容標記,並讀取內建價格快照
- 手動記錄用量:在未使用擷取代理時手動登錄一次呼叫
- 適用情境
- 適合同時呼叫多家 LLM 供應商、希望在同一處看清花費,或想讓助理用自然語言回答花費問題並建議最便宜模型的情境。它只是計量器而非路由器,只回報花費,不會改變你的呼叫。
- 執行需求
- 以 stdio 方式在本機執行,透過 uv 或 pipx 從 PyPI 安裝(Python)。要擷取呼叫需另外執行本機擷取代理(僅回環位址,連接埠 5525),並以 base URL 變數讓用戶端指向它。擷取需要對應供應商的 API 金鑰,例如 ANTHROPIC_API_KEY、OPENAI_API_KEY、DEEPSEEK_API_KEY 或 DASHSCOPE_API_KEY;資料存放在本機 SQLite 檔案。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 LLM Usage,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
llm-usage-mcp
LLM Usage & Cost Tracker — your local-first spend watchdog
[CI] [License: MIT] [Python 3.13+] [Glama score]
English | 中文
Stop treating your LLM API bills like a scary horror movie you only look at through your fingers at the end of the month. Know what your LLM calls actually cost — across every provider, in one place, on your own machine. Ask your coding agent (MCP) or type a command (CLI).
It's a cost meter, not a router: it tells you what you spent and which provider fits a workload — it never changes your calls. Pairs happily alongside a router or a model-leaderboard tool.
[Claude Code answering "how much did I spend?" via llm-usage]
Or straight from the terminal — your week's spend, broken down by provider, and a cross-provider cost comparison before you commit to a model:
[llm-usage CLI: weekly spend by provider and a cross-provider cost comparison]
Why you'd want this
You're calling LLMs from a handful of providers — Claude, GPT, plus Chinese models like Qwen and DeepSeek. Each one bills in its own dashboard, in its own currency, with its own rules for what a "cached token" costs. So the simplest possible question — how much am I spending, and on what? — turns into four browser logins, looking up exchange rates for RMB to USD, and trying to decipher what a "cached context token discount" actually means in midnight math. Most people just cross their fingers and let the bill be a surprise at the end of the month.
llm-usage-mcp captures every call you make into one local store, costs it correctly per provider at the moment it happens, and hands the answer back two ways:
- Ask your coding agent. It's an MCP server, so Claude Code, Cursor, or any MCP client can answer "how much did I spend on Claude this week?" or "which provider is cheapest for a 10k-in / 2k-out call?" in plain English.
- Or type a command. It's also a CLI —
llm-usage spend,llm-usage compare,llm-usage recommend— for when you'd rather not round-trip through an agent.
And it stays out of your way:
- Local-first. No SaaS, no signup, no telemetry. Just a SQLite file at
~/.llm-usage/usage.db. Privacy is a feature, not a setting. - Multi-provider, Chinese models included. Anthropic, OpenAI, DeepSeek, Qwen — streaming and non-streaming for all four. DeepSeek and Qwen run the same capture path as Anthropic and OpenAI, not a bolted-on afterthought. More providers (Gemini, Bedrock, Moonshot, …) are on the way.
Quickstart
Two minutes from git clone to your first captured call. This part is about capture — getting calls recorded. Reading the data back comes next.
1. Install
Install from PyPI with uv (or pipx) — this puts the three console scripts on your PATH:
Prefer to hack on it? Clone and sync from source instead:
Either way you get three console scripts:
llm-usage— the multi-command CLI. See From the command line (CLI) below.llm-usage-mcp— the stdio MCP server.llm-usage-proxy— a back-compat alias; identical tollm-usage proxy.
The Quickstart below uses
uv run …(the from-source workflow). If you installed from PyPI, the scripts are already on yourPATH— drop theuv runprefix, and register the MCP server withclaude mcp add llm-usage -- llm-usage-mcp.
2. Set at least one API key
You only need a key for the provider(s) you actually use; the proxy starts regardless and per-route requests return 503 configuration_error for any provider whose key is missing.
Full env-var reference: docs/configuration.md (or copy .env.example to .env and fill in).
3. Run the capture proxy
It binds loopback-only (127.0.0.1:5525) — never reachable from the network. The proxy holds your API keys server-side; clients never need them.
4. Point your coding agent at the proxy
The proxy exposes one route per provider. Set the matching *_BASE_URL env var on the client side:
Example — launch Claude Code with calls routed through the proxy:
5. Confirm it's capturing
Make a call through your agent (or any client pointed at the proxy), then check it landed:
Every call lands in ~/.llm-usage/usage.db with tokens, cost, latency, and a request_id for idempotency — and shows up in that headline. That's the whole loop: capture on one side, answers on the other.
Querying your spend
Once calls are being captured, you read them back two ways. Same data, same numbers — pick whichever fits the moment.
Ask your coding agent (MCP)
Register the MCP server with Claude Code:
Then just ask, in plain English, inside that session:
How much did I spend on Anthropic today? Which provider is cheapest for a 10k-input / 2k-output call?
Claude picks the right tool and reads the numbers back. Seven tools are exposed over stdio; full param/return shapes are in docs/spec.md.
query_spend and usage_summary default to include_failed=false so partial-stream rows don't pollute totals; opt-in via the param.
From the command line (CLI)
The same questions, as a CLI — eight subcommands under one llm-usage console, for when typing is faster than asking your agent.
The examples below assume
llm-usageis on yourPATH— eithersource .venv/bin/activateoruv tool install .. Otherwise, prefix each command withuv run(e.g.uv run llm-usage spend).
Conventions that hold across every command:
--jsonemits the same Pydantic shape the matching MCP tool returns. Pipe straight intojq.--color {auto,always,never}honorsNO_COLORand TTY detection. The palette is a warm, low-contrast dark theme — easy on the eyes at 11pm.- Filter flags (
--provider,--model) are case-insensitive on providers, case-sensitive on models, and repeatable where they act as whitelists. --version/-Vprints the version and exits.--install-completion {bash|zsh|fish|powershell}installs a tab-completion script — one shell restart later, every flag is<Tab>-able.
compare
Rank every priced model by projected cost for an n-input / m-output call. Cheapest first, percent against the cheapest. Default view family-deduplicates rows that share both a model family root and an identical price — so gpt-5-mini and gpt-5-mini-2025-08-07 collapse to one row with ×2. Pass --all to see every catalog row.
[llm-usage compare ranking models by projected cost]
models
Catalog browser. Sibling of compare, but answers "what does this model charge?" rather than "what would my workload cost?". Rates per million tokens, sorted alphabetically by provider by default; switch with --sort input or --sort output to find the cheapest in either axis. Cache rates are hidden until you ask (--cache) because most models don't have them and empty columns waste width.
recommend
Picks one. Filters by --provider, --model, and --budget, then returns the cheapest match plus two runner-ups. The reasoning string explains what it assumed and what got chosen, so you can sanity-check rather than trust blindly.
v1 ranks by cost only. --task is optional and surfaces in the reasoning text; it doesn't drive selection (the tool isn't an LLM and can't interpret free text).
spend
Read the SQLite. The default view is a usage_summary headline — total dollars, top-3 providers, top-3 models, largest single call. Pass --group-by to switch into rollup mode.
Period boundaries are calendar UTC: today = since 00:00 UTC, week = since Monday, month = since the 1st, year = since January 1st. Failed / partial-stream rows are excluded by default; opt in with --include-failed.
[llm-usage spend headline — totals, top providers, largest call]
status
One screen, four sections: Database, Capture proxy, Providers, Pricing. The "is everything actually working?" command. Read-only — running it on a fresh install before you've ever booted the proxy or MCP server prints database not initialized rather than silently creating the file.
providers
Per-provider configuration view. Wider than the status Providers block: adds the wire-format flag (openai-compat: yes/no) and an optional --models expansion that lists every priced model under each provider.
about
The front-door panel: version, author, license, and the project homepage. The human-facing companion to --version — fields are read from the installed package metadata, so they match what PyPI shows.
Supported providers
More on the way. Google Gemini, AWS Bedrock, Moonshot (Kimi), Zhipu GLM, MiniMax, and others are scoped in docs/post_v1_providers.md.
Where prices come from. Pricing is a vendored, trimmed snapshot of LiteLLM's pricing JSON, refreshed weekly by a GitHub Action (refresh-pricing.yml). Models LiteLLM doesn't carry yet are filled in locally via pricing_overrides.json.
Configuration
Everything is env vars (or a .env file at the repo root). Defaults are sane — nothing is required to start the proxy. Full reference: docs/configuration.md. The three you're most likely to touch:
Docker
A minimal Dockerfile is included only for automated MCP registry validation (e.g. Glama), which verifies that the packaged server boots and responds to MCP introspection. The recommended way to run the server is still uvx llm-usage-mcp locally — this is a local-first tool, not a hosted service.
License
MIT.
來源:README.md,提交 f14c870
工具
0版本歷史
1- v0.1.3最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分