Daily Cost Report 📊
Generate comprehensive OpenClaw usage and cost reports with breakdowns by agent, model, and channel. Supports both on-demand analysis and automated daily email delivery.
Quick Start
CODEBLOCK0
What It Does
The daily cost report analyzes OpenClaw session data for a specified date range and generates:
- - Total cost and token usage across all agents, models, and channels
- Per-agent breakdown showing which agents consumed the most resources
- Per-model breakdown showing cost distribution across Claude models, Deepseek, GPT, etc.
- Per-channel breakdown showing usage from Telegram, CLI, web, etc.
- Top sessions by cost identifying the most expensive individual sessions
- Prompt cache metrics showing cache write/read tokens and cost savings
Reports use the current pricing for:
- - Claude Haiku 4.5
- Claude Sonnet 4.5
- Claude Opus 4.6
- Deepseek V3.2
- OpenAI GPT-4o-mini
Cache pricing (read/write) is factored into cost calculations.
Scripts
daily-cost-report.sh
Core report generator. Queries OpenClaw sessions via openclaw sessions --all-agents --json, filters by date range, calculates costs using model-specific pricing, and generates markdown output.
Output: INLINECODE2
daily-cost-report-email.sh
Wraps the markdown report in an HTML email template with styled tables, summary metrics, and visual hierarchy.
Output: INLINECODE4
send-cost-report.sh
Sends the HTML report via email using the mail command. Falls back to saving the file if mail delivery fails.
Usage: INLINECODE7
Cron Usage
The daily cost report is typically scheduled as a cron job in ~/.openclaw/cron/jobs.json:
CODEBLOCK1
The cron job invokes the skill, which then calls the appropriate scripts.
Manual Invocation from Agent
When Karl asks for a cost report:
CODEBLOCK2
Report Format
The report includes:
- 1. Summary section - Total cost, tokens, cache metrics, savings
- Cost by Agent - Which agents are most active/expensive
- Cost by Model - Model-level resource consumption
- Cost by Channel - Usage by Telegram, CLI, web, etc.
- Top Sessions - Highest-cost individual sessions
All monetary values are in USD with 4 decimal precision. Token counts are formatted with thousands separators for readability.
Date Handling
Scripts accept:
- -
yesterday (default) - Previous calendar day - INLINECODE10 - Current calendar day
- INLINECODE11 - Specific date
Date parsing is compatible with both macOS (date -v-1d) and Linux (date -d "yesterday").
Requirements
- - OpenClaw CLI: INLINECODE14
- INLINECODE15 for JSON processing
- INLINECODE16 for aggregation
- INLINECODE17 command (for email delivery)
- bash 4+ (for associative arrays)
Cost
This skill costs nothing — it only reads session metadata that OpenClaw already tracks. No external API calls.
Example Output
CODEBLOCK3
每日成本报告 📊
生成全面的OpenClaw使用和成本报告,按代理、模型和渠道细分。支持按需分析和自动每日邮件发送。
快速开始
bash
生成昨天的报告(Markdown格式)
{baseDir}/scripts/daily-cost-report.sh yesterday
生成指定日期的报告
{baseDir}/scripts/daily-cost-report.sh 2026-03-18
生成今天的报告
{baseDir}/scripts/daily-cost-report.sh today
生成HTML格式的邮件报告
{baseDir}/scripts/daily-cost-report-email.sh yesterday
发送邮件报告给收件人
{baseDir}/scripts/send-cost-report.sh kjvarga@gmail.com yesterday
功能说明
每日成本报告分析指定日期范围内的OpenClaw会话数据,并生成:
- - 总成本和Token使用量 — 涵盖所有代理、模型和渠道
- 按代理细分 — 显示哪些代理消耗了最多资源
- 按模型细分 — 显示Claude模型、Deepseek、GPT等模型的成本分布
- 按渠道细分 — 显示Telegram、CLI、Web等渠道的使用情况
- 成本最高的会话 — 识别最昂贵的单个会话
- 提示缓存指标 — 显示缓存写入/读取Token及成本节省
报告使用以下模型的当前定价:
- - Claude Haiku 4.5
- Claude Sonnet 4.5
- Claude Opus 4.6
- Deepseek V3.2
- OpenAI GPT-4o-mini
缓存定价(读取/写入)已计入成本计算。
脚本
daily-cost-report.sh
核心报告生成器。通过openclaw sessions --all-agents --json查询OpenClaw会话,按日期范围过滤,使用模型特定定价计算成本,并生成Markdown输出。
输出: /tmp/cost-report-YYYY-MM-DD.md
daily-cost-report-email.sh
将Markdown报告包装在HTML邮件模板中,包含样式化表格、汇总指标和视觉层次结构。
输出: /tmp/cost-report-YYYY-MM-DD.html
send-cost-report.sh
使用mail命令通过邮件发送HTML报告。如果邮件发送失败,则回退为保存文件。
用法: send-cost-report.sh <收件人邮箱> [日期]
Cron定时任务
每日成本报告通常作为cron任务安排在~/.openclaw/cron/jobs.json中:
json
{
id: daily-cost-report,
agentId: worker,
name: main-daily-cost-report,
enabled: true,
schedule: {
kind: cron,
expr: 0 8 *,
tz: America/Vancouver
},
sessionTarget: isolated,
wakeMode: now,
payload: {
kind: agentTurn,
message: 生成昨天的成本报告并发送至kjvarga@gmail.com
},
delivery: {
mode: announce,
channel: telegram,
to: 7918443630
}
}
cron任务调用该技能,技能再调用相应的脚本。
从代理手动调用
当Karl需要成本报告时:
bash
从任何具有exec权限的代理执行
exec(command: bash ~/.openclaw/workspace/skills/daily-cost-report/scripts/daily-cost-report.sh yesterday)
或生成并发送邮件
exec(command: bash ~/.openclaw/workspace/skills/daily-cost-report/scripts/send-cost-report.sh kjvarga@gmail.com yesterday)
报告格式
报告包含:
- 1. 摘要部分 — 总成本、Token数、缓存指标、节省金额
- 按代理划分的成本 — 哪些代理最活跃/最昂贵
- 按模型划分的成本 — 模型级别的资源消耗
- 按渠道划分的成本 — Telegram、CLI、Web等渠道的使用情况
- 热门会话 — 成本最高的单个会话
所有货币值以美元为单位,精确到小数点后4位。Token数量使用千位分隔符以便阅读。
日期处理
脚本接受:
- - yesterday(默认)— 前一个日历日
- today — 当前日历日
- YYYY-MM-DD — 指定日期
日期解析兼容macOS(date -v-1d)和Linux(date -d yesterday)。
依赖要求
- - OpenClaw CLI:openclaw sessions --all-agents --json
- jq用于JSON处理
- awk用于聚合
- mail命令(用于邮件发送)
- bash 4+(用于关联数组)
成本
此技能不产生任何费用 — 它仅读取OpenClaw已跟踪的会话元数据。无外部API调用。
示例输出
OpenClaw每日成本报告 🐈⬛
日期: 2026-03-18
生成时间: 2026-03-19 08:00:00 PDT
摘要
1,234,567 |
|
输入Token数 | 987,654 |
|
输出Token数 | 246,913 |
|
缓存写入Token数 | 123,456 |
|
缓存读取Token数 | 456,789 |
|
缓存节省金额 | $0.3245 |
按代理划分的成本
| 代理 | 成本 | Token数 | 输入 | 输出 |
|---|
| main | $1.2345 | 654,321 | 543,210 | 111,111 |
| worker |
$0.8901 | 400,000 | 320,000 | 80,000 |
| research | $0.3321 | 180,246 | 124,444 | 55,802 |
...