Skip to main content

Provider-agnostic LLM call_tool router with yaml routing, fallback chains, and cost telemetry.

Project description

llm_routerPyPI License: MIT

Provider-agnostic LLM router with YAML routing, auto-failover, cost telemetry, and multi-model support.
One API. Any provider. Zero vendor lock-in.

llm_router is a small Python package (~500 LOC core) that gives you a uniform call_tool() interface across Anthropic, DeepInfra, OpenRouter (30+ models), and more. Define routing rules in YAML — change providers without touching application code. In production since May 2026 powering second-brain-instance.

Why llm_router?

  • 🔀 Multi-provider by default — Anthropic, DeepInfra, OpenRouter. Add more via config.
  • 🛡️ Auto-failover — provider down? Router switches to fallback automatically (circuit breaker)
  • 💰 Cost-aware — route to cheapest available model. Daily budget guard.
  • 📊 Telemetry built-in — every call logged (provider, model, tokens, cost, latency)
  • 📝 YAML-only config — change routing rules without touching code
  • 🇵🇱 Polish-optimized — routing rules aware of PL language quality per model
  • 🧩 Drop-in — replace direct anthropic SDK calls with call_tool(use_case=..., ...)

Quick Start

pip install llm-router
from llm_router import call_tool, set_routing_config

# One-time setup (put in your app's __init__)
set_routing_config('config/llm_routing.yaml')

# Use anywhere — same API regardless of provider
result, usage = call_tool(
    use_case='myapp.feature_x',
    system='You are a helpful assistant.',
    user='Summarize this text: ...',
    schema={'name': 'summarize', 'input_schema': {...}},
)
print(f'${usage.cost_usd:.4f} via {usage.provider}/{usage.model}')

Full walkthrough: docs/INTEGRATION.md (5 min).

Configuration

# config/llm_routing.yaml
providers:
  deepinfra:
    api_key_env: DEEPINFRA_API_KEY
    default_model: Qwen/Qwen3.5-397B-A17B
  openrouter:
    api_key_env: OPENROUTER_API_KEY
    base_url: https://openrouter.ai/api/v1
  anthropic:
    api_key_env: ANTHROPIC_API_KEY

use_cases:
  myapp.feature_x:
    primary: { provider: deepinfra, model: Qwen/Qwen3.5-397B-A17B }
    fallback:
      - { provider: openrouter, model: qwen/qwen3.5-397b-a17b }
      - { provider: anthropic, model: claude-haiku-4-5-20251001 }
    cost_stop_per_call_usd: 0.50

Status

In production — routing all LLM calls for second-brain-instance since May 2026.

  • 30+ calls/day across 11 perspective types
  • DeepInfra Qwen primary, OpenRouter fallback, Anthropic last resort
  • Provider error rate monitored with auto-failover (R4 — in progress)

Documentation

Decision history:

Strategy:

License

MIT © 2026 Eryk Orłowski


Built for second-brain-instance — now open to everyone.

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

exocortex_llm_router-0.1.1.tar.gz (197.1 kB view details)

Uploaded Source

Built Distribution

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

exocortex_llm_router-0.1.1-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: exocortex_llm_router-0.1.1.tar.gz
  • Upload date:
  • Size: 197.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for exocortex_llm_router-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f630492a7005b6cd729453a5520f17091f62959a70c4de0f9f41b500eb04003b
MD5 ced198626b90a88139a1d0dac8984ac4
BLAKE2b-256 347a2a1a34116497f09e291bd4e5e7d68e38775793bf899b69d09c442609e9b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for exocortex_llm_router-0.1.1.tar.gz:

Publisher: publish.yml on hretheum/router

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for exocortex_llm_router-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bba058257f6ed8c78d95e396df78a791eb3d5883b6c2c8c121287305a482d93f
MD5 1bea23c91d214fd677fddf9369ed19c6
BLAKE2b-256 b94bb8c01c884a72f288d789011c24234a0d2d436d709df160c72dcecd404635

See more details on using hashes here.

Provenance

The following attestation bundles were made for exocortex_llm_router-0.1.1-py3-none-any.whl:

Publisher: publish.yml on hretheum/router

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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