A robust Python system that automatically switches between multiple free AI API providers for reliable chat completions and text generation. Never worry about rate limits or downtime again!
- 🔄 Automatic Fallback: Seamlessly switches providers when one fails or hits limits
- 📊 Usage Tracking: Monitors daily usage across all providers
- ⚡ Exponential Backoff: Smart retry logic to handle temporary failures
- 🔧 Modular Design: Clean, maintainable code split across multiple files
- 📈 Real-time Stats: Monitor API consumption and performance
- 🛡️ Robust Error Handling: Comprehensive logging and graceful failures
| Provider | Daily Limit | Speed | Models |
|---|---|---|---|
| Groq | 1,000 requests | ⚡ Fastest | Llama 3.3 70B |
| Cerebras | 1M tokens | 🚀 High throughput | Llama 3.3 70B |
| OpenRouter | 200 requests | 🔀 Multi-model | Various free |
| Together AI | 500 requests | 🤝 Open source | Llama variants |
| Mistral | 200 requests | 🇫🇷 European | Mistral 7B |
| HuggingFace | 1,000 requests | 🤗 Community | Llama 3.3 70B |
| Fireworks | 500 requests | 🎆 Fast inference | Llama variants |
git clone https://github.com/pratikm778/Free-API-setup.git
cd Free-API-setuppip install -r requirements.txtcp .env.example .env
# Edit .env and add your API keyspython test_providers.pypython example.pycascading-ai-flow/
├── cascade.py # Main cascading API client
├── providers.py # Provider configurations
├── usage_tracker.py # Usage tracking functionality
├── utils.py # Utility functions
├── config.py # Settings and configuration
├── example.py # Usage examples
├── test_providers.py # Provider testing script
├── requirements.txt # Dependencies
├── .env.example # Environment variables template
└── README.md # This file
from cascade import CascadingAPIClient
# Initialize client (uses all available providers)
client = CascadingAPIClient()
# Send a message
messages = [
{"role": "user", "content": "What is machine learning?"}
]
response = client.chat_completion(messages)
print(response)Get free API keys from these providers:
| Provider | Signup Link | Notes |
|---|---|---|
| Groq | console.groq.com | Fastest inference |
| Cerebras | inference.cerebras.ai | High throughput |
| OpenRouter | openrouter.ai | Multiple models |
| Together AI | api.together.ai | Open source focus |
| Mistral | console.mistral.ai | European provider |
| HuggingFace | huggingface.co | Community models |
| Fireworks | fireworks.ai | Fast inference |
💡 Tip: You don't need all keys! Start with 2-3 providers and add more later.
# Test all providers
python test_providers.py
# Quick test (individual providers only)
python test_providers.py --quickfrom cascade import CascadingAPIClient
client = CascadingAPIClient()
# Custom parameters
response = client.chat_completion(
messages=messages,
max_tokens=500,
temperature=0.8,
max_retries=3
)
# Get usage statistics
stats = client.get_usage_stats()
print(stats)Edit config.py to customize:
- Logging levels and file locations
- Default API parameters
- Retry and backoff settings
- Usage tracking options
The system automatically:
- Tracks daily usage in
usage_tracking.json - Logs all activity to
cascade_api.log - Resets usage counters daily
- Provides real-time statistics
No providers available
- Check API keys in
.envfile - Run
python test_providers.pyto verify setup
Rate limit errors
- System handles automatically with backoff
- Check usage with
client.get_usage_stats()
API errors
- Check
cascade_api.logfor detailed errors - Verify model names are correct
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - use freely in your projects!
Thanks to all AI providers offering free tiers and the developer community for inspiration.
⭐ Star this repo if it helps you! ⭐