Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

20 Commits

Folders and files

Repository files navigation

Open Switch

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.

Run

source ~/.cargo/env
export CARGO_TARGET_DIR=$HOME/targets/openswitch
cargo run -p openswitch-server -- --config examples/mock.yaml
curl 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.

Configuration

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.

Architecture

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.

Load benchmark

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 loadgen

Measured 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.

Checks

cargo fmt --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages