npx skills add https://github.com/adaptationio/skrillz --skill agent-cost-optimizerSKILL.md
Agent Cost Optimizer
Overview
agent-cost-optimizer provides comprehensive cost tracking, budget enforcement, and ROI measurement for AI agent operations.
Purpose: Control and optimize AI spending while maximizing value delivered
Pattern: Task-based (7 operations for cost management)
Key Innovation: Real-time cost tracking with automatic budget enforcement and cost-effective fallbacks
Industry Context (2025):
- Average AI spending: $85,521/month (36% YoY increase)
- Only 50% of organizations can measure AI ROI
- IT teams struggle with hidden costs
Solution: Comprehensive cost management from tracking to optimization
When to Use
Use agent-cost-optimizer when:
- Tracking AI costs across skills
- Preventing budget overruns
- Measuring ROI (cost vs. value delivered)
- Optimizing model selection (Opus vs. Sonnet vs. Haiku)
- Planning AI budgets
- Cost-effective development
- Enterprise cost accountability
Prerequisites
Required
- AI API access (Anthropic, OpenAI, Google)
- Cost tracking capability (API usage data)
Optional
- Paid.ai or AgentOps integration (advanced cost tracking)
- Prometheus/Grafana (cost visualization)
- Budget approval workflow
Cost Operations
Operation 1: Track Token Usage
Purpose: Monitor token consumption per skill invocation
Process:
-
Initialize Tracking:
{ "tracking_id": "track_20250126_1200", "skill": "multi-ai-verification", "started_at": "2025-01-26T12:00:00Z", "tokens": { "prompt": 0, "completion": 0, "total": 0 }, "cost": { "amount_usd": 0.00, "model": "claude-sonnet-4-5" } } -
Track During Execution:
// After each AI call trackTokens({ prompt_tokens: response.usage.input_tokens, completion_tokens: response.usage.output_tokens, model: 'claude-sonnet-4-5' }); // Update running totals -
Finalize Tracking:
{ "tracking_id": "track_20250126_1200", "skill": "multi-ai-verification", "completed_at": "2025-01-26T12:45:00Z", "duration_minutes": 45, "tokens": { "prompt": 15234, "completion": 8932, "total": 24166 }, "cost": { "amount_usd": 0.073, "model": "claude-sonnet-4-5", "rate": "$3 per million tokens" } } -
Save to Cost Log:
# Append to daily cost log cat tracking.json >> .cost-tracking/$(date +%Y-%m-%d).json
Outputs:
- Token usage per invocation
- Cost per invocation
- Model used
- Daily/monthly aggregates
Validation:
- Tracking initialized
- Tokens counted accurately
- Cost calculated correctly
- Logs saved
Time Estimate: Automatic (integrated into skills)
Operation 2: Calculate Costs
Purpose: Compute accurate costs based on provider pricing
Pricing (2025 rates):
Anthropic (Claude):
| Model | Input (per MTok) | Output (per MTok) |
|---|---|---|
| Claude Opus 4.5 | $15 | $75 |
| Claude Sonnet 4.5 | $3 | $15 |
| Claude Haiku 4.5 | $0.80 | $4 |
OpenAI (Codex):
| Model | Input | Output |
|---|---|---|
| GPT-5.1-codex | $5 | $15 |
| o3 | $10 | $40 |
| o4-mini | $1.50 | $6 |
Google (Gemini):
| Model | Input | Output |
|---|---|---|
| Gemini 2.5 Pro | $1.25 | $5 |
| Gemini 2.5 Flash | $0.15 | $0.60 |
Process:
function calculateCost(usage, model) {
const pricing = {
'claude-sonnet-4-5': { input: 3, output: 15 },
'claude-haiku-4-5': { input: 0.80, output: 4 },
'claude-opus-4-5': { input: 15, output: 75 },
// ... more models
};
const rates = pricing[model];
const inputCost = (usage.prompt_tokens / 1_000_000) * rates.input;
const outputCost = (usage.completion_tokens / 1_000_000) * rates.output;
return {
input_cost: inputCost,
output_cost: outputCost,
total_cost: inputCost + outputCost,
currency: 'USD'
};
}
Outputs:
- Accurate cost per invocation
- Model-specific pricing
- Input vs. output cost breakdown
Operation 3: Enforce Budget Caps
Purpose: Prevent exceeding monthly budget limits
Process:
-
Set Budget:
{ "monthly_budget_usd": 100, "skill_budgets": { "multi-ai-verification": 70, "multi-ai-research": 20, "multi-ai-testing": 10 }, "alert_thresholds": { "warning": 0.80, "critical": 0.95 } } -
Check Before Operation:
async function checkBudget(skill, estimated_cost) { const usage = getCurrentMonthUsage(); const remaining = budget.monthly_budget_usd - usage.total_cost; if (estimated_cost > remaining) { return { allowed: false, reason: `Budget exceeded: $${usage.total_cost}/$${budget.monthly_budget_usd}`, overage: estimated_cost
...