Skip to main content

Ignis Router

Intelligent LLM Routing Library for Python

Automatically selects the best language model for every query using ML routers, rule-based intent detection, weighted scoring, and provider fallback.

Python 3.10+ License: MIT Maintained


What is Ignis Router?

Ignis Router is a production-ready Python package that sits between your application and LLM providers. It uses machine learning to predict the optimal model for each query, rule-based intent detection as an intelligent fallback, and automatic provider switching when API keys are unavailable.

Your App → Ignis Router → Best LLM (OpenAI / Anthropic / Gemini) → Response

Why use it?

  • Cost savings — Routes simple queries to cheaper models, complex ones to premium models
  • Quality optimization — ML routers trained on 50k+ examples learn which model performs best for which query type
  • Zero downtime — Automatic fallback when a provider is unavailable
  • Full observability — Every routing decision is logged with correlation IDs

Key Features

Feature Description
🧠 ML-Based Routing 4 router types (KNN, SVM, Graph, MF) predict the best LLM model
🎯 Intent Detection Hybrid semantic + rule-based classification (code, summarization, reasoning, etc.)
🔄 Provider Fallback Auto-switches to available provider when API key is missing
4 Strategies Quality-first, cost-first, latency-first, balanced — configurable via YAML
🛠️ Decorators @route(), @chat(), @with_router(), @retry()
🌐 REST API FastAPI with Swagger UI, feature toggles, metrics
📊 Dashboard Streamlit dashboard for routing analytics
🗄️ PostgreSQL Automatic persistence of every routing decision
📝 Structured Logging JSON logs with correlation IDs and crash tracebacks
🔀 Feature Flags Toggle routing behavior at runtime without restart

Installation

pip install git+https://github.com/Infogain-GenAI/ignis_router.git@main
Optional extras
pip install "ignis_router[all]"         # All LLM providers
pip install "ignis_router[dashboard]"   # Streamlit dashboard
pip install "ignis_router[dev]"         # Development tools

Quick Start

1. Create .env

OPENAI_API_KEY=sk-your-key-here
ML_ROUTER_TYPE=svm
ENABLE_ML_MODEL_HINT_ROUTING=true

2. Route + Call LLM

from ignis_router import chat

@chat(system_prompt="You are a helpful assistant")
def ask(query, response):
    rd = response["routing_decision"]
    print(f"ML Predicted:  {rd['ml_router_predicted']}")
    print(f"Final Model:   {rd['final_model']}")
    print(f"Intent:        {rd['intent']}")
    print(f"Response:      {response['content'][:100]}")
    return response

ask("Write a Python function to sort a list")

3. Output

ML Predicted:  qwen2.5-7b-instruct
Final Model:   gpt-4.1-2025-04-14 (openai)
Intent:        code_generation
Response:      Here's a Python sorting function...

Usage Options

Decorators (simplest)

from ignis_router import route, chat

@route()
def handle(query, routing_result, routing_decision):
    return routing_decision["final_model"]

@chat()
def ask(query, response):
    return response["content"]

Direct Python API

from ignis_router import Router

router = Router()
router.register_supported_models()
router.register_default_intent_rules()
router.enable_llm_clients()

response = router.chat("Explain quantum computing")
print(response["content"])

REST API

python -m ignis_router.api.run_api
# Server: http://127.0.0.1:8080
# Swagger: http://127.0.0.1:8080/docs
curl -X POST http://localhost:8080/chat \
  -H "Content-Type: application/json" \
  -d '{"query": "Write Python code for sorting"}'

SDK Client

from ignis_router import IgnisClient

with IgnisClient("http://127.0.0.1:8080") as client:
    result = client.chat("Write Python code")
    print(result.content)

How It Works

User Query: "Write a Python API with authentication"
     │
     ▼
┌─ Intent Detection ────────────────────────────┐
│  Semantic ML → confidence 0.92 → code_gen     │
└───────────────────────────────────────────────┘
     │
     ▼
┌─ ML Router (SVM) ────────────────────────────┐
│  Predicts: qwen2.5-7b-instruct               │
└───────────────────────────────────────────────┘
     │
     ▼
┌─ Provider Check ─────────────────────────────┐
│  qwen2.5 → No API key → Fallback to OpenAI  │
└───────────────────────────────────────────────┘
     │
     ▼
┌─ LLM Call ───────────────────────────────────┐
│  gpt-4.1 (OpenAI) → AI Response             │
└───────────────────────────────────────────────┘
     │
     ▼
┌─ Persistence ────────────────────────────────┐
│  PostgreSQL + JSON Logs + Correlation IDs     │
└───────────────────────────────────────────────┘

ML Routers

Four pre-trained routers from LLMRouter (open-source, UIUC):

Router Inference Accuracy Best For
SVM 12 ms 91.2% Production SaaS, low latency
KNN 45 ms 88.4% Startups, explainability
Graph 78 ms 93.8% Enterprise, complex domains
MF 52 ms 89.6% Multi-tenant, personalization
ML_ROUTER_TYPE=svm  # or knn, graph, mf

API Endpoints

Method Path Description
GET /health Health check
GET /docs Swagger UI
POST /route Route query → model, strategy, confidence
POST /chat Route + LLM → AI response + routing decision
GET /metrics?days=N Routing metrics
GET /dashboard?days=N Full dashboard data
GET /features Feature flag states
PUT /features/{key} Toggle features at runtime

Dashboard

pip install "ignis_router[dashboard]"
python -m streamlit run examples/streamlit_dashboard.py

Visual analytics: KPIs, model distribution, confidence histograms, per-model performance, routing log.


Configuration

Variable Default Description
OPENAI_API_KEY OpenAI API key
ANTHROPIC_API_KEY Anthropic API key
GOOGLE_API_KEY Google Gemini API key
ML_ROUTER_TYPE knn Router: knn, svm, graph, mf
ROUTER_YAML_CONFIG Strategy YAML path
ENABLE_ML_MODEL_HINT_ROUTING false Enable ML model prediction
ML_CONFIDENCE_THRESHOLD 0.60 Fallback threshold
ROUTER_DB_PASSWORD postgres PostgreSQL password

See user_guide.md for the full environment variable reference.


Documentation

Resource Description
User Guide Complete setup, configuration, and usage documentation
Swagger UI Interactive API explorer (when API is running)
Examples Sample scripts (AI chat, routing with DB, Streamlit dashboard)

Project Structure

src/ignis_router/
├── api/           # FastAPI REST service + SDK client
├── configs/       # Routing strategy YAMLs + ML router configs
├── core/          # Router, routing engine, model selector
├── data/          # Intent training data
├── db/            # PostgreSQL persistence
├── detection/     # Intent detection (semantic + rule-based)
├── evaluation/    # Metrics, dashboard, reports
├── llm/           # LLM provider clients (OpenAI, Anthropic, Gemini)
├── ml/            # LLMRouter integration + ML inference
├── models/        # Pre-trained ML router models (.pkl, .pt)
└── scripts/       # Training scripts

Development

git clone https://github.com/Infogain-GenAI/ignis_router.git
cd ignis_router
pip install -e ".[dev,all,dashboard]"
python -m pytest tests/ -v

License

This project is licensed under the MIT License — see LICENSE for details.


Built by Infogain GenAI

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ignis_router-0.2.0.tar.gz (31.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ignis_router-0.2.0-py3-none-any.whl (32.3 MB view details)

Uploaded Python 3

File details

Details for the file ignis_router-0.2.0.tar.gz.

File metadata

  • Download URL: ignis_router-0.2.0.tar.gz
  • Upload date:
  • Size: 31.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.8

File hashes

Hashes for ignis_router-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b921c88fd9f1366543c9d4b159ec11b071e9756445f706d0e13203828c2faded
MD5 a4093823dbbf8aaf65f5d1126731323a
BLAKE2b-256 be9b263cb60210810452233ccb85bfc79b8663761fe61ec41d6e2570c5329a10

See more details on using hashes here.

File details

Details for the file ignis_router-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: ignis_router-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 32.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.8

File hashes

Hashes for ignis_router-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d06000fd7cd4bd5b6ad64d9d3905c31c38b6e58114d580e6a03a3622b3d208cc
MD5 dfe8268dd23ea2473be3035a4aac81e4
BLAKE2b-256 11168abe69671b4659f734de8f233bc5c1c8a01376046703afd6c83dc0f695f9

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.0

2 files

0.3.0

2 files

This release

0.2.0 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page