Skip to main content

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

Project description

ghostrouter

English · 中文 · 日本語 · 한국어 · Русский · Deutsch

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.2.0.tar.gz (112.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.2.0-py3-none-any.whl (131.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ghostrouter-0.2.0.tar.gz
  • Upload date:
  • Size: 112.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.2.0.tar.gz
Algorithm Hash digest
SHA256 47b27ab40755279954d039827ca6c7adb10f1325669aaa4e5743bbcb6c9d857b
MD5 30d70ff3d4a86f88c888a0fad22365bd
BLAKE2b-256 b24410a0924cbc15b7b2c559f85c80f81c999beacca905ca50936dcd96dcd24a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ghostrouter-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 131.8 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 857cd2b7fd40e65b73991d70c846e602f572bde78454d33ef91045740df933ee
MD5 4c7e1709518db7c82c8fdc84e0b5ee81
BLAKE2b-256 b31b63dd3a2bb6b601b1cb45c813b1c1e228fb2bb2923cd99948dd02ccdad5fa

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