Skip to main content

In-process Rust router for LLM providers. Hedged-parallel + 429/5xx hot-swap < 1ms. Composes with hosted gateways like llmkit.

Project description

f3dx-router

OpenSSF Scorecard

LiteLLM is the incumbent Python router. It works but it's slow (~500us mean overhead per call by their own troubleshooting docs), and the Hono / Cloudflare gateways like Helicone went into maintenance mode in March 2026 after the Mintlify acquisition. The in-process Rust hot path is the gap.

f3dx-router is what you import inside an agent loop when the network hop to a hosted gateway is too expensive. It composes with hosted billing/dashboard products like llmkit instead of competing with them: same SDK, two backends. Local f3dx-router for the sub-millisecond hot path; llmkit for the cost dashboard. Or both.

pip install f3dx-router
from f3dx_router import Router

r = Router(
    providers=[
        {"name": "openai", "kind": "openai",
         "base_url": "https://api.openai.com/v1",
         "api_key": "sk-..."},
        {"name": "groq", "kind": "openai",
         "base_url": "https://api.groq.com/openai/v1",
         "api_key": "gsk_..."},
    ],
    policy="hedged",
    hedge_k=2,
)

response = r.chat_completions({
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "hi"}],
})
print(response["choices"][0]["message"]["content"])

Routing policies

Policy What it does Cost vs latency
sequential Fire to providers in order; on 429 / 5xx / timeout fall through to the next Lowest cost, highest latency on failures
hedged Fire to top-K in parallel; return first non-error, cancel the rest Higher cost, latency = min over K

V0.1 adds weighted (round-robin with per-provider weights) and the killer feature: schema-pass-rate sliding window classifier wired to f3dx-trace, routing away from a degrading provider automatically. Track validation-failure-rate per (provider, tenant, model) over the last N requests; if it crosses a threshold, drop that provider's weight to zero until the rate recovers.

Failure model

Status Class Behavior
2xx success Return the body
408 / 429 / 5xx soft Try the next provider in the policy
4xx (other) hard Surface immediately - retrying elsewhere with the same payload makes things worse
Connection reset, timeout soft Same as 5xx

The hard-failure short-circuit matters: routing a 401 (bad API key) to the next provider just leaks the same bad key to a second vendor.

Architecture

f3dx-router/
  crates/
    f3dx-router/      core: Provider, RouterConfig, Router (Rust)
    f3dx-router-py/   PyO3 bridge cdylib (the only crate with #[pymodule])
  python/
    f3dx_router/__init__.py  Router class wrapping the native PyO3 surface

Connection pooling via reqwest's per-host pool (16 idle conns / host). Tokio runtime constructed once at Router instantiation; every chat_completions call reuses it under py.allow_threads so concurrent callers don't deadlock on the GIL.

Composes with llmkit

llmkit at llmkit.sh is the hosted gateway: TypeScript on Cloudflare Workers, OpenAI / Anthropic / Gemini provider abstraction, budget enforcement, cost dashboards, npm + PyPI SDKs. The clean separation:

  • llmkit: hosted, multi-tenant, billing, dashboards, audit logs. Network hop required.
  • f3dx-router: in-process, single-tenant, sub-ms swap. No network hop.

You can use both: f3dx-router as the local hot path with llmkit configured as one of its providers for the cost-tracking sink. Best of both.

What this is not

f3dx-router is not a hosted gateway. Use llmkit, Helicone, Portkey, or OpenRouter for that.

f3dx-router is not LiteLLM. LiteLLM has 100+ provider adapters; this V0 has two (OpenAI-shape, Anthropic-shape). The differentiator is in-process latency, not provider coverage.

f3dx-router is not a multi-region failover system. Region awareness lives in your provider config; the router just picks among configured providers.

Sibling projects

  • f3dx: Rust runtime your Python imports. Drop-in for openai + anthropic SDKs. Native SSE streaming, agent loop with concurrent tool dispatch, OTel emission.
  • f3dx-cache: Content-addressable LLM response cache + replay. Zero-cost CI runs against captured prod traces.
  • pydantic-cal: Calibration metrics for pydantic-evals. ECE, Brier, reliability diagrams, Fisher-Rao geometry.

Roadmap

Version What
v0.0.1 Sequential + hedged policies, OpenAI + Anthropic provider kinds, 429/5xx soft-failure routing
v0.0.2 Weighted round-robin, per-provider rate-limit budgets via token-bucket
v0.1.0 Schema-pass-rate sliding window classifier (the killer feature) wired to f3dx-trace
v0.2.0 RouteLLM weights wrapped behind f3dx-router[smart] extra
v0.3.0 Wire the same crate to wasm32-unknown-unknown + drop into llmkit's CF Worker as the new hot path

License

MIT.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

f3dx_router-0.0.2-cp310-abi3-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.10+Windows x86-64

f3dx_router-0.0.2-cp310-abi3-musllinux_1_2_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

f3dx_router-0.0.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

f3dx_router-0.0.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.5 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

f3dx_router-0.0.2-cp310-abi3-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

f3dx_router-0.0.2-cp310-abi3-macosx_10_12_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file f3dx_router-0.0.2-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: f3dx_router-0.0.2-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for f3dx_router-0.0.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 040704ebbfc7f3f36674d929a35a1269e3264d1c02d25c21bac6ef3ddf6d2a42
MD5 fc9f2b69b42004f80328b08f2e0de1a4
BLAKE2b-256 b4110480c09dbc8e36e7ea7e836aeb1b284ef05973b8857863aef236c27a974d

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_router-0.0.2-cp310-abi3-win_amd64.whl:

Publisher: release.yml on smigolsmigol/f3dx-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 f3dx_router-0.0.2-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for f3dx_router-0.0.2-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 53ff7c739fc17fcc3cf11d146f294617a9e4e05a43fcbfd6b19cfd76a8506943
MD5 75bc7f680e4880157fd46e09df07edca
BLAKE2b-256 959dbdab495c189febf755c8681f2cc889d7370960b61b34d7b6d8aa570f01c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_router-0.0.2-cp310-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on smigolsmigol/f3dx-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 f3dx_router-0.0.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for f3dx_router-0.0.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 db252c5329fdea5a7f63a0ce5294ab6393a296b3792f9b7f834b631975eb183a
MD5 14a06ac1ac260cde8ddb0823738bb520
BLAKE2b-256 dcc224776f815a8fb57fd11e3c124e380ccd2012dfb09f6b161f87a694014ec4

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_router-0.0.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on smigolsmigol/f3dx-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 f3dx_router-0.0.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for f3dx_router-0.0.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 798e66d0090fba51e0e4afbecc46a6a1f7f4f6aa138ca94bdb2e03bd48c36496
MD5 f68fc62345f2fc3bc764e185c088541c
BLAKE2b-256 74211cb2db3ab0e15390bb05e334f5c2eee50094117976a9b821695101047467

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_router-0.0.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on smigolsmigol/f3dx-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 f3dx_router-0.0.2-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for f3dx_router-0.0.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 262da2a1944d74e32a49774556cce40b5330a7bb35820a3617270eeaa53f7f12
MD5 311151122bf4c2057c2a8ee63a1fce09
BLAKE2b-256 396160a386eea3010df7190937f14c39be7a558188ab8191072f6d1dca3ec5df

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_router-0.0.2-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on smigolsmigol/f3dx-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 f3dx_router-0.0.2-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for f3dx_router-0.0.2-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 44fd8c05cfe5804a3440fcd0f7d7a53dce03316853e67174a2ce078b0a0fcfef
MD5 e215e3d10905f399b6dbf09a8649abb2
BLAKE2b-256 6dea626429e2236208aa3e6dc51297617c75a3cea745d575701d8803fcca0a89

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_router-0.0.2-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on smigolsmigol/f3dx-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