Skip to main content

The LLM router that learns — intelligent routing, fallback, circuit breakers, budget tracking, 10+ providers

Project description

ghostrouter

The LLM router that learns. Intelligent routing across 10+ providers, with fallback, circuit breakers, budget tracking, and post-model redaction.

Why

Every project hardcodes model names and API clients. When a model is slow, rate-limited, or refuses a request, the call just fails. ghostrouter routes each call to the best available model automatically — with circuit breakers, fallback chains, and post-model redaction baked in.

Install

pip install ghostrouter

Quick Start

import asyncio
from ghostrouter.config import initialize_controlcore
from ghostrouter.adapters.executor import execute_call
from ghostrouter.schemas import ControlCoreCall, Caller, Intent, Target

# Initialize registries (reads env vars for API keys)
config, model_registry, adapter_registry = initialize_controlcore()

# Build a call
call = ControlCoreCall(
    caller=Caller(handle="my-app", account_id="00000000-0000-0000-0000-000000000000"),
    intent=Intent(**{"class": "lookup"}),           # `class` is aliased; use dict unpacking
    target=Target(type="model", alias="claude"),
    prompt="What is the capital of France?",
)

# Execute with automatic fallback
result, trace = asyncio.run(execute_call(call, model_registry, adapter_registry))
print(result.answer)

Or boot as a daemon and call over HTTP:

ghostrouter serve            # binds to localhost:8265
ghostrouter run claude "Explain recursion"
ghostrouter result <job_id> --poll

Architecture

call → bouncer → eligibility filter → routing → adapter → redaction → result
                                          ↓
                                   circuit breaker
                                          ↓
                                   fallback chain
  1. Routing — scores eligible models by trust tier, cost, and latency history
  2. Eligibility — filters models by intent, verbosity, and determinism requirements
  3. Fallback — tries models in order; switches on timeout, error, refusal, or rate limit
  4. Adapter — thin shim per provider; no shared state between providers
  5. Redaction — applied to model output (not the prompt); strips leaked secrets, emails, phone numbers

Providers

Provider Models
OpenAI GPT-4, GPT-4o, o1, o1-mini
Anthropic Claude Sonnet, Opus, Haiku
Google Gemini 1.5 Pro/Flash, Gemini 2.0
xAI Grok, Grok-2
Mistral Mistral Large/Medium/Small, Codestral
Groq Llama-70B, Llama-8B, Mixtral, Gemma
Together Llama-405B, Qwen-72B, DeepSeek-V3
DeepSeek DeepSeek Chat, Coder, Reasoner
Perplexity Sonar (search-augmented)
Ollama Any local model

Set the relevant *_API_KEY environment variables to enable each provider.

Key Features

  • Circuit breakers — automatically open on repeated failures, recover with half-open probing
  • Trust tiers — models tagged with trust levels; calls can require a minimum tier
  • Post-model redaction — output is scanned and sanitized before returning to caller
  • Execution traces — every call records which models were tried, timings, and outcomes
  • Structured schemas — Pydantic v2 throughout; strict validation at every boundary
  • Async-native — built on httpx + asyncio; runs in Starlette for low overhead

Spine Integration (optional)

ghostrouter supports maelspine for zero-import access to registries across a larger application:

from ghostrouter.boot import boot

core = boot()  # idempotent singleton

# Any module, anywhere:
from spine import Core
registry = Core.instance().get("model_registry")

HTTP API

Method Path Description
POST /call Submit a call
GET /result/{job_id} Poll for result
GET /health Health + job stats
GET /jobs List recent jobs

Part of the GhostLogic Stack

maelspine   — frozen capability registry
ghostrouter   — LLM orchestration gateway  ← you are here
ghostserver — evidence server (Blackbox)

License

Apache-2.0 — Copyright 2026 Adam Thomas / GhostLogic LLC

Project details


Download files

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

Source Distribution

ghostrouter-0.1.1.tar.gz (111.5 kB view details)

Uploaded Source

Built Distribution

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

ghostrouter-0.1.1-py3-none-any.whl (131.0 kB view details)

Uploaded Python 3

File details

Details for the file ghostrouter-0.1.1.tar.gz.

File metadata

  • Download URL: ghostrouter-0.1.1.tar.gz
  • Upload date:
  • Size: 111.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for ghostrouter-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1a4d247269dad25227cc53e371e2dff9ceb842b228d23b6ac71524e48b57a4d9
MD5 1f422da555c77cacfc3ca861adc1f8b4
BLAKE2b-256 c78a6148976dea84996edd0010e9ea09acf8f48855c3723b4fa4b75e5ffbbbf3

See more details on using hashes here.

File details

Details for the file ghostrouter-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ghostrouter-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 131.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for ghostrouter-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3fce967e6592bfae5f42b9b0e1f60bb387b8bbdfe0fc08ee08ee9ee7b7c5dc8b
MD5 65d35e555e86c61a37fb55d5c88aaa3f
BLAKE2b-256 e1bf7cf11b8855a9ef0919c5b8a94bbdb8dba95a9f553a74ac558f1a528b1b74

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page