# APICrusher Lite
Open source AI model router that automatically reduces API costs by routing simple queries to cheaper models.
## The Problem
You're using GPT-5 or Claude Opus 4.1 for everything. Even for tasks like:
- Formatting JSON
- Extracting emails from text
- Basic string operations
- Simple yes/no questions
That's like hiring a brain surgeon to apply band-aids.
## The Solution
This lightweight router analyzes query complexity and automatically routes simple requests to cheaper models while preserving quality for complex tasks.
```python
# Before: Everything goes to expensive models
response = openai.chat.completions.create(
model="gpt-5", # $1.25/$10 per million tokens (input/output)
messages=[{"role": "user", "content": "Extract the email from: Contact john@example.com"}]
)
# After: Simple tasks use cheaper models automatically
from apicrusher_lite import Router
router = Router()
model = router.route("gpt-5", messages) # Returns "gpt-5-nano" for simple tasks
response = openai.chat.completions.create(model=model, messages=messages)
```
## Installation
```bash
pip install apicrusher-lite
```
## Basic Usage
```python
from apicrusher_lite import Router
# Initialize router
router = Router()
# Your messages
messages = [
{"role": "user", "content": "What's the capital of France?"}
]
# Get optimal model for this query
optimal_model = router.route("gpt-5", messages)
print(f"Using {optimal_model} instead of gpt-5") # "Using gpt-5-nano instead of gpt-5"
# Use with your existing OpenAI code
import openai
response = openai.chat.completions.create(
model=optimal_model,
messages=messages
)
```
## How It Works
The router analyzes your messages for complexity indicators:
- Length and structure
- Code blocks
- Data processing requirements
- Reasoning complexity
- Output format requirements
Simple queries (complexity < 0.3) get routed to cheaper models.
## Supported Model Mappings (September 2025)
| Original Model | Simple Task Routes To | Original Cost | Optimized Cost | Savings |
|---------------|----------------------|---------------|----------------|---------|
| gpt-5 | gpt-5-nano | $1.25/$10 | $0.05/$0.40 | 96% |
| gpt-5-turbo | gpt-5-nano | $0.60/$2.40 | $0.05/$0.40 | 92% |
| claude-opus-4.1 | claude-3-haiku | $15/$75 | $0.25/$1.25 | 98% |
| claude-sonnet-4 | claude-3-haiku | $3/$15 | $0.25/$1.25 | 92% |
| gemini-2.5-pro | gemini-2.5-flash-lite | $1.25/$5 | $0.10/$0.40 | 92% |
| grok-4 | grok-3-mini | $3/$15 | $1/$3 | 67% |
*Costs shown as input/output per million tokens*
## Examples
```python
# Example 1: Simple extraction (routes to nano/mini model)
messages = [{"role": "user", "content": "Extract the date: Meeting on Jan 15, 2025"}]
model = router.route("gpt-5", messages) # Returns "gpt-5-nano"
# Example 2: Complex reasoning (keeps original model)
messages = [{"role": "user", "content": "Analyze this code for security vulnerabilities and suggest improvements: [500 lines of code]"}]
model = router.route("gpt-5", messages) # Returns "gpt-5"
# Example 3: Check complexity score
complexity = router.analyze_complexity(messages)
print(f"Complexity: {complexity}") # 0.1 for simple, 0.9 for complex
```
## Testing
Run the test suite to verify functionality:
```bash
# Install development dependencies
pip install -r requirements.txt
# Run tests
python -m pytest tests/
# Or run specific test
python tests/test_router.py
```
The test suite includes:
- Simple query routing validation
- Complex query preservation tests
- Complexity analysis verification
- Model mapping accuracy checks
## Development
```bash
# Clone the repository
git clone https://github.com/apicrusher/apicrusher-lite.git
cd apicrusher-lite
# Install in development mode
pip install -e .
# Run tests
python -m pytest tests/
```
## Limitations
This is the basic open-source router. It does NOT include:
- ❌ Real-time model pricing updates
- ❌ Response caching
- ❌ Cross-provider routing (GPT→Claude)
- ❌ Usage analytics
- ❌ Context compression
- ❌ Automatic fallback for deprecated models
## Want 73-99% Cost Savings?
This lite version provides basic routing within the same provider.
For enterprise features including:
- ✅ Real-time optimization rules updated daily
- ✅ Intelligent caching (30% hit rate)
- ✅ Cross-provider routing (route GPT-5 queries to Claude Haiku)
- ✅ Analytics dashboard with ROI tracking
- ✅ Context compression (77% token reduction)
- ✅ Model deprecation handling
Check out **[APICrusher Pro](https://apicrusher.com)** - from $99/month with a 7-day free trial.
## Basic Router Implementation
```python
class Router:
def __init__(self):
self.model_map = {
"gpt-5": "gpt-5-nano",
"gpt-5-turbo": "gpt-5-nano",
"gpt-4": "gpt-4o-mini",
"claude-opus-4.1-20250805": "claude-3-haiku-20240307",
"claude-sonnet-4-20250222": "claude-3-haiku-20240307",
# ... more mappings
}
def analyze_complexity(self, messages):
# Basic complexity analysis
text = str(messages)
complexity = 0.1
if len(text) > 500: complexity += 0.3
if "```" in text: complexity += 0.3 # Has code
if any(word in text.lower() for word in ['analyze', 'explain', 'complex']):
complexity += 0.3
return min(complexity, 1.0)
def route(self, model, messages):
complexity = self.analyze_complexity(messages)
if complexity < 0.3 and model in self.model_map:
return self.model_map[model]
return model
```
## Contributing
We welcome contributions! Please:
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Make your changes
4. Add tests for new functionality
5. Ensure tests pass (`python -m pytest tests/`)
6. Commit your changes (`git commit -m 'Add amazing feature'`)
7. Push to the branch (`git push origin feature/amazing-feature`)
8. Open a Pull Request
## License
MIT License - See [LICENSE](LICENSE) for details.
## Support
- GitHub Issues: [github.com/apicrusher/apicrusher-lite/issues](https://github.com/apicrusher/apicrusher-lite/issues)
- Email: hello@apicrusher.com
## Disclaimer
This tool is provided as-is. Always test with your specific use cases. Some complex queries incorrectly routed to simple models may produce lower quality results.
---
*Built by developers who were spending $8k/month on uppercase conversions. We learned our lesson.*
Raw data
{
"_id": null,
"home_page": "https://github.com/apicrusher/apicrusher-lite",
"name": "apicrusher-lite",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "ai api cost optimization routing openai anthropic llm",
"author": "APICrusher",
"author_email": "hello@apicrusher.com",
"download_url": "https://files.pythonhosted.org/packages/1c/cc/b9b03d2623c601bffbe0ff46aca821bef0d937da60e3a325b8ce1dfff737/apicrusher_lite-1.0.0.tar.gz",
"platform": null,
"description": "# APICrusher Lite\n\nOpen source AI model router that automatically reduces API costs by routing simple queries to cheaper models.\n\n## The Problem\n\nYou're using GPT-5 or Claude Opus 4.1 for everything. Even for tasks like:\n- Formatting JSON\n- Extracting emails from text\n- Basic string operations\n- Simple yes/no questions\n\nThat's like hiring a brain surgeon to apply band-aids.\n\n## The Solution\n\nThis lightweight router analyzes query complexity and automatically routes simple requests to cheaper models while preserving quality for complex tasks.\n\n```python\n# Before: Everything goes to expensive models\nresponse = openai.chat.completions.create(\n model=\"gpt-5\", # $1.25/$10 per million tokens (input/output)\n messages=[{\"role\": \"user\", \"content\": \"Extract the email from: Contact john@example.com\"}]\n)\n\n# After: Simple tasks use cheaper models automatically\nfrom apicrusher_lite import Router\n\nrouter = Router()\nmodel = router.route(\"gpt-5\", messages) # Returns \"gpt-5-nano\" for simple tasks\nresponse = openai.chat.completions.create(model=model, messages=messages)\n```\n\n## Installation\n\n```bash\npip install apicrusher-lite\n```\n\n## Basic Usage\n\n```python\nfrom apicrusher_lite import Router\n\n# Initialize router\nrouter = Router()\n\n# Your messages\nmessages = [\n {\"role\": \"user\", \"content\": \"What's the capital of France?\"}\n]\n\n# Get optimal model for this query\noptimal_model = router.route(\"gpt-5\", messages)\nprint(f\"Using {optimal_model} instead of gpt-5\") # \"Using gpt-5-nano instead of gpt-5\"\n\n# Use with your existing OpenAI code\nimport openai\nresponse = openai.chat.completions.create(\n model=optimal_model,\n messages=messages\n)\n```\n\n## How It Works\n\nThe router analyzes your messages for complexity indicators:\n- Length and structure\n- Code blocks\n- Data processing requirements\n- Reasoning complexity\n- Output format requirements\n\nSimple queries (complexity < 0.3) get routed to cheaper models.\n\n## Supported Model Mappings (September 2025)\n\n| Original Model | Simple Task Routes To | Original Cost | Optimized Cost | Savings |\n|---------------|----------------------|---------------|----------------|---------|\n| gpt-5 | gpt-5-nano | $1.25/$10 | $0.05/$0.40 | 96% |\n| gpt-5-turbo | gpt-5-nano | $0.60/$2.40 | $0.05/$0.40 | 92% |\n| claude-opus-4.1 | claude-3-haiku | $15/$75 | $0.25/$1.25 | 98% |\n| claude-sonnet-4 | claude-3-haiku | $3/$15 | $0.25/$1.25 | 92% |\n| gemini-2.5-pro | gemini-2.5-flash-lite | $1.25/$5 | $0.10/$0.40 | 92% |\n| grok-4 | grok-3-mini | $3/$15 | $1/$3 | 67% |\n\n*Costs shown as input/output per million tokens*\n\n## Examples\n\n```python\n# Example 1: Simple extraction (routes to nano/mini model)\nmessages = [{\"role\": \"user\", \"content\": \"Extract the date: Meeting on Jan 15, 2025\"}]\nmodel = router.route(\"gpt-5\", messages) # Returns \"gpt-5-nano\"\n\n# Example 2: Complex reasoning (keeps original model) \nmessages = [{\"role\": \"user\", \"content\": \"Analyze this code for security vulnerabilities and suggest improvements: [500 lines of code]\"}]\nmodel = router.route(\"gpt-5\", messages) # Returns \"gpt-5\"\n\n# Example 3: Check complexity score\ncomplexity = router.analyze_complexity(messages)\nprint(f\"Complexity: {complexity}\") # 0.1 for simple, 0.9 for complex\n```\n\n## Testing\n\nRun the test suite to verify functionality:\n\n```bash\n# Install development dependencies\npip install -r requirements.txt\n\n# Run tests\npython -m pytest tests/\n\n# Or run specific test\npython tests/test_router.py\n```\n\nThe test suite includes:\n- Simple query routing validation\n- Complex query preservation tests \n- Complexity analysis verification\n- Model mapping accuracy checks\n\n## Development\n\n```bash\n# Clone the repository\ngit clone https://github.com/apicrusher/apicrusher-lite.git\ncd apicrusher-lite\n\n# Install in development mode\npip install -e .\n\n# Run tests\npython -m pytest tests/\n```\n\n## Limitations\n\nThis is the basic open-source router. It does NOT include:\n- \u274c Real-time model pricing updates\n- \u274c Response caching\n- \u274c Cross-provider routing (GPT\u2192Claude)\n- \u274c Usage analytics\n- \u274c Context compression\n- \u274c Automatic fallback for deprecated models\n\n## Want 73-99% Cost Savings?\n\nThis lite version provides basic routing within the same provider. \n\nFor enterprise features including:\n- \u2705 Real-time optimization rules updated daily\n- \u2705 Intelligent caching (30% hit rate)\n- \u2705 Cross-provider routing (route GPT-5 queries to Claude Haiku)\n- \u2705 Analytics dashboard with ROI tracking\n- \u2705 Context compression (77% token reduction)\n- \u2705 Model deprecation handling\n\nCheck out **[APICrusher Pro](https://apicrusher.com)** - from $99/month with a 7-day free trial.\n\n## Basic Router Implementation\n\n```python\nclass Router:\n def __init__(self):\n self.model_map = {\n \"gpt-5\": \"gpt-5-nano\",\n \"gpt-5-turbo\": \"gpt-5-nano\", \n \"gpt-4\": \"gpt-4o-mini\",\n \"claude-opus-4.1-20250805\": \"claude-3-haiku-20240307\",\n \"claude-sonnet-4-20250222\": \"claude-3-haiku-20240307\",\n # ... more mappings\n }\n \n def analyze_complexity(self, messages):\n # Basic complexity analysis\n text = str(messages)\n complexity = 0.1\n \n if len(text) > 500: complexity += 0.3\n if \"```\" in text: complexity += 0.3 # Has code\n if any(word in text.lower() for word in ['analyze', 'explain', 'complex']):\n complexity += 0.3\n \n return min(complexity, 1.0)\n \n def route(self, model, messages):\n complexity = self.analyze_complexity(messages)\n \n if complexity < 0.3 and model in self.model_map:\n return self.model_map[model]\n \n return model\n```\n\n## Contributing\n\nWe welcome contributions! Please:\n\n1. Fork the repository\n2. Create a feature branch (`git checkout -b feature/amazing-feature`)\n3. Make your changes\n4. Add tests for new functionality\n5. Ensure tests pass (`python -m pytest tests/`)\n6. Commit your changes (`git commit -m 'Add amazing feature'`)\n7. Push to the branch (`git push origin feature/amazing-feature`)\n8. Open a Pull Request\n\n## License\n\nMIT License - See [LICENSE](LICENSE) for details.\n\n## Support\n\n- GitHub Issues: [github.com/apicrusher/apicrusher-lite/issues](https://github.com/apicrusher/apicrusher-lite/issues)\n- Email: hello@apicrusher.com\n\n## Disclaimer\n\nThis tool is provided as-is. Always test with your specific use cases. Some complex queries incorrectly routed to simple models may produce lower quality results.\n\n---\n\n*Built by developers who were spending $8k/month on uppercase conversions. We learned our lesson.*\n",
"bugtrack_url": null,
"license": null,
"summary": "Basic AI model router for cost optimization",
"version": "1.0.0",
"project_urls": {
"Homepage": "https://github.com/apicrusher/apicrusher-lite"
},
"split_keywords": [
"ai",
"api",
"cost",
"optimization",
"routing",
"openai",
"anthropic",
"llm"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "51d158bbbca1084b457fd1d7ef2352e4dedf2829599f5613ea677f01688c1dc0",
"md5": "9223e1e126feaf77f433967568fa67fd",
"sha256": "16e895c29139e68d8eda23e4f380866d6394eb91106f067d9a2955ed4a0b5730"
},
"downloads": -1,
"filename": "apicrusher_lite-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9223e1e126feaf77f433967568fa67fd",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 4943,
"upload_time": "2025-09-12T19:08:21",
"upload_time_iso_8601": "2025-09-12T19:08:21.402785Z",
"url": "https://files.pythonhosted.org/packages/51/d1/58bbbca1084b457fd1d7ef2352e4dedf2829599f5613ea677f01688c1dc0/apicrusher_lite-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "1cccb9b03d2623c601bffbe0ff46aca821bef0d937da60e3a325b8ce1dfff737",
"md5": "3065529f0010275b3fe119f743346217",
"sha256": "aecc4ca8c6a8962eb25d567d77fb6de3a067bbe018ee686b78c104dbdc34bbd4"
},
"downloads": -1,
"filename": "apicrusher_lite-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "3065529f0010275b3fe119f743346217",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 5079,
"upload_time": "2025-09-12T19:08:22",
"upload_time_iso_8601": "2025-09-12T19:08:22.621264Z",
"url": "https://files.pythonhosted.org/packages/1c/cc/b9b03d2623c601bffbe0ff46aca821bef0d937da60e3a325b8ce1dfff737/apicrusher_lite-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-12 19:08:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "apicrusher",
"github_project": "apicrusher-lite",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "requests",
"specs": [
[
">=",
"2.28.0"
]
]
}
],
"lcname": "apicrusher-lite"
}