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