# ai-router 🚀
Ultra-light AI API Router - Zero deps, single file, auto failover
Have you ever:
- 🤯 An AI API goes down and your app crashes with it
- 😤 Free API quota is exhausted, no auto-fallback to paid
- 🔄 Want to use multiple AI providers without rewriting integration for each
- 📦 Just want to make an API call without installing 500MB of dependencies
ai-router is your answer. One file, zero dependencies, deploy anywhere.
pip install git+https://github.com/longongzi/ai-router.gitOr just download the single file:
curl -O https://raw.githubusercontent.com/longongzi/ai-router/main/ai_router.pyexport DEEPSEEK_API_KEY="sk-your-key-here"
ai-router serveOpenAI-compatible API:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8080/v1", api_key="-")
response = client.chat.completions.create(
model="gpt-4o-mini", # auto-mapped to deepseek-chat
messages=[{"role": "user", "content": "Hello!"}],
)Or curl:
curl http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Hello"}]}'| Feature | Description |
|---|---|
| 🪶 Zero deps | Pure Python stdlib, runs anywhere |
| 🔄 Auto failover | Primary down? Switch to backup |
| 🎯 Model aliases | Drop-in replacement for any OpenAI SDK |
| 🤝 Multi-provider | DeepSeek, OpenClaw, any OpenAI-compatible API |
| ⚡ Streaming | Native SSE streaming |
| 🐳 Single file | One .py, no node_modules, no venv hell |
| 📦 CLI tools | Built-in CLI for testing |
| vs | ai-router | Alternative |
|---|---|---|
| LiteLLM | 1 file, 0 deps | ~50MB deps |
| OpenRouter | Self-hosted | Hosted, privacy concerns |
| Glue code | One solution | Per-project wrappers |
- Local model support (llama.cpp / Ollama)
- Load balancing
- Request caching
- Rate limiting
- Docker image
Every sponsorship fuels continued development 🙏
MIT License © 2026 longongzi
Built with ❤️ and ☕