AI模型成本计算工具

tokencost是一款用于计算和比较AI模型使用成本的工具,支持模型详情查询、成本估算和模型比较功能。

  • by atriumn
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 atriumn/tariff

使用说明

tokencost

Ask your AI assistant "how much does GPT-4o cost?" — get an instant, accurate answer.


30秒内安装

克劳德代码:

claude mcp add tokencost-dev -- npx -y tokencost-dev

然后问: “在claude-sonnet-4-5上,100万输入代币的成本是多少?”

光标 (.cursor/mcp.json):

{
  "mcpServers": {
    "tokencost-dev": {
      "command": "npx",
      "args": ["-y", "tokencost-dev"]
    }
  }
}

没有API密钥。没有账户。没有配置文件。定价数据从 LiteLLM社区注册 并在本地缓存24小时。

工具

get_model_details

查找任何型号的定价、上下文窗口和功能。模糊匹配方法 "sonnet 4.5" 工作得一样好 "claude-sonnet-4-5-20250514".

> "What are Claude Sonnet 4.5's pricing and capabilities?"

Model: claude-sonnet-4-5
Provider: anthropic | Mode: chat

Pricing (per 1M tokens):
  Input:  $3.00
  Output: $15.00

Context Window:
  Max Input:  200K
  Max Output: 8K

Capabilities: vision, function_calling, parallel_function_calling

calculate_estimate

估算给定数量的输入和输出令牌的成本。

> "How much will 1000 input + 500 output tokens cost on Claude Sonnet 4.5?"

Cost Estimate for claude-sonnet-4-5

  Input:  1K tokens × $3.00/1M  = $0.003000
  Output: 500 tokens × $15.00/1M = $0.007500
  ─────────────────────────────
  Total:  $0.0105

compare_models

找到符合您要求的最具成本效益的型号。

> "What are the cheapest OpenAI chat models?"

Top 2 most cost-effective models (provider: openai) (mode: chat):

1. gpt-4o-mini
   Provider: openai | Mode: chat
   Input: $0.15/1M | Output: $0.60/1M
   Context: 128K in / 16K out

2. gpt-4o
   Provider: openai | Mode: chat
   Input: $5.00/1M | Output: $15.00/1M
   Context: 128K in / 16K out

refresh_prices

强制从LiteLLM注册表中重新获取定价数据(缓存每24小时自动刷新一次)。

文档

完整文档请访问 tokencost.dev

许可证

麻省理工学院