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 Distribution

f3dx_router-0.0.3.tar.gz (22.5 kB view details)

Uploaded Source

Built Distributions

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

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

Uploaded CPython 3.10+Windows x86-64

f3dx_router-0.0.3-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.3-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.3-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.3-cp310-abi3-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

f3dx_router-0.0.3-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.3.tar.gz.

File metadata

  • Download URL: f3dx_router-0.0.3.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for f3dx_router-0.0.3.tar.gz
Algorithm Hash digest
SHA256 5ced132f94e98ce359e52a10a25dd5574a63f6781fb4881e3325e618d7981292
MD5 5a4746f00757f0a88584542eea8c6bd6
BLAKE2b-256 2489101f825c815dfa0a4d7402c02951967310ab900c2b8b3c94737f089a1a66

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_router-0.0.3.tar.gz:

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.3-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: f3dx_router-0.0.3-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.3-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 741c61659cd4a98ffdc5cef1a01c8e8cf161c6dd4b46f25f404ff6fe7b670630
MD5 924733a176a71cf1f83137ea64d193e7
BLAKE2b-256 605cf4c5507fdc86e0adddd99746239ea9e72cd09a18b38953e6e41c4bf4b2e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_router-0.0.3-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.3-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for f3dx_router-0.0.3-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 62815769005778b86c2f9f57ee6798c2696c6cd6ac443b2dd8ef5b9b9a2394e8
MD5 f5be3d18232eb2b0749f12c366bb80aa
BLAKE2b-256 e22a1c5a9621a4d50b6e2aa5c0c424dfd78f75a593b282210dc8f277c99f75e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_router-0.0.3-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.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for f3dx_router-0.0.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c24f447495f8b2773a556fe833b1eb0c510ad4385e1d53c5accd621d69ce7c6a
MD5 f6150255233d4f06af78934d3f1535ef
BLAKE2b-256 80c8630493d89ceecc5772510fea617475924e59cce34ea3e8f5fdbd86cfc576

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_router-0.0.3-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.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for f3dx_router-0.0.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3ab277e72c7f2a139e3ec96b67ed766fcc9a1a45a4c09f73543b9eaf0e58ce62
MD5 58a1552cf978a67872e8452d6316fe3e
BLAKE2b-256 671aecd5bb33881752319aac0786c3ecfdbef8c3e8d042f411c3d034e434085f

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_router-0.0.3-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.3-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for f3dx_router-0.0.3-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6398d199c64682f41faed920305b66f3b6a4c9a659f14a6ef502d8449f7e0f92
MD5 571f385edc4dae7e6d9701aaa2487f75
BLAKE2b-256 7e5acb4168a3a41975ca945ea2ca464cfd00aa09872b84fcaa4b6c6de720a835

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_router-0.0.3-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.3-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for f3dx_router-0.0.3-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f16b1f0b661a11b583ca97aa1c2aae352e6064a33a51a218448a6d9e0e35bcb9
MD5 96277540882a0331cfbf918d88cf6634
BLAKE2b-256 300babce7357910fb76df283f3fdd63038700d10170589140b457e29e8958a1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_router-0.0.3-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