返回顶部
a

anthropic-usage

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.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.7
安全检测
已通过
118
下载量
1
收藏
概述
安装方式
版本历史

anthropic-usage

# 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: ```bash [[ -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: ```json { "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.

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 anthropic-usage-1775956862 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 anthropic-usage-1775956862 技能

通过命令行安装

skillhub install anthropic-usage-1775956862

下载 Zip 包

⬇ 下载 anthropic-usage v1.0.7

文件大小: 16.84 KB | 发布时间: 2026-4-13 09:20

v1.0.7 最新 2026-4-13 09:20
Add openclaw.json as alternative setup option for CLI users. UI remains recommended. No env var export.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部