TokenZero

io.github.tokenzero-ai由 GitHub 帳號 tokenzero-ai 發布v0.2.2更新於 Oct 26, 2026

LLM cost optimization gateway, repo token-waste auditor & model arbitrage MCP server.

發布方自己的服務:TokenZero

已驗證Streamable HTTP可網頁執行開發者工具資料與分析AI 與機器學習

概覽

AI 產生的概覽

TokenZero 稽核程式碼中的 LLM token 浪費、改寫請求內容以啟用提示快取、比較不同模型價格,並檢視工作區的節省與 ROI 指標。

可以做什麼
  • 稽核公開 GitHub 儲存庫或一組原始碼檔案中的 token 浪費,列出問題、修正建議與預估可回收比例
  • 改寫 OpenAI 或 Anthropic 請求內容,讓靜態前綴可被供應商快取,回傳新內容、變更項目與預估節省
  • 依牌價為工作負載在多個模型間比價,包含更便宜的同類模型與提示快取的影響
  • 建立 TokenZero 工作區與金鑰,並檢視工作區的即時節省與 ROI 計分卡
適用情境
適合正在支付 LLM API 費用、想讓助理找出浪費的提示寫法、讓請求更容易被快取、比較模型成本,或查看工作區實測節省的情況。
執行需求
遠端 MCP 端點 tokenzero.sh,或以 npx 在本機執行 npm 套件 @tokenzero/mcp。稽核、比價與提示最佳化工具不需帳號;workspace_metrics 需要工作區金鑰(tz_live_…),也可傳 demo: true 取得範例資料。閘道本身採自帶金鑰(BYOK)模式。
安裝前請注意
optimize_prompt_payload 會把使用者提供的請求內容送到 TokenZero 服務,因此不要在其中放入機密資訊。工作區金鑰屬於憑證;README 提醒內嵌在 base URL 中的金鑰應視為機密,外洩後需輪換。稽核數字是依牌價的靜態估算,並非實測流量節省。建立工作區在每月免費額度內不收費。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 TokenZero,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Web executable,透過 Streamable HTTP。 遠端服務在工作區中設定後即可從網頁執行環境執行。

交給代理程式安裝

把這段提示詞貼上到 Claude Code、Codex、Cursor 等代理程式,或 SourceWeft 對話中。代理程式會讀取該伺服器的安裝指南,先向你展示發布者、端點和登入方式,經你同意後再把它新增到你的客戶端。金鑰不會寫進任何命令。

閱讀 https://sourceweft.com/mcp/io.github.tokenzero-ai%2Ftokenzero/install.md,並按其中說明把這個 MCP 伺服器接入我的客戶端。修改任何設定之前,先告訴我它的發布者、端點和登入方式,等我確認。不要把 API 金鑰寫進命令或我會提交的檔案;問我金鑰應從哪裡取得。

檢視代理程式所依據的安裝指南

其他 MCP 客戶端

把它新增到你客戶端的 mcpServers 設定中。

{
  "mcpServers": {
    "tokenzero": {
      "type": "http",
      "url": "https://tokenzero.sh/mcp"
    }
  }
}

README

TokenZero tools

Open-source tools from TokenZero, the bring-your-own-key gateway that cuts OpenAI, Anthropic and Gemini bills.

  • @tokenzero/mcp is a stdio MCP server for Claude Code, Cursor, Windsurf and Cline: audit the open project for token waste (locally), price model alternatives, make request bodies cache-friendly.
  • @tokenzero/cli connects a project to the gateway with no code changes, audits LLM token waste locally, shows usage and verifies signed savings receipts.
  • The analyzer (src/audit-core.ts) is the static token-waste audit used by the CLI, the hosted repo audit and the PR cost-diff check. It runs entirely on your machine.
  • The pricing table (src/pricing.ts) lists the list prices every estimate is computed from, versioned and dated.

Audit a project

sh
npx -y @tokenzero/cli audit            # local, nothing is uploadednpx -y @tokenzero/cli audit --jsonnpx -y @tokenzero/cli audit --fail-over 30   # CI gate: exit 1 above 30% recoverablegit diff origin/main | npx -y @tokenzero/cli audit --diff - --format markdown

Audits are static heuristics: they read code, not traffic. Numbers are estimates at list prices; verified savings come from the gateway's signed ledger once requests flow through it.

What it looks for:

  • large static prompts sent without caching directives (Anthropic cache_control, OpenAI prefix stability)
  • prompt templates defined away from their call sites with no caching anywhere
  • frontier models on prompts that read like extraction or classification
  • LLM calls inside loops (Batch API or shared-prefix caching candidates)
  • unpriced or retired model ids

Library and SDK repositories are detected and their findings downgraded, since their call sites pass through whatever the caller chooses.

Check every pull request (GitHub Action)

yaml
# .github/workflows/tokenzero.ymlname: TokenZero cost checkon: pull_requestpermissions: { contents: read, pull-requests: write }jobs:  cost-check:    runs-on: ubuntu-latest    steps:      - uses: actions/checkout@v4        with: { fetch-depth: 0 }      - uses: tokenzero-ai/tokenzero/action@v0

One comment per PR, updated on every push; nothing leaves the runner. See action/README.md for inputs and outputs.

Use it from a coding agent (MCP)

sh
claude mcp add tokenzero -- npx -y @tokenzero/mcp          # Claude Code
json
{ "mcpServers": { "tokenzero": { "command": "npx", "args": ["-y", "@tokenzero/mcp"] } } }

audit_repo_token_waste and calculate_model_arbitrage run entirely on your machine. optimize_prompt_payload sends the request body you give it to the TokenZero service (https://tokenzero.sh unless TOKENZERO_URL is set), so do not put secrets in it.

Connect a project to the gateway

sh
npx -y @tokenzero/cli init

init audits locally, creates a workspace, and (with your consent) adds OPENAI_BASE_URL / ANTHROPIC_BASE_URL to .env. Your provider keys pass through untouched and are never stored.

Authentication: send the workspace key as the X-TokenZero-Key header (recommended). For zero-code setups the CLI can also embed it in the base URL (/w/<key>/v1); treat such URLs as secrets and use tokenzero rotate-key if one leaks.

Develop

sh
npm installnpm run build      # bundles cli/bin/tokenzero.mjs (single file, no runtime deps)npm test

License: Apache-2.0 · [email protected]

來源:README.md,提交 52982eb

工具

5

audit_repo_token_waste

Static-analyze a public GitHub repo (owner/name) or a set of source files for LLM token waste: uncached static prompts, frontier models on extraction tasks, hot loops, non-deterministic repeat calls. Returns findings with fixes and an estimated recoverable percentage.

輸入參數repofiles

optimize_prompt_payload

Rewrite an OpenAI Chat/Responses or Anthropic Messages request body so its static prefix is provider-cacheable (Anthropic cache_control breakpoints, OpenAI prompt_cache_key). Returns the optimized body, what changed, the token profile and the projected per-request saving. Never changes the tokens the model sees.

輸入參數body必填endpointstrategy

calculate_model_arbitrage

Price a workload at list prices across models: cost per request and per month for the requested model, its cheaper sibling, and the effect of prompt caching. Pricing table version 2026-10-26.

輸入參數model必填compare_toinput_tokens必填output_tokens必填static_tokensrequests_per_month

provision_workspace

Create a TokenZero workspace and key with no form. Returns the key once, the base URLs that route through it (OPENAI_BASE_URL / ANTHROPIC_BASE_URL), the one-click dashboard link and the badge URL. Free up to the monthly free tier; nothing is billed.

輸入參數name

workspace_metrics

Live value scorecard for a TokenZero workspace: hard savings and net ROI per window, the four engines' contribution, speed, parity, availability and privacy posture, per-model breakdown and one-click recommendations. Needs the workspace key (tz_live_…); pass demo: true for a labelled sample.

輸入參數keydemowindow

版本歷史

1
  1. v0.2.2最新Oct 26, 2026

評分

已滿足適用檢查項的 100%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通必需25 分
  • 已宣告認證方式必需10 分
  • 已列出工具必需15 分
  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分

其他 Tokenzero 整合