Token Usage Monitor
Overview
This skill provides comprehensive token usage monitoring and reporting capabilities for AI models. It helps you track token consumption in real-time, analyze historical usage patterns, and receive alerts when usage exceeds predefined thresholds. Ideal for optimizing prompt costs, controlling AI service expenses, and ensuring efficient use of model resources.
Core Capabilities
1. Real-Time Token Usage Monitoring
- - Track token consumption per request, per session, and per model
- Monitor token usage speed (tokens per second/minute)
- View live usage metrics including prompt tokens, completion tokens, and total tokens
2. Historical Usage Analysis
- - Generate usage reports for specified time periods (daily, weekly, monthly)
- Analyze usage trends across different models and applications
- Identify peak usage times and cost drivers
3. Threshold Alerts
- - Set custom token usage thresholds for different models or sessions
- Receive notifications when usage exceeds defined limits
- Configure alert channels (chat, email, or system notifications)
4. Cost Estimation
- - Calculate approximate costs based on token usage and model pricing
- Compare costs across different models and providers
- Optimize prompts to reduce token usage and costs
Quick Start
Monitor Current Session Usage
CODEBLOCK0
Generate Daily Usage Report
CODEBLOCK1
Set Usage Threshold
CODEBLOCK2
Resources
scripts/
Create only the resource directories this skill actually needs. Delete this section if no resources are required.
scripts/
- -
token_usage_tracker.py: Main script for tracking and reporting token usage
Key features:
- Tracks token usage per session, model, and time period
- Generates daily usage reports with cost estimates
- Supports custom usage thresholds and alerts
- Provides real-time and historical usage analytics
Usage examples:
CODEBLOCK3
Note: The script automatically creates and manages a data file at ~/.openclaw/token_usage.json to store usage data.
references/
Documentation and reference material intended to be loaded into context to inform Codex's process and thinking.
Examples from other skills:
- - Product management:
communication.md, context_building.md - detailed workflow guides - BigQuery: API reference documentation and query examples
- Finance: Schema documentation, company policies
Appropriate for: In-depth documentation, API references, database schemas, comprehensive guides, or any detailed information that Codex should reference while working.
assets/
Files not intended to be loaded into context, but rather used within the output Codex produces.
Examples from other skills:
- - Brand styling: PowerPoint template files (.pptx), logo files
- Frontend builder: HTML/React boilerplate project directories
- Typography: Font files (.ttf, .woff2)
Appropriate for: Templates, boilerplate code, document templates, images, icons, fonts, or any files meant to be copied or used in the final output.
Not every skill requires all three types of resources.
Token 用量监控器
概述
本技能为AI模型提供全面的Token用量监控与报告功能。可实时追踪Token消耗情况,分析历史使用模式,并在用量超过预设阈值时发送警报。适用于优化提示词成本、控制AI服务支出、确保模型资源高效利用。
核心功能
1. 实时Token用量监控
- - 按请求、会话和模型追踪Token消耗
- 监控Token使用速度(每秒/每分钟Token数)
- 查看实时用量指标,包括提示Token、补全Token和总Token数
2. 历史用量分析
- - 生成指定时间段(日、周、月)的用量报告
- 分析不同模型和应用的使用趋势
- 识别用量高峰期和成本驱动因素
3. 阈值警报
- - 为不同模型或会话设置自定义Token用量阈值
- 用量超过设定限制时接收通知
- 配置警报渠道(聊天、邮件或系统通知)
4. 成本估算
- - 基于Token用量和模型定价计算近似成本
- 比较不同模型和提供商的成本
- 优化提示词以减少Token用量和成本
快速开始
监控当前会话用量
bash
检查当前会话Token用量
python scripts/token
usagetracker.py --session
生成每日用量报告
bash
生成今日用量报告
python scripts/token
usagetracker.py --report --period day
设置用量阈值
bash
为GPT-4设置每日100,000 Token的阈值
python scripts/token
usagetracker.py --set-threshold --model gpt-4 --limit 100000 --period day
资源
scripts/
仅创建此技能实际需要的资源目录。如无需资源,请删除此部分。
scripts/
- - tokenusagetracker.py:用于追踪和报告Token用量的主脚本
主要特性:
- 按会话、模型和时间段追踪Token用量
- 生成包含成本估算的每日用量报告
- 支持自定义用量阈值和警报
- 提供实时和历史用量分析
使用示例:
bash
# 追踪单次用量事件
python scripts/tokenusagetracker.py --track --model doubao-seed --prompt-tokens 100 --completion-tokens 200
# 查看当前会话用量
python scripts/tokenusagetracker.py --session
# 生成每日用量报告
python scripts/tokenusagetracker.py --report --period day
# 设置用量阈值(豆包每日100,000 Token)
python scripts/tokenusagetracker.py --set-threshold --model doubao-seed --limit 100000
# 查看总体用量摘要
python scripts/tokenusagetracker.py --summary
注意: 脚本会自动在 ~/.openclaw/token_usage.json 创建并管理数据文件,用于存储用量数据。
references/
旨在加载到上下文中以指导Codex流程和思考的文档和参考资料。
其他技能示例:
- - 产品管理:communication.md、context_building.md - 详细工作流程指南
- BigQuery:API参考文档和查询示例
- 财务:模式文档、公司政策
适用场景: 深度文档、API参考、数据库模式、综合指南,或Codex在工作时应参考的任何详细信息。
assets/
不打算加载到上下文中,而是在Codex生成的输出中使用的文件。
其他技能示例:
- - 品牌样式:PowerPoint模板文件(.pptx)、Logo文件
- 前端构建器:HTML/React样板项目目录
- 排版:字体文件(.ttf、.woff2)
适用场景: 模板、样板代码、文档模板、图片、图标、字体,或任何旨在复制或用于最终输出的文件。
并非每个技能都需要所有三种类型的资源。