MCPcopy Create free account
hub / github.com/NVIDIA-NeMo/Switchyard

github.com/NVIDIA-NeMo/Switchyard @v0.2.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.2.0 ↗ · + Follow
5,764 symbols 21,761 edges 420 files ⚖ custom 2,155 documented · 37% updated 7d agov0.2.0 · 2026-08-10★ 2,75443 open issues

Browse by type

Functions 4,886 Types & classes 851 Endpoints 27
What it actually does AI analysis from the code graph
loading…
README

Switchyard

Switchyard

Switchyard is a Rust proxy and library for LLM traffic. It routes requests across providers, translates between OpenAI and Anthropic APIs, records operational metrics, and provides typed, composable routing algorithms.

Why Switchyard? Point a coding agent such as Claude Code or Codex at an open-source model. Switchyard translates between the OpenAI Chat, Anthropic Messages, and OpenAI Responses formats, so the agent keeps speaking its native API while the request is served by vLLM, NVIDIA NIM, Ollama, or any OpenAI-compatible endpoint. The same proxy can spread traffic across several models for A/B benchmarking, apply signal-driven stage routing, or run a custom algorithm you write yourself.

Features

  • Protocol Translation: convert between OpenAI Chat, Anthropic Messages, and OpenAI Responses formats
  • Multi-Backend Routing: random routing, LLM-as-classifier routing, signal-driven stage-router, or your own algorithm
  • Operational Metrics: Prometheus metrics cover requests, errors, latency, tokens, and routing overhead

Quick Start

Choose the launcher path to run Claude Code, Codex CLI, or OpenClaw through Switchyard. Choose the server path to run Switchyard as a standalone proxy. Choose the library path to embed routing in your own Rust application.

Launcher Path

Install uv if it is not already available, then install the published Switchyard tool:

curl -LsSf https://astral.sh/uv/install.sh | sh
source "$HOME/.local/bin/env"
uv tool install --python 3.12 "nemo-switchyard[cli,server]"

The coding agent you launch must also be installed and on your PATH. This does not install the standalone switchyard-server binary; use the Server Path for that.

Set an OpenRouter key and launch against the packaged deployment:

export OPENROUTER_API_KEY="your-openrouter-key"  # pragma: allowlist secret
switchyard launch claude --model switchyard
switchyard launch codex --model switchyard
switchyard launch openclaw --model switchyard

To use your own native TOML deployment, pass its route ID and configuration:

switchyard launch claude --model my-route --config routes.toml

Server Path

Use this path to install and run the standalone Rust proxy. Install Rust with Cargo, then install the published binary:

cargo install --locked switchyard-server
switchyard-server --help

Cargo builds the release binary and installs it into ~/.cargo/bin by default.

Create routes.toml using the Getting Started guide, then validate it and start the server:

export OPENROUTER_API_KEY="your-openrouter-key"  # pragma: allowlist secret
switchyard-server --config routes.toml --dry-run
switchyard-server --config routes.toml --host 127.0.0.1 --port 4000

Verify the proxy in another terminal:

curl http://localhost:4000/health

For a complete configuration and a test request, follow Getting Started.

Library Path

switchyard-libsy embeds the routing algorithms in your own Rust application. It never calls a model itself: an algorithm decides which target to use and hands every model call back to you, so it drops into an existing proxy, gateway, or agent runtime without owning an HTTP stack. Pair it with switchyard-llm-client when you want the calls made for you.

[dependencies]
switchyard-libsy = { git = "https://github.com/NVIDIA-NeMo/Switchyard.git" }
switchyard-protocol = { git = "https://github.com/NVIDIA-NeMo/Switchyard.git" }

See Getting Started for setup and the algorithm list, or the switchyard-libsy crate docs.

Routing Strategies

Strategy Use it when Route type
LLM Classifier Request content should decide whether a turn needs the weak or strong tier. llm_classifier
Stage Router Signals already in the conversation, such as tool results and errors, should route most turns without an extra model call. stage_router
Escalation Router Every turn runs on the weak tier first, and a judge reads that answer to decide whether to send the same request to the strong tier. llm_classifier with mode = "escalation"
Random You need a fixed traffic split for A/B tests, baselines, or cost experiments. random

A passthrough route registers one target under one model ID with no routing decision. See the Routing Overview for the common route shape and self-hosted targets.

Architecture

flowchart LR
    clients["Clients"]
    switchyard["Switchyard

routing · translation · fallback"]
    backends["Model backends"]

    clients -->|"OpenAI / Anthropic API"| switchyard
    switchyard -->|"provider-native format"| backends

Clients keep their native OpenAI or Anthropic API format. Switchyard picks a configured backend, forwards the request in that backend's own format, and translates the response back into the shape the client expects. The server accepts OpenAI Chat Completions, OpenAI Responses, and Anthropic Messages. Each configured LLM client selects one upstream format.

Documentation

Community

License

Apache 2.0 License. Copyright NVIDIA Corporation.

Extension points exported contracts — how you extend this code

browse all types & interfaces →

Core symbols most depended-on inside this repo

browse all functions →

Shape

Function 2,826
Method 2,060
Class 767
Enum 66
Route 27
Interface 18

Languages

Python54%
Rust46%

Modules by API surface

tests/test_chat_response.py107 symbols
tests/test_translation_engine_chaos.py105 symbols
switchyard_rust/core.py98 symbols
crates/switchyard-server/src/lib.rs91 symbols
crates/libsy/src/core/algorithm.rs89 symbols
crates/libsy/src/algorithms/llm_class.rs87 symbols
crates/libsy/src/algorithms/fall_through.rs87 symbols
crates/libsy-llm-client/src/client.rs82 symbols
tests/test_route_bundle.py81 symbols
tests/test_python_profile_abstractions.py74 symbols
tests/test_switchyard.py73 symbols
tests/test_deterministic_routing_profile.py63 symbols

Dependencies from manifests, versioned

litellm1.92.0 · 1×
nemo-switchyard0.1.0 · 1×

For agents

$ claude mcp add Switchyard \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page