← 返回
未分类

ClawCache Free - LLM Cost Tracking & Caching

Track and log LLM API costs with automatic token counting and cache exact responses locally using SQLite to reduce expenses and boost efficiency.
自动计数追踪LLM API费用,使用SQLite本地缓存完整响应,降低成本并提升效率。
abyousef739
未分类 clawhub v0.2.0 1 版本 99523.8 Key: 无需
★ 0
Stars
📥 209
下载
💾 1
安装
1
版本
#caching#cost-tracking#developer-tools#latest#llm#python

概述

ClawCache Free - LLM Cost Tracking & Caching

ClawCache is a production-ready Python library that helps you track every penny spent on LLM APIs and automatically cache responses to slash costs.

🎯 What You Get

💰 Cost Tracking

  • Automatic logging of every LLM API call with precise token counting
  • Daily CLI reports showing spending, savings, and cache efficiency
  • Multi-provider support: OpenAI, Anthropic, Mistral, Ollama, and more
  • 2026 pricing built-in for accurate cost calculations

⚡ Smart Caching

  • Exact-match caching using SQLite (fast, reliable, local)
  • 58.3% cache hit rate proven in real-world scenarios
  • Automatic savings - cached responses cost $0
  • Composite cache keys for better accuracy (model + temperature + params)

📊 Real-World Performance

Based on comprehensive simulation with 48 API calls across 4 common use cases:

| Metric | Value |

|--------|-------|

| Cache Hit Rate | 58.3% |

| Total Cost | $0.0062 |

| API Calls Saved | 28 out of 48 |

| Scenarios Tested | Code Review, Data Analysis, Content Generation, QA Support |

Scenario Breakdown

| Scenario | Calls | Cache Hits | Hit Rate |

|----------|-------|------------|----------|

| Code Review | 12 | 7 | 58.3% |

| Data Analysis | 12 | 8 | 66.7% |

| Content Generation | 12 | 7 | 58.3% |

| QA Support | 12 | 6 | 50.0% |

🚀 Quick Start

Installation

pip install clawcache

Basic Usage

from clawcache.free.cost import async_monitor_cost
from clawcache.free.cache_basic import BasicCache

# Initialize cache
cache = BasicCache()

# Decorate your LLM function
@async_monitor_cost
async def my_llm_call(prompt, model="gpt-4-turbo"):
    # Check cache first
    cached = await cache.aget(prompt, model=model)
    if cached:
        return cached.content
    
    # Make actual API call
    response = await openai.ChatCompletion.acreate(
        model=model,
        messages=[{"role": "user", "content": prompt}]
    )
    
    # Cache the response
    await cache.aset(prompt, response, model=model)
    return response

# Use it
result = await my_llm_call("Explain quantum computing")

View Your Cost Report

ClawCache automatically tracks all your LLM spending:

# See today's detailed cost report
clawcache --report

# Output shows:
# - Money spent today
# - Money saved via cache
# - Total API calls
# - Cache hit rate
# - Efficiency metrics

✨ Features

Cost Tracking & Monitoring

  • Automatic Cost Logging: Every API call tracked with timestamp, model, tokens, and cost
  • Daily CLI Reports: Shows spending, savings, and efficiency metrics
  • Accurate Token Counting: Uses tiktoken when available
  • Multi-Provider Support: OpenAI, Anthropic, Mistral, Ollama, etc.

Smart Caching

  • Exact-Match Caching: SQLite-based (fast and reliable)
  • Composite Cache Keys: Cache by prompt + model + params
  • Async Support: Full async/await compatibility
  • Automatic Savings: Cached responses cost $0

Security & Reliability

  • Secure: Pickle opt-in (disabled by default)
  • Concurrent-Safe: SQLite WAL mode
  • Cross-Platform: Windows, macOS, Linux

🔒 Security

ClawCache takes security seriously:

  • Pickle opt-in: Deserialization disabled by default to prevent RCE
  • SQLite WAL mode: Safe concurrent access
  • File locking: Cross-platform file locking for log integrity

📖 Configuration

Customize ClawCache behavior via environment variables:

export CLAWCACHE_HOME=/path/to/cache  # Default: ~/.clawcache

Cache Key Specificity

ClawCache supports composite cache keys for better accuracy:

# Cache by prompt + model + temperature
await cache.aset(
    prompt, 
    response, 
    model="gpt-4-turbo",
    temperature=0.7
)

Supported Models (2026 Pricing)

| Model | Input ($/1M tokens) | Output ($/1M tokens) |

|-------|---------------------|----------------------|

| GPT-4 Turbo | $10.00 | $30.00 |

| GPT-3.5 Turbo | $0.50 | $1.50 |

| Claude 3.5 Sonnet | $3.00 | $15.00 |

| Claude 3 Haiku | $0.25 | $1.25 |

💡 Use Cases

1. Code Review Assistant

@async_monitor_cost
async def review_code(code_snippet):
    prompt = f"Review this code for bugs: {code_snippet}"
    return await llm_call(prompt, model="gpt-4-turbo")

2. Data Analysis

@async_monitor_cost
async def analyze_data(dataset):
    prompt = f"Analyze this dataset: {dataset}"
    return await llm_call(prompt, model="claude-3-5-sonnet")

3. Content Generation

@async_monitor_cost
async def generate_content(topic):
    prompt = f"Write a blog post about: {topic}"
    return await llm_call(prompt, model="gpt-3.5-turbo")

📈 Cost Savings Projection

Based on typical usage patterns:

  • Without ClawCache: $0.0062 for 48 calls
  • With ClawCache: $0.0062 for first run, ~$0.0026 for subsequent runs (58% savings)
  • Annual Projection: For 10,000 calls/month → $3,600 saved/year

⭐ Pro Version Coming Soon

Want even more savings and insights? ClawCache Pro will include:

  • 🔮 Semantic Caching: Match similar queries (higher hit rates!)
  • 📊 Advanced Analytics: Detailed cost breakdowns and trends
  • 📈 Visual Reports: Beautiful charts and graphs
  • 🚀 Social Sharing: Share savings on Twitter, LinkedIn, Molbook with auto-generated charts
  • ☁️ Cloud Sync: Sync cache across devices
  • 🎯 Team Analytics: Track costs across your team

Free: Cost tracking with CLI reports + exact-match caching

Pro: Adds social sharing with charts + semantic caching + advanced analytics

Learn more

🤝 Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new features
  4. Submit a pull request

📄 License

MIT License - see LICENSE for details

🔗 Links


Made with ❤️ for the AI community

Save money. Track costs. Build better.

版本历史

共 1 个版本

  • v0.2.0 当前
    2026-05-12 05:52 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-intelligence

self-improving agent

pskoett
捕获经验教训、错误及修正内容,以实现持续改进。适用于以下场景:(1)命令或操作意外失败;(2)用户纠正Claude(如“不,那不对……”“实际上……”);(3)用户请求的功能不存在;(4)外部API或工具出现故障;(5)Claude发现自身
★ 4,071 📥 804,571
developer-tools

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 672 📥 324,922
security-compliance

Skill Vetter

spclaudehome
AI智能体技能安全预审工具。安装ClawdHub、GitHub等来源技能前,检查风险信号、权限范围及可疑模式。
★ 1,223 📥 267,291