TokenZero

sh.tokenzero由 tokenzero.sh 發布官方發布者v0.3.0更新於 Nov 5, 2026

Ledger of record for AI spend: verifiable receipts, waste auditor & model arbitrage MCP.

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

概覽

AI 產生的概覽

TokenZero 稽核 LLM token 浪費、比較不同模型價格並讓請求內容可被快取,還能開通 BYOK 閘道工作區並簽發可驗證的節省憑證。

可以做什麼
  • 稽核公開 GitHub 儲存庫或原始碼檔案中的 token 浪費,例如未加快取的靜態提示詞、用前沿模型做抽取任務、迴圈內呼叫
  • 改寫 OpenAI 或 Anthropic 請求內容,讓靜態前綴可被供應商快取,並顯示預估節省
  • 依牌價比較同一負載在不同模型上的成本,包含更便宜的同類模型與提示快取效果
  • 建立工作區與金鑰,回傳閘道 base URL 和儀表板連結
  • 讀取工作區的節省計分卡、ROI 與各模型明細
  • 免金鑰即可在範例或自有提示詞上預覽四個節省引擎
適用情境
適合想降低 LLM API 帳單的情境:檢查程式碼庫或拉取請求中的 token 浪費、比較某負載的模型成本,或把流量接到可快取並簽發可驗證節省憑證的閘道。
執行需求
可作為遠端端點使用,也可透過 npx 以本機 npm 套件執行,stdio 方式需要 Node.js。多數工具不需金鑰;workspace_metrics 需要 TOKENZERO_KEY 中的工作區金鑰,TOKENZERO_URL 可覆寫閘道位址。託管工具需要網路連線。
安裝前請注意
optimize_prompt_payload 會把你提供的請求內容送到 TokenZero 服務,其中不應包含機密資訊。工作區金鑰只回傳一次,應視為機密;嵌入 base URL 的金鑰尤其敏感。供應商金鑰會經過閘道,稽核數字是依牌價做的靜態估算,並非實測節省。

安裝

在 SourceWeft 中

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

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

交給代理程式安裝

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

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

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

其他 MCP 客戶端

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

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

README

TokenZero tools

Open-source tools from TokenZero, the independent ledger of record for AI spend (metering, attribution, budget control, audit).

  • The receipt verifier (verifier/tokenzero-verify.mjs) checks a TokenZero receipt without trusting TokenZero: Ed25519 signature over canonical JSON, the savings-bucket math and the hash chain. Zero dependencies; library or CLI. The format is specified in docs/receipt-spec.md.

  • @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 ledger (through the gateway sensor) 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,提交 d0afe66

工具

6

try_tokenzero

Try TokenZero (no key needed)

Call this first: no API key, no signup, no setup. Shows what TokenZero would do to one of your LLM calls: it runs the four savings engines (prompt-cache formatting, edge cache, cascade advice, signed receipt) on a sample or your own prompt and model, and returns the list-price saving, the signed receipt and a copy-paste keyless curl that makes a real call on a free model. Pass {} for the default, or {"model": "gpt-6.1-sol", "system": "...", "prompt": "..."}.

輸入參數modelpromptsystem

audit_repo_token_waste

Audit a repo for LLM token waste

No API key needed. Static-analyze a public GitHub repo (e.g. {"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, and prompt-caching mis-integration (caching gated on model names, volatile values in the system prompt, random ids in history, wrong-provider cache markers, misplaced breakpoints, cost math that ignores cached tokens). Returns findings with fixes and an estimated recoverable percentage.

輸入參數repofiles

optimize_prompt_payload

Make a request body cache-friendly

No API key needed. 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 across models

No API key needed; only `model` is required (e.g. {"model": "gpt-6.1-sol"}, defaults 2,000 tokens in and 400 out). 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. The result names the pricing table version it used.

輸入參數model必填compare_toinput_tokensoutput_tokensstatic_tokensrequests_per_month

provision_workspace

Create a free TokenZero 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

Read a workspace savings scorecard

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

版本歷史

8
  1. v0.3.0最新Nov 5, 2026
  2. v0.2.16Nov 4, 2026
  3. v0.2.15Nov 3, 2026
  4. v0.2.12Nov 1, 2026
  5. v0.2.11Nov 1, 2026
  6. v0.2.9Oct 30, 2026
  7. v0.2.5Oct 26, 2026
  8. v0.2.2Oct 26, 2026

評分

已滿足適用檢查項的 100%

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

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

其他 Tokenzero 整合