ClawCache is a production-ready Python library that helps you track every penny spent on LLM APIs and automatically cache responses to slash costs.
Based on comprehensive simulation with 48 API calls across 4 common use cases:
MetricValueCache Hit Rate58.3%Total Cost$0.0062API Calls Saved28 out of 48Scenarios TestedCode Review, Data Analysis, Content Generation, QA Support
ScenarioCallsCache HitsHit RateCode Review12758.3%Data Analysis12866.7%Content Generation12758.3%QA Support12650.0%
bash
pip install clawcache
python
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")
ClawCache automatically tracks all your LLM spending:
bash
# 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
tiktoken when availableClawCache takes security seriously:
Customize ClawCache behavior via environment variables:
bash
export CLAWCACHE_HOME=/path/to/cache # Default: ~/.clawcache
ClawCache supports composite cache keys for better accuracy:
python
# Cache by prompt + model + temperature
await cache.aset(
prompt,
response,
model="gpt-4-turbo",
temperature=0.7
)
ModelInput ($/1M tokens)Output ($/1M tokens)GPT-4 Turbo$10.00$30.00GPT-3.5 Turbo$0.50$1.50Claude 3.5 Sonnet$3.00$15.00Claude 3 Haiku$0.25$1.25
python
@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")
python
@async_monitor_cost
async def analyze_data(dataset):
prompt = f"Analyze this dataset: {dataset}"
return await llm_call(prompt, model="claude-3-5-sonnet")
python
@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")
Based on typical usage patterns:
Want even more savings and insights? ClawCache Pro will include:
Free: Cost tracking with CLI reports + exact-match caching
Pro: Adds social sharing with charts + semantic caching + advanced analytics
Contributions welcome! Please:
MIT License - see LICENSE for details
Made with ❤️ for the AI community
Save money. Track costs. Build better.