agentleFS
zad111ak-aizad111ak-ai/hermes-agent-skills/skills/meta/api-cost-tracker/SKILL.md

api-cost-tracker

Skill7 starsChanged 4 months agoMITView on GitHub

Трекер расходов на API в реальном времени. Логирование каждого вызова, подсчёт стоимости, алерты при превышении лимита. Чтобы не проснуться с пустым балансом.

  • Reads credentials

The file

Files
SKILL.md

API Cost Tracker — Трекер расходов на API

Активировать: при каждой задаче, которая делает API-вызовы (LLM, парсинг, генерация).

Цель: Знать сколько тратишь. Не проснуться с $0 на балансе.


Зачем

AI-агенты сжигают токены молча. Ты не замечаешь как 100K токенов пролетают за одну задачу. Через неделю — сюрприз: баланс на нуле.


Текущая ценовая карта (2025)

ПровайдерМодельВходВыход100K токенов
GroqLlama 3.1 8B0.05$0.08$0.013$
OpenRouterGemini 2.5 Flash0.15$0.60$0.075$
OpenRouterClaude Sonnet 43.00$15.00$1.80$
DeepSeekDeepSeek V30.14$0.28$0.042$
GLM-4Zhipu AI0.07¥0.07¥0.007¥

Логирование

import time
from dataclasses import dataclass

@dataclass
class APICall:
    provider: str
    model: str
    input_tokens: int
    output_tokens: int
    cost: float
    timestamp: float

class CostTracker:
    def __init__(self, budget_limit: float = 10.0):
        self.calls = []
        self.budget_limit = budget_limit
        self.total_cost = 0.0
    
    def log_call(self, provider, model, input_tokens, output_tokens, cost):
        call = APICall(provider, model, input_tokens, output_tokens, cost, time.time())
        self.calls.append(call)
        self.total_cost += cost
        
        if self.total_cost > self.budget_limit:
            print(f"🚨 БЮДЖЕТ ПРЕВЫШЕН: ${self.total_cost:.2f} / ${self.budget_limit:.2f}")
    
    def today_summary(self):
        today = time.time() - 86400
        today_calls = [c for c in self.calls if c.timestamp > today]
        total = sum(c.cost for c in today_calls)
        return f"Сегодня: {len(today_calls)} вызовов, ${total:.4f}"

Алерты

# Проверь баланс перед задачей
grep -i "balance\|credit\|remaining" ~/.provider_status

# Установи лимит в .env
BUDGET_DAILY_LIMIT=5.00
BUDGET_MONTHLY_LIMIT=50.00

Правила

  1. ВСЕГДА логируй каждый API-вызов
  2. ПРОВЕРЯЙ баланс перед дорогими задачами
  3. ИСПОЛЬЗУЙ дешёвые модели для простых задач (Groq, DeepSeek)
  4. ДЕЛАГАЙ на дешёвые модели когда возможно
  5. СОХРАНЯЙ логи — потом можно проанализировать расходы

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.