npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

prompt-token-counter

v1.0.11

Published

OpenClaw skill: Count tokens and estimate costs for 300+ LLM models. Audit workspace token consumption (memory, persona, skills).

Downloads

898

Readme

prompt-token-counter

English

一个 OpenClaw skill,用于统计 token 数量并估算 API 成本。

实现原理

本项目提供本地 token 计数,无需调用 API:

| 方式 | OpenAI | 其他模型 | |------|--------|----------| | 方法 | tiktoken(精确) | 公式近似 | | 精度 | 精确 | 约 85–95% |

对非 OpenAI 模型,使用按 provider 校准的公式。当文本包含 CJK(中/日/韩)时,会根据 CJK 字符占比混合比例,使中文为主的文本获得更低的 chars/token(每字符更多 token)。

基准测试:主力模型(8927 字符,英文/混合)

| 模型 | 字符数 | Token 数 | 1 token ≈ 多少字符 | 状态 | |------|--------|----------|-------------------|------| | anthropic/claude-sonnet-4-6 | 8927 | 2763 | 3.23 | ✓ | | anthropic/claude-sonnet-4-5 | 8927 | 2763 | 3.23 | ✓ | | anthropic/claude-opus-4.6 | 8927 | 2763 | 3.23 | ✓ | | openai/gpt-5.2-codex | 8927 | 2459 | 3.63 | ✓ | | google/gemini-3.1-pro-preview | 8927 | 2627 | 3.40 | ✓ | | z-ai/glm-5 | 8927 | 2457 | 3.63 | ✓ | | volcengine/doubao-seed-2-0-pro | 8927 | 2702 | 3.30 | ✓ | | moonshot/kimi-k2.5 | 8927 | 2402 | 3.72 | ✓ | | minimax/MiniMax-M2.5 | 8927 | 2428 | 3.68 | ✓ | | deepseek-v3.2 | 8927 | 2578 | 3.46 | ✓ |

基准测试:主力模型(3050 字符,混杂中文)

| 模型 | 字符数 | Token 数 | 1 token ≈ 多少字符 | 状态 | |------|--------|----------|-------------------|------| | anthropic/claude-sonnet-4-6 | 3050 | 1913 | 1.59 | ✓ | | anthropic/claude-sonnet-4-5 | 3050 | 1913 | 1.59 | ✓ | | anthropic/claude-opus-4.6 | 3050 | 1913 | 1.59 | ✓ | | openai/gpt-5.2-codex | 3050 | 1564 | 1.95 | ✓ | | google/gemini-3.1-pro-preview | 3050 | 1473 | 2.07 | ✓ | | z-ai/glm-5 | 3050 | 1318 | 2.31 | ✓ | | volcengine/doubao-seed-2-0-pro | 3050 | 1494 | 2.04 | ✓ | | moonshot/kimi-k2.5 | 3050 | 1257 | 2.43 | ✓ | | minimax/MiniMax-M2.5 | 3050 | 1289 | 2.37 | ✓ | | deepseek-v3.2 | 3050 | 1361 | 2.24 | ✓ |

基准数据来自 scripts/examples/benchmark_token_ratio.py(API 模式)。

这个 Skill 能做什么

加载后,Agent 可以:

| 能力 | 使用场景 | |------|----------| | 统计 token | 「这段 prompt 有多少 token?」、「X 的 token 长度」 | | 估算成本 | 「这段文字用 GPT-4 要多少钱?」、「Claude 的 API 成本」 | | 审计 OpenClaw 工作区 | 「我的工作区用了多少 token?」、「哪些 memory/persona/skills 消耗 token?」 | | 对比模型 | 「对比不同模型的 token 成本」、「哪个模型更便宜?」 |

OpenClaw Token 审计

该 skill 帮助识别工作区各组件的 token 消耗:

  • Memory 与 persona:AGENTS.md、SOUL.md、IDENTITY.md、USER.md、MEMORY.md、TOOLS.md 等
  • Skills~/.openclaw/skills/workspace/skills/ 下的每个 SKILL.md

审计示例(批量多文件):

python -m scripts.cli -m gpt-4o -c AGENTS.md SOUL.md MEMORY.md

何时触发

  • 用户询问 token 数量、prompt 长度、API 成本
  • 用户提到 OpenClaw 上下文大小或工作区 token 使用
  • Agent 需要在变更前后审计 token 消耗

复制发送给 OpenClaw

ClawHub(推荐,国际)

Please run clawhub install prompt-token-counter to install this skill, and help me count tokens and estimate API costs.

npm

Please run npm i prompt-token-counter to install this skill, and help me count tokens and estimate API costs.

快速参考

python -m scripts.cli -m gpt-4 "Hello, world!"
python -m scripts.cli -f input.txt -m claude-3-opus -c
python -m scripts.cli -l   # 列出 300+ 模型

基准测试脚本

运行 scripts/examples/benchmark_token_ratio.py 可批量测试各模型的 token 比例:

  • API 模式(默认):调用模型 API 获取精确 prompt_tokens。需在脚本中设置 API_KEYBASE_URL
  • 本地模式--local):使用本项目的 TokenCounter 近似计算,无需 API。
python scripts/examples/benchmark_token_ratio.py           # API 模式
python scripts/examples/benchmark_token_ratio.py --local   # 本地近似

MIT