LLMSwitch
Free-tier AI provider router for developers. Write AI code once; LLMSwitch handles provider fallback across Groq, OpenRouter, NVIDIA, and more.
Install
pip install ai-switch
The distribution is named ai-switch; the import stays llmswitch.
Configure
Set an API key for any provider you want LLMSwitch to use — it only tries providers with a key present:
export GROQ_API_KEY="..."
export OPENROUTER_API_KEY="..."
export NVIDIA_API_KEY="..."
Usage
from llmswitch import AIClient
client = AIClient()
response = client.chat("Write a Python web scraper")
print(response)
Providers are tried in order (Groq, OpenRouter, NVIDIA by default). If one is rate-limited, unreachable, or errors, LLMSwitch automatically falls back to the next.
Model names
model accepts either a friendly alias ("fast-model", "smart-model" — see llmswitch/registry.py) that's resolved per-provider, or a raw provider-specific model name passed straight through:
client.chat("hello", model="fast-model")
client.chat("hello", model="llama-3.1-8b-instant") # Groq-specific name
Health tracking
LLMSwitch remembers which providers just failed, so a rate-limited provider isn't retried on every call — it's rested and moved to the back of the queue:
client.chat("hi") # groq is rate-limited -> falls back to openrouter
client.chat("hi") # groq skipped entirely; openrouter served directly
Cooldowns respect the provider's own Retry-After header when present, and otherwise back off exponentially (60s, 120s, 240s… capped at 15 min for rate limits; shorter for transient outages). A success clears the streak.
If every provider is resting, LLMSwitch still tries them — closest-to-recovery first — rather than failing without an attempt.
Inspect current state at any time:
client.status()
# {'groq': {'available': False, 'cooldown_remaining': 57.0, ...},
# 'openrouter': {'available': True, 'total_successes': 2, ...}}
Choosing providers explicitly
from llmswitch import AIClient
from llmswitch.providers import GroqProvider, NVIDIAProvider
client = AIClient(providers=[GroqProvider(), NVIDIAProvider()])
See examples/ for more.
Tests
pip install -e ".[dev]"
pytest
Status
Pre-release (v0.1, MVP). See roadmap.md and todo.md for current progress.
Metadata
Release files for ai-switch 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ai_switch-0.2.0.tar.gz | 13.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ai_switch-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.0 kB
Release files / ai_switch-0.2.0.tar.gz
| Download URL | ai_switch-0.2.0.tar.gz |
|---|---|
| Size | 13.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
14be840d73c64e84881b0a3598dd6466e4d90d5b1d6863b7d30dd24badca4b17
|
|
BLAKE2b-256 checksum How to use checksums |
c545420ff0bc91a44adf69b059e7b4312d3e27641fb18c861e59ef614dff7929
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
ai-switch-uploader/1.0
|
Release files / ai_switch-0.2.0-py3-none-any.whl
| Download URL | ai_switch-0.2.0-py3-none-any.whl |
|---|---|
| Size | 11.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ef53aa88a2e52f996f6ad9227c0f17bdec8e3f4970e5ed3db0451d64526aa31b
|
|
BLAKE2b-256 checksum How to use checksums |
6a95594d51e13bb5bd9ac101b7957c16710d6e65869b6beaa14f5b9b305031ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
ai-switch-uploader/1.0
|