Typed, composable LLM routing with request/response translation and multi-backend orchestration
Project description
Switchyard
Typed, composable LLM routing and format translation for Python. Route traffic between multiple LLM providers, translate between OpenAI and Anthropic APIs, collect usage statistics, and build profile-backed routing flows with strong typing and minimal boilerplate.
Why Switchyard? Point coding agents like Claude Code and Codex at compatible open-source models. Switchyard transparently translates between OpenAI Chat, Anthropic Messages, and OpenAI Responses formats, so each agent keeps speaking its native API while requests are served by vLLM, NVIDIA NIM, Ollama, or any OpenAI-compatible endpoint. The same proxy can also route across multiple models for A/B benchmarking splits, signal-driven cascade escalation, or a custom router you wire in.
Launcher routing is explicit: launchers default to built-in LLM-classifier routing, which you can tune with --weak-model, --classifier-model, --profile, and --classifier-min-confidence; use --model X for single-model passthrough. The deprecated --routing-profiles FILE path remains for launcher-owned legacy bundles.
Features
- Protocol Translation: convert between OpenAI Chat, Anthropic Messages, and OpenAI Responses formats
- Multi-Backend Routing: random routing, LLM-as-classifier routing, signal-driven cascade, or custom routers
- Strong Types: typed request/response containers for OpenAI, Anthropic, and Responses APIs
- Profile-Owned Routing: typed profiles own routing, backend calls, stats, and translation wiring
- One-Command Launchers:
switchyard launch claude,switchyard launch codex, andswitchyard launch openclawspin up a local proxy and drop you into the target CLI - Request Statistics: collect per-request latency, token, and cost data
Quick Start
Install from PyPI
pip install "nemo-switchyard[cli,server]"
Install from source for local use (requires uv)
git clone git@github.com:NVIDIA-NeMo/Switchyard.git
cd Switchyard
uv tool install --editable '.[server,cli]'
Install from source for contributors (requires uv)
git clone git@github.com:NVIDIA-NeMo/Switchyard.git
cd Switchyard
uv sync
uv run switchyard ...
1. Launch Claude Code, Codex, or OpenClaw through Switchyard
Create an OpenRouter account at openrouter.ai and generate an API key from the OpenRouter keys page, then export it:
export OPENROUTER_API_KEY="your-openrouter-key" # pragma: allowlist secret
export OPENROUTER_BASE_URL="https://openrouter.ai/api/v1"
switchyard launch claude --model openai/gpt-4o-mini --api-key "$OPENROUTER_API_KEY" --base-url "$OPENROUTER_BASE_URL"
switchyard launch codex --model openai/gpt-4o-mini --api-key "$OPENROUTER_API_KEY" --base-url "$OPENROUTER_BASE_URL"
switchyard launch openclaw --model openai/gpt-4o-mini --api-key "$OPENROUTER_API_KEY" --base-url "$OPENROUTER_BASE_URL"
Each launcher starts a local proxy, points the agent at it, and shuts the proxy
down when the agent exits. Use --model for single-model passthrough. The
deprecated --routing-profiles flag remains for launcher-owned legacy bundles:
switchyard launch claude --model openai/gpt-4o-mini --base-url https://openrouter.ai/api/v1 # single-model passthrough
switchyard --routing-profiles routes.yaml -- launch claude # legacy route bundle
Bedrock-backed profile caveat (Claude Code + MCP): Bedrock enforces a 64-character
toolSpec.namecap. Claude Code's MCP bridge can auto-inject longer tool names, producingBedrockException400s on tool-bearing requests. If you use a Bedrock-backed route and hit this, swap to an OpenAI-compatible model with--model openai/gpt-4oor a routing-profile YAML.
See Agent Launchers for supported harness
versions, model requirements, troubleshooting, and Claude Code /model picker
aliasing.
2. Run a standalone profile-config server
New standalone deployments use a profile config that separates provider connectivity, upstream targets, and client-facing profiles. A complete OpenRouter-backed random-routing config looks like this:
endpoints:
openrouter:
api_key: ${OPENROUTER_API_KEY}
base_url: https://openrouter.ai/api/v1
targets:
strong:
endpoint: openrouter
model: openai/gpt-4o
format: openai
weak:
endpoint: openrouter
model: openai/gpt-4o-mini
format: openai
profiles:
smart:
type: random-routing
strong: strong
weak: weak
strong_probability: 0.3
Serve it as a proxy. The smart profile and both target ids are exposed as
models; clients select one through the request's model field:
switchyard serve --config profiles.yaml --port 4000
curl http://localhost:4000/v1/models
curl http://localhost:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model": "smart", "messages": [{"role": "user", "content": "hi"}]}'
Launcher compatibility: Launcher subcommands do not accept
--config. The deprecated--routing-profilesflag remains for launcher-owned legacyroutes:bundles and saved bundle paths:
routes:
fast:
type: model
target: openai/gpt-4o-mini
switchyard --routing-profiles routes.yaml -- launch claude
switchyard --routing-profiles routes.yaml -- configure
For profile selection and full configuration examples, start with Routing Overview, then open the strategy-specific page:
For multi-turn classifier sessions, see Session Affinity (Sticky Routing).
3. Use as a Python library
import asyncio
from switchyard import ChatRequest, PassthroughProfileConfig, ProfileSwitchyard
switchyard = ProfileSwitchyard(PassthroughProfileConfig(
api_key="sk-...",
base_url="https://api.openai.com/v1",
).build())
async def main():
request = ChatRequest.openai_chat({
"model": "gpt-4o",
"messages": [{"role": "user", "content": "What is 2+2?"}],
})
response = await switchyard.call(request)
# call() returns a JSON-compatible dict in the OpenAI Chat Completions shape.
print(response["choices"][0]["message"]["content"])
asyncio.run(main())
Architecture
Switchyard sits between client applications and one or more LLM backends:
clients --> Switchyard --> model backends
+--------> routing, translation, and fallback
Clients keep their supported OpenAI or Anthropic API format while Switchyard selects a configured model endpoint and translates the response back to the expected shape. See Architecture for system context and the end-to-end request flow.
Installation Options
Install from PyPI:
pip install nemo-switchyard
Optional extras:
pip install "nemo-switchyard[server]" # FastAPI / Uvicorn HTTP endpoints
pip install "nemo-switchyard[cli]" # Interactive CLI launchers (Claude / Codex)
pip install "nemo-switchyard[all]" # Server, CLI, GPU routing, and tracing extras
See Installation for a full breakdown of what each extra adds.
Documentation
- Getting Started: step-by-step setup, first request, troubleshooting
- Known Issues: known issues in 0.1.0
- Agent Launchers: Claude Code, Codex, and OpenClaw launcher behavior
- Cli Reference: canonical reference for every
switchyardsubcommand and flag - Architecture: system context and end-to-end request flow
- Routing Algorithms: signal-driven weak/strong cascade routing: picker layers, signal dimensions, and calibration data.
- Contributing: dev setup, testing, CI gates, PR process
- Development: project structure, benchmarks, conventions
- Agents: full design philosophy and architectural patterns
Supported Providers
- OpenAI: Chat Completions API
- Anthropic: Claude Messages API
- OpenAI Responses API: structured output / reasoning
- OpenAI-compatible APIs: vLLM, Ollama, Azure, etc. (anything with
/v1/chat/completions)
Requirements
- Python 3.12+
- macOS, Linux, or Windows
- API keys for your chosen backend (OpenAI, Anthropic, etc.)
- Linux x86_64 wheels require an x86-64-v3 / AVX2-class CPU (post 2013).
- Linux aarch64 wheels require a Neoverse N1-class CPU (post 2020).
Community
- Issues: GitHub Issues
- Code of Conduct: Code of Conduct
- Contributing: Contributing
License
Apache 2.0 License. Copyright NVIDIA Corporation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nemo_switchyard-0.0.1.dev1.tar.gz.
File metadata
- Download URL: nemo_switchyard-0.0.1.dev1.tar.gz
- Upload date:
- Size: 629.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b6b28a876843d61f6f5de6b76fdf1b2c35b3cc93e1154c8363ef743a51952ec
|
|
| MD5 |
ce542b5290dff0f1e2e93af4eb9c7ddc
|
|
| BLAKE2b-256 |
8b6d3eee5eda7e1829e3e1e08ae6b60fcb7c31c42440b84d68f1e97b420430f2
|
File details
Details for the file nemo_switchyard-0.0.1.dev1-cp312-abi3-win_arm64.whl.
File metadata
- Download URL: nemo_switchyard-0.0.1.dev1-cp312-abi3-win_arm64.whl
- Upload date:
- Size: 4.0 MB
- Tags: CPython 3.12+, Windows ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d2469a5e3fa41e581b58355e253b0ac9aa85c0c5941f0f9f5128e87b715090d
|
|
| MD5 |
83679d0ef5497672e36742415eebf397
|
|
| BLAKE2b-256 |
6d1fb1a5ddf729b6d4b9e068c64a48ae4ec09152c636f65ab3a8732e67d88e82
|
File details
Details for the file nemo_switchyard-0.0.1.dev1-cp312-abi3-win_amd64.whl.
File metadata
- Download URL: nemo_switchyard-0.0.1.dev1-cp312-abi3-win_amd64.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.12+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbf9b2259e44a1c2a31b209bf82a925722065adb816990f2cb428500b0bb81e0
|
|
| MD5 |
e1b4301086d5778006dc59bb92ff8518
|
|
| BLAKE2b-256 |
9abf2798ec6beceb7425c128510900fbd5a6ae83febd389e6d193e4f6982008a
|
File details
Details for the file nemo_switchyard-0.0.1.dev1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: nemo_switchyard-0.0.1.dev1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.0 MB
- Tags: CPython 3.12+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3031d0f4a6292985d5d0e2bd8ba1635d7059609ca5ae80f12cf769740a82a909
|
|
| MD5 |
00797a53329dd5648a6cafee9d8bbcba
|
|
| BLAKE2b-256 |
f1e5fcc9a1033ca738124754adb78d5937d1a230ece62aacc77c9b902d729bb9
|
File details
Details for the file nemo_switchyard-0.0.1.dev1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: nemo_switchyard-0.0.1.dev1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 5.0 MB
- Tags: CPython 3.12+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2b257b8f9a7165fbe24efa378de90fdf0e2e749d4ccd4edfbb03b2f56bcf30b
|
|
| MD5 |
29af9ff120c88bec6c96353f5cf737fa
|
|
| BLAKE2b-256 |
5b2887e409ef5b82b2cd2e1c6c345aee2b017797074c4b0fe4f83dfbeb17a127
|
File details
Details for the file nemo_switchyard-0.0.1.dev1-cp312-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: nemo_switchyard-0.0.1.dev1-cp312-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 4.6 MB
- Tags: CPython 3.12+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f3abb0c3797c039772892b31800c483e6771e94d4a96fb95858d829ea03ab07
|
|
| MD5 |
8b8346b6f13de9dae45e87863efd4e55
|
|
| BLAKE2b-256 |
9e851cc2a1b71581d61eb374d9608025497ad1126fb6143080d94514b9a29634
|
File details
Details for the file nemo_switchyard-0.0.1.dev1-cp312-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: nemo_switchyard-0.0.1.dev1-cp312-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 4.7 MB
- Tags: CPython 3.12+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02ef84c5c701960c475b3053f7562e9973bed06099e013ede997169798cab8f1
|
|
| MD5 |
a4987e5125017988be073aac6464bc15
|
|
| BLAKE2b-256 |
2f6f59ae3abdd443f43967067054e299df4478b8b79a7a064759a05985560bcb
|