在 Claude Code、Codex、Cursor、OpenCode、Pi、Gemini CLI 等 AI Coding Agent 中直接查询 LLM 价格,让 AI 自动完成 API 成本核算。
推荐做法是把 skill 直接交给 Agent,让它自己完成安装:
SKILL.md 内容。如需手动安装,各 Agent 的 skill 位置如下:
.claude/skills/traktoken-query/SKILL.md.agents/skills/traktoken-query/SKILL.md.cursor/skills/traktoken-query/SKILL.md.opencode/skill/traktoken-query/SKILL.mdAGENTS.md。更新方式:重新复制或下载当前版本并替换原文件。价格 API 会返回当前 skill_version;版本不一致时,Skill 会提示更新,但不会自动覆盖本地文件。
--- name: traktoken-query description: Query current LLM API prices from TrakToken, compare token costs, and calculate scenario-based monthly API spend. Use when the user asks about LLM pricing, token costs, or API cost comparisons. Do not estimate hardware sizing or local-deployment ROI without verified hardware prices and measured throughput. --- # TrakToken Query Skill Installed version: `0.2.0`. Canonical source: `https://www.traktoken.com/skills/traktoken.md`. ## Workflow 1. Resolve the requested models without fetching the full catalog: ```bash curl -sS --get --data-urlencode "q=MODEL_NAME" https://www.traktoken.com/api/prices # When exact ids are known: curl -sS "https://www.traktoken.com/api/prices?ids=MODEL_ID_1,MODEL_ID_2" ``` Use localhost only when developing the TrakToken repository itself and its local server is running. 2. Validate the response before calculating: - Require `success: true`, `schema_version: 2`, and `skill_version`. - If `skill_version` differs from installed version `0.2.0`, disclose the mismatch and link `skill_download_url`. Do not silently overwrite local files. - Use only entries whose `price_status` is `priced` and whose prices are numbers. - Treat `null` prices as "not collected". Never treat them as free or substitute zero. - If multiple versions match, show the candidates or ask which exact model to use. Do not silently choose between reasoning, non-reasoning, dated, or preview variants. - Treat `context_window: null` as unknown. 3. Calculate scenario costs. For requests per day: - `daily_input = requests * input_tokens_per_request` - `daily_output = requests * output_tokens_per_request` - `monthly_cost = days * (daily_input / 1_000_000 * input_price + daily_output / 1_000_000 * output_price)` - Use the user's billing period. If absent, use 30 days and state that assumption. 4. Present the exact model id, provider, input/output prices per 1M tokens, monthly cost, and `updated_at`. Describe `updated_at` as the dataset fetch time, not proof that the vendor changed its price on that date. State that caching, batch discounts, taxes, exchange rates, and provider-specific tiers are excluded unless supplied. 5. Fail closed: - If the endpoint fails, the requested model is missing, or the price is unpriced, say that current pricing cannot be calculated from TrakToken. Do not reuse remembered or example prices. - For local-deployment ROI, explain that this Skill currently lacks verified hardware prices and measured throughput. Link to `https://www.traktoken.com/models/open-source#local-roi` for a user-supplied interactive estimate instead of inventing hardware costs or a payback period. ## Output checklist - Name the data source and fetch date. - Distinguish exact model variants. - Show the formula and assumptions. - Never rank unpriced models as cheapest.
安装完成后,你可以在 Claude Code、Codex、Cursor 等任意 Coding Agent 的对话中直接向 AI 提问:
"我要做一个每天处理 10 万条消息的客服机器人,调用 DeepSeek V4 和 GPT-5 mini 相比,哪个方案更省钱?""查一下 DeepSeek V3.2 推理版和非推理版的价格;如果匹配到多个版本,先把候选项列出来。""查一下目前 Claude Sonnet 5 的最新价格,并和 Kimi K2.6、DeepSeek V4 等国内同级别模型做个对比。"