ModelCostSaver
Predict the cost of an LLM call before you make it, and pick the cheapest model that still does the job, offline, from your editor.
README
ModelCostSaver
Predict the cost of an LLM call before you make it, and pick the cheapest model that still does the job, offline, from your editor.
ModelCostSaver is a Model Context Protocol server. It gives any AI coding agent or IDE a free, zero-config tool that answers the three questions every agent should ask before an LLM call:
- What will this prompt cost on each candidate model? (
predict_cost,estimate_cost) - Which is the cheapest model that meets the task? (
select_optimal_model) - How do my options compare side by side? (
compare_models)
It is pure pricing-and-routing math over a bundled, dated catalog, so the core needs no API keys and makes no network calls.
Quick start
Run it directly with npx (no install, no keys):
npx -y @workswarm/modelcostsaver
Or write the config for your editor in one command:
npx -y @workswarm/modelcostsaver install --client cursor
Add to Cursor — one click installs it in Cursor. Or drop the block below into ~/.cursor/mcp.json, or run npx -y @workswarm/modelcostsaver install --client cursor.
Listed on the official MCP registry and editor MCP directories as io.github.sachinuppal/modelcostsaver.
The seven tools
| Tool | What it answers |
|---|---|
estimate_cost |
Cost of one call when you already know (or can estimate) the token counts. |
predict_cost |
Forecast cost across a candidate set from a prompt, before the call. Ranked cheapest-first. |
select_optimal_model |
The cheapest model that meets the task tier, capabilities, and budget, with full reasoning. |
compare_models |
A side-by-side cost table for a fixed token shape, with relativeToCheapest. |
list_models / get_pricing |
The pricing catalog, filterable by provider, tier, capability, or max input price. |
optimize_request |
"I plan to call model X, can I do better?" Returns the cheaper option and the savings. |
record_usage |
Append a local usage record (opt-in; off unless MODELCOSTSAVER_LEDGER=on). |
Every cost-bearing result carries catalogVersion and asOf so you can see how fresh the prices are. Every selection carries a reasoning array, never a black-box pick.
Trust: no keys, offline, no telemetry
For a tool that sits in your editor, trust is the whole pitch. ModelCostSaver is:
- No API keys. The core does pricing math, not provider calls. Nothing to leak.
- Offline by default. The core tools return correct answers with no network access. The only outbound request is an opt-in catalog refresh (
MODELCOSTSAVER_REFRESH=on), a single GET of a static JSON, zod-validated before it can replace the bundled catalog, and it always falls back to the bundle on any failure. - No telemetry. Ever. The default is silent and local.
record_usageonly writes when you setMODELCOSTSAVER_LEDGER=on, and only to a JSONL file under your own config dir. - Two dependencies.
@modelcontextprotocol/sdkandzod. Nothing else. Small supply-chain surface, fastnpxcold start. - Apache-2.0. An open-source developer tool published by Workswarm as
@workswarm/modelcostsaver. The shipped bundle contains no proprietary or internal-service code: no internal-framework imports and no internal identifiers, just dependency-free pricing-and-routing math.
stdout carries only JSON-RPC; all logs go to stderr.
Install per IDE
ModelCostSaver speaks stdio MCP, so the entry is the same npx command everywhere. Use install --client <name> to write it idempotently, or paste the block by hand.
Cursor
~/.cursor/mcp.json (global) or .cursor/mcp.json (project):
{ "mcpServers": { "modelcostsaver": { "command": "npx", "args": ["-y", "@workswarm/modelcostsaver"] } } }
npx -y @workswarm/modelcostsaver install --client cursor
Claude Code
claude mcp add modelcostsaver -- npx -y @workswarm/modelcostsaver
or a .mcp.json in the repo root (which install --client claude writes):
{ "mcpServers": { "modelcostsaver": { "command": "npx", "args": ["-y", "@workswarm/modelcostsaver"], "env": { "MODELCOSTSAVER_PROVIDERS": "anthropic" } } } }
Claude clients run Claude for their own inference, so the install seeds MODELCOSTSAVER_PROVIDERS=anthropic as a sensible default for target: self recommendations. Override it per call or with the env var. See Self vs code.
Claude Desktop
Add the same mcpServers block to claude_desktop_config.json.
VS Code / GitHub Copilot
.vscode/mcp.json:
{ "servers": { "modelcostsaver": { "command": "npx", "args": ["-y", "@workswarm/modelcostsaver"], "type": "stdio" } } }
npx -y @workswarm/modelcostsaver install --client vscode
Windsurf
~/.codeium/windsurf/mcp_config.json with the same mcpServers block, or:
npx -y @workswarm/modelcostsaver install --client windsurf
Cline / Zed / Antigravity
Same stdio command/args. Use the matching installer:
npx -y @workswarm/modelcostsaver install --client cline
npx -y @workswarm/modelcostsaver install --client zed
npx -y @workswarm/modelcostsaver install --client antigravity
After adding the server, restart the client and confirm the seven tools appear in the tool list.
Two axes: self vs code
ModelCostSaver advises; it does not route traffic. So every recommendation is filtered to what you can actually act on, along two independent axes.
Axis 1, availability. Recommendations are scoped to a set of allowed providers. The default is derived from the connected client (read from the MCP handshake): a Claude client defaults to anthropic because its own inference is Claude; multi-provider clients (Cursor, VS Code, Windsurf, Cline, Zed, Antigravity) and unknown clients default to all providers. The scope and its source are always echoed in reasoning, and it is overridable: a per-call providers arg, then MODELCOSTSAVER_PROVIDERS, then config, then the client default, then all.
Axis 2, target.
target: 'self'(default): the agent's or your own next inference in this client. The Axis-1 scope applies. In Claude Code this means cross-tier Anthropic moves (Opus to Haiku), which you can act on right now.target: 'code': a model you will call from your own application, where you supply that provider's key. The client scope does not apply, so all in-catalog providers are eligible.
ModelCostSaver is always honest about the gap: if the globally-cheapest model is outside your actionable set, it is surfaced as cheaperIfAvailable with the reason, never silently chosen. For example, a Claude Code target: self summarize call selects claude-haiku-4-5 and notes that a cheaper non-Anthropic model exists if you pass target: code.
How it predicts
- Tokens. Exact counts if you supply them; otherwise a heuristic estimate (
~4 chars/token, tunable viaMODELCOSTSAVER_CHARS_PER_TOKEN). The heuristic is approximate but common-mode across candidates, which is what relative ranking needs. Output tokens come from your explicit value, then the task class cap, then the model cap, then a conservative default. - Cost.
(inTok / 1e6) * inputPerMillion + (outTok / 1e6) * outputPerMillion, in full-precision USD and as integerusdMicros. A prediction is never rounded to cents. - Selection. Resolve the target tier (from an explicit
taskClass, else a transparent keyword/length classifier), filter candidates by tier (degrade up, never below the floor), capabilities, and provider scope, forecast each, drop those over budget intorejected, and pick the cheapest survivor. Every step is recorded inreasoning, and afallbackChainis returned for retry-on-failure.
Configuration
All config is optional. Precedence: tool-call arg, then env var, then modelcostsaver.config.json (cwd, then your user config dir), then the built-in default.
| Key | Env | Default | Purpose |
|---|---|---|---|
| tier overrides | MODELCOSTSAVER_TRIVIAL_MODEL, _FAST_MODEL, _STANDARD_MODEL, _REASONING_MODEL |
catalog cheapest per tier | Pin a preferred model per tier. |
| providers | MODELCOSTSAVER_PROVIDERS |
client-derived | Allowlist for recommendations (Axis 1). |
| default provider | MODELCOSTSAVER_PROVIDER |
none | Bias select_optimal_model. |
| include local | MODELCOSTSAVER_INCLUDE_LOCAL |
off |
Surface self-hosted / $0 models. |
| chars/token | MODELCOSTSAVER_CHARS_PER_TOKEN |
4 |
Tune the token estimator. |
| refresh | MODELCOSTSAVER_REFRESH |
off |
Enable the opt-in remote catalog refresh. |
| catalog url | MODELCOSTSAVER_CATALOG_URL |
bundled | Override the refresh source. |
| ledger | MODELCOSTSAVER_LEDGER |
off |
Enable the local record_usage write. |
| telemetry | MODELCOSTSAVER_TELEMETRY |
off |
Kept off; listed for transparency. |
Pricing data
Prices change often, so ModelCostSaver ships a versioned, dated seed and is honest about its freshness.
- The bundled
catalog.jsoncarries acatalogVersion, anasOfdate, and asourceon every entry. - Default behavior is offline: it reads only the bundled catalog.
MODELCOSTSAVER_REFRESH=onfetches a single static JSON, validates it with zod, caches it with a TTL, and falls back to the bundle on any failure.- A
pricingOverridesmap inmodelcostsaver.config.jsonlets you inject negotiated or enterprise rates without forking.
Verify before you trust a number for billing. The seed is re-checked against each provider's public pricing page at release; the asOf date tells you when. For absolute precision in your own accounting, confirm against your provider invoice.
Development
npm install # first time only
npm run build # tsup bundle to dist/index.js
npm test # vitest
npm run typecheck # tsc --noEmit
npm run smoke # stdio JSON-RPC smoke test (asserts stdout stays clean)
License
Apache-2.0. See NOTICE.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。