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 集成