llmrouter multi-provider router
909
llmrouter is a programmable OpenAI-compatible router for Large Language Models. It lets you combine multiple providers, fall back gracefully, and cache responses without changing upstream client code.
# install dependencies
pip install -r requirements.txt
# optional: install semantic cache extras (pulls in PyTorch)
pip install -r requirements-semantic.txt
# export provider credentials
export PROVIDER_KEY_GROQ=...
export PROVIDER_KEY_OPENROUTER=...
export PROVIDER_KEY_NVIDIA_NIM=...
export PROVIDER_KEY_HUGGINGFACE=...
# point at the published catalog (or your local one)
export LLMROUTER_MODEL_INDEX_URL="https://raw.githubusercontent.com/schedion/llmrouter/refs/heads/main/generated/model_index.json"
uvicorn app.main:app --reload
Query the API:
# list available canonical models
curl http://localhost:8000/v1/models
# run a chat completion
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-oss-20b",
"messages": [
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "hello"}
]
}'
Semantic caching controls:
LLMROUTER_SEMANTIC_CACHE_ENABLED (false by default)X-LLMRouter-Semantic-Cache: on|offX-LLMRouter-Semantic-Threshold: 0.9sentence-transformers, which pulls in PyTorch. We may switch to an ONNXRuntime-backed embedding loader in the future; if you explore that path, keep the MiniLM model and tokenizer files together and use onnxruntime for inference.Exact-match caching uses LLMROUTER_CACHE_TTL (seconds, 0 disables).
config/model_catalog_seed.yaml.generated/model_index.json) with:
./scripts/build_free_model_catalog.py \
--providers groq,openrouter,nvidia_nim,huggingface \
--output generated/model_index.json --pretty
--providers list.PROVIDER_KEY_GROQ, PROVIDER_KEY_OPENROUTER, PROVIDER_KEY_NVIDIA_NIM, PROVIDER_KEY_HUGGINGFACE.A sample Compose file (docker-compose.sample.yml) mounts named volumes for config, generated data, and the Hugging Face cache. Update the image name and credentials, then run:
docker compose -f docker-compose.sample.yml up -d
Published images:
schedion/llmrouter:slim – no semantic cache dependencies, smallest footprint (multi-arch: linux/amd64, linux/arm64, linux/arm/v7).schedion/llmrouter:latest – includes semantic cache extras (published for linux/amd64 only because PyTorch wheels aren’t available for our other targets).For the arm/v7 build we pull Python wheels from piwheels.org; if you build locally on a Raspberry Pi, keep the same extra index (PIP_EXTRA_INDEX_URL=https://www.piwheels.org/simple) to avoid compiling NumPy from source.
/metrics (suitable for scraping)./metrics/dashboard summarises API traffic and upstream provider status/latency for quick local inspection.python -m compileall app scripts # quick syntax check
pytest # when tests are added
Content type
Image
Digest
sha256:90e677a69…
Size
3.9 GB
Last updated
12 months ago
docker pull schedion/llmrouter