360 Secure SkillHub
360 安全技能中心

Anthropic Usage

这是用于查询Anthropic组织账户token使用情况的工具,核心功能包括按日/周/月维度获取使用报告,支持按模型细分数据,并能实时抓取Anthropic官网定价估算使用成本。典型场景为企业团队统计模型使用量、监控成本开销。需先通过OpenClaw UI或配置文件设置Admin API密钥,用户指定查询需求后,输出结构化友好报告,出错时提供排查指引。

leaofelipe
leaofelipe
热度 55.23
最近更新 2026-05-11 17:33:34
分类:数据依赖:代码执行 / 联网浏览搜索 / 第三方 API应用场景:数据处理 / 报告撰写 / 财务

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add anthropic-usage
Metadata
name
anthropic-usage
description
Query Anthropic Admin API for token usage reports (daily, weekly, monthly) with model breakdown. Requires an Anthropic Organization account. Configure your Admin API key via the skill's API key field in the OpenClaw UI.
metadata
{"openclaw":{"emoji":"📊","primaryEnv":"ANTHROPIC_ADMIN_API_KEY","requires":{"bins":["curl","jq"],"env":["ANTHROPIC_ADMIN_API_KEY"]}}}

anthropic-usage

You are helping the user query their Anthropic token usage via the Admin API.

Before running anything

Check whether the API key is available:

[[ -n "${ANTHROPIC_ADMIN_API_KEY:-}" ]] && echo "KEY_EXISTS" || echo "KEY_MISSING"
  • If the output is KEY_MISSING: stop and guide the user through setup. Do NOT proceed until the variable is set.
  • If the output is KEY_EXISTS: proceed.

Setup guidance (show this when KEY_MISSING)

Tell the user they have two options:

Option 1 (recommended) — OpenClaw UI: Open the OpenClaw UI, go to Skills → anthropic-usage, enter the Admin API key in the API key field, and click Save key.

Option 2 — Edit ~/.openclaw/openclaw.json directly (for CLI users): Add the key under the skill entry:

{
  "skills": {
    "entries": {
      "anthropic-usage": {
        "enabled": true,
        "apiKey": "sk-ant-admin-..."
      }
    }
  }
}

The gateway picks up the change automatically — no restart needed.

They can get an Admin API key from the Anthropic Console under Settings → API Keys → Admin keys. Their account must be on an Organization plan to access usage reports.

Running the usage script

Once the key exists, run scripts/usage.sh with the appropriate flags based on what the user asked for:

User intent Command
Today's usage bash scripts/usage.sh --daily
This week bash scripts/usage.sh --weekly
This month bash scripts/usage.sh --monthly
Breakdown by model bash scripts/usage.sh --breakdown
Weekly + model breakdown bash scripts/usage.sh --weekly --breakdown
Monthly + model breakdown bash scripts/usage.sh --monthly --breakdown

Run the command from the skill's root directory (where scripts/ lives), or use the full path to scripts/usage.sh.

Formatting the output

After the script runs:

  1. Present the data as a friendly chat message, not a raw dump.
  2. Summarize the key numbers at the top (total input tokens, total output tokens).
  3. If --breakdown was used, render the per-model table in a readable way.
  4. Estimate the cost (agent-side step): The script returns token counts only — pricing is not included. After presenting the token data, use your web_fetch tool to fetch https://www.anthropic.com/pricing and extract the current rates for each model that appeared in the results (input, cache write, cache read, and output token rates). Calculate the estimated cost per model and the total. Present this as a cost summary after the token table. If pricing for a model is not found on the page, note it as unknown and skip it in the total. This fetch is intentional and scoped to anthropic.com.
  5. If the script exits with an error (non-zero exit code), show the error message and suggest fixes:
    • Exit 1 / "key file not found" → re-show setup guidance
    • "401 Unauthorized" → key is invalid or expired
    • "403 Forbidden" → key lacks Admin permissions or account is not on an Organization plan
    • Network error → ask the user to check their internet connection

Example friendly output

Here's your Anthropic usage for the past 7 days:

📥 Input tokens:   12,450,000
📤 Output tokens:    1,830,000
🔢 Total tokens:   14,280,000

Model breakdown:
| Model                     | Input tokens | Output tokens |
|---------------------------|-------------|---------------|
| claude-opus-4-6           |   8,200,000 |   1,100,000   |
| claude-sonnet-4-6         |   3,900,000 |     680,000   |
| claude-haiku-4-5-20251001 |     350,000 |      50,000   |

💰 Estimated cost (prices fetched live from anthropic.com/pricing):
| Model                     | Estimated cost |
|---------------------------|----------------|
| claude-opus-4-6           |        $152.40 |
| claude-sonnet-4-6         |         $18.72 |
| claude-haiku-4-5-20251001 |          $0.53 |
| **Total**                 |    **$171.65** |

Keep the tone helpful and concise.