Open Switch is a Rust LLM gateway with a deterministic routing core and an axum HTTP server. It accepts the OpenAI chat-completions shape, applies per-key token windows, falls back across deployment groups, tracks circuit-breaker state, and can hedge a slow first attempt with a second deployment.
source ~/.cargo/env
export CARGO_TARGET_DIR=$HOME/targets/openswitch
cargo run -p openswitch-server -- --config examples/mock.yamlcurl http://127.0.0.1:8080/v1/chat/completions \
-H 'Authorization: Bearer demo' -H 'content-type: application/json' \
-d '{"model":"mock-chat","messages":[{"role":"user","content":"hello"}]}'stream: true returns server-sent events. OpenAI-compatible upstream SSE bytes pass through without JSON re-encoding. GET /v1/models, GET /healthz, and GET /metrics are also available.
listen sets the bind address. hedge_delay_ms starts the second matching deployment after the delay. A value of zero disables hedging. breaker_failure_threshold controls how many consecutive failures open a deployment breaker, and breaker_cooldown_ms controls when it admits a half-open probe. api_keys maps bearer tokens to tokens_per_minute.
Each deployment needs id, model, group, and provider. Providers are mock with latency_ms, error_every, response, and optional stream_chunks; openai_compatible with base_url and optional api_key; or anthropic with base_url and api_key. Configuration rejects unknown fields, duplicate deployment IDs, empty identifiers, invalid upstream URLs, and zero breaker thresholds with a specific error.
openswitch-core contains deterministic deployment, budget, circuit-breaker, latency, planning, trace, selection, and simulation modules. It performs no IO and has no runtime dependency. openswitch-server owns HTTP, provider calls, SSE responses, cancellation through tokio::select!, and text metrics. openswitch-wasm exposes the simulation to the browser demo.
The server integration suite binds the gateway and fake upstreams to random loopback ports. It checks non-streaming and streaming responses, fallback ordering, breaker recovery, hedge completion, budgets, authentication, both network adapters, and metrics.
The load generator runs the gateway in process with a zero-latency mock. It uses concurrency 64 for 20 seconds and records a bounded 100 ns latency histogram.
cargo run --release -p openswitch-server --example loadgenMeasured in WSL on September 29, 2026: 578,428 requests per second, 111,100 ns p50 added latency, and 225,300 ns p99 added latency across 11,568,645 requests. These figures measure the in-process mock path, not HTTP, network, provider, or token-generation time.
cargo fmt --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace