Skip to main content

Cut AI API costs by 63-99% with intelligent routing

Project description

APICrusher - Cut AI API Costs by 63-99%

Stop bleeding money on AI APIs. APICrusher automatically routes requests to the cheapest capable model and caches responses, cutting costs by 63-99% with just 2 lines of code.

🚀 Quick Start

pip install apicrusher
# Before (expensive)
from openai import OpenAI
client = OpenAI()

# After (63-99% cheaper)
from apicrusher import OpenAI
client = OpenAI(apicrusher_key="your_key")

That's it. Your code stays the same, your costs drop dramatically.

💰 How Much Can You Save?

Your Current Usage Monthly Cost With APICrusher You Save
GPT-4 for everything $1,000 $180 $820 (82%)
Mixed GPT-4/3.5 $500 $95 $405 (81%)
Heavy API usage $5,000 $750 $4,250 (85%)
Long conversations $2,000 $340 $1,660 (83%)

🎯 Features

Cross-Provider Optimization (NEW in v1.3.0)

Get 99% savings by routing between providers:

from apicrusher import OpenAI

client = OpenAI(
    api_key="sk-...",                    # Your OpenAI key
    anthropic_api_key="sk-ant-...",      # Add Anthropic key (optional)
    google_api_key="...",                # Add Google key (optional)
    apicrusher_key="apc_live_..."    
)

# Simple GPT-4 queries now route to Claude Haiku automatically
# Complex queries stay on GPT-4 to preserve quality

### Universal Provider Support
Works with ALL major AI providers:
- OpenAI (GPT-4, GPT-4o, GPT-3.5, O1)
- Anthropic (Claude 3.5, Claude Opus 4.1)
- Google (Gemini 1.5, Gemini 2.0)
- Groq, Cohere, Meta, Mistral, and more

### Intelligent Model Routing
- Simple queries  Cheap models (gpt-4o-mini)
- Complex queries  Premium models (GPT-4)
- Automatic quality preservation

### Smart Caching
- Deduplicates identical requests
- Redis + in-memory fallback
- 33% average cache hit rate

### 🆕 Context Compression (NEW!)
**Stop paying to reprocess the same conversation 50 times:**

```python
# Enable context compression for long conversations
response = client.chat.completions.create(
    model="gpt-4",
    messages=conversation_history,  # 50 messages = 15,000 tokens normally
    compress_context=True  # Reduces to ~3,000 tokens automatically
)

# Features:
# - Summarizes older messages while preserving key decisions
# - Removes duplicate context automatically  
# - Compresses code blocks by 40-60%
# - Sends only deltas for continuing conversations
# - Preserves last 3 messages in full for accuracy

Context Compression Savings Example:

  • Normal 20-message conversation: 150,000 tokens ($2.25)
  • With compression: 35,000 tokens ($0.52)
  • Savings: 77% on long conversations

Analytics & Reporting

# Get detailed savings report
client.print_savings_summary()

# Output:
# 💸 Total Saved: $127.43
# 📞 Total Calls: 1,432
# 💾 Cache Hit Rate: 34.2%
# ⚡ Optimization Rate: 91.3%

🔧 Advanced Usage

Multi-Provider Setup

from apicrusher import OpenAI

client = OpenAI(
    openai_api_key="sk-...",
    anthropic_api_key="sk-ant-...",
    google_api_key="...",
    apicrusher_key="apc_..."
)

# Automatically routes to cheapest provider
response = client.chat.completions.create(
    model="gpt-4",  # Will use gpt-4o-mini if appropriate
    messages=[{"role": "user", "content": "Format this date: 2024-01-01"}]
)

Context Compression Options

# Fine-tune compression behavior
response = client.chat.completions.create(
    model="gpt-4",
    messages=long_conversation,
    compress_context=True,
    compression_threshold=10,  # Start compressing after 10 messages
    preserve_recent=5  # Keep last 5 messages uncompressed
)

Manual Optimization Control

# Force specific model
response = client.chat.completions.create(
    model="gpt-4o-mini",  # Use this exact model
    messages=messages,
    skip_optimization=True  # Bypass routing logic
)

📊 Real-World Results

Based on actual customer usage:

  • E-commerce company: Reduced costs from $8,400/mo to $1,260/mo (85% savings)
  • SaaS startup: Cut API bills from $3,200/mo to $480/mo (85% savings)
  • AI coding assistant: Dropped from $12,000/mo to $2,400/mo (80% savings)

🛡️ Security & Privacy

  • Your API keys stay local - Never sent to our servers
  • No prompt logging - Your data remains private
  • Open source - Audit the code yourself
  • SOC2 compliant - Enterprise-ready security

🚀 Getting Started

  1. Install: pip install apicrusher
  2. Get your key: Sign up at apicrusher.com
  3. Add 2 lines: Replace your import and add your key
  4. Save money: Watch your costs drop by 63-99%

💰 Pricing

  • Free Trial: 7 days, no credit card required
  • Professional: $99/month (pays for itself in hours)
  • Enterprise: Custom pricing for high-volume usage

Most customers save 10-50x the subscription cost in the first month.

🤝 Support

License

MIT License - Use it however you want.


Stop bleeding money on AI APIs. Start saving with APICrusher today.

Get Your Key →

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apicrusher-1.3.2.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

apicrusher-1.3.2-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file apicrusher-1.3.2.tar.gz.

File metadata

  • Download URL: apicrusher-1.3.2.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for apicrusher-1.3.2.tar.gz
Algorithm Hash digest
SHA256 022512e442a49f6650b89f956ee9d23e22f1095d6a22870c8508d87bff3e5b68
MD5 9ae2a27a2c1d8bb777d99db50e06cf15
BLAKE2b-256 3456f3f1ad87bb87bcea1f168652283e8246f0207e33806d9a19b55bc0cae97b

See more details on using hashes here.

File details

Details for the file apicrusher-1.3.2-py3-none-any.whl.

File metadata

  • Download URL: apicrusher-1.3.2-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for apicrusher-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b850cbf22c982fb5a6986dc843854bc2352b70e84218a50b483b5cc72758b87c
MD5 4301209172ce77ee1a8ec98ce0370679
BLAKE2b-256 a50e4d28488e346e146d7c9319c7ac29df811db3cc6c5674cf24c28784e5c848

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page