Skip to content

Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.

Rust

chore: update single provider recipe (#898)

Greg Clark101b8af837ac
diff --git a/docs/recipes/single_provider_coding_agents.md b/docs/recipes/single_provider_coding_agents.md
index 6ede23313..fd07ae061 100644
--- a/docs/recipes/single_provider_coding_agents.md
+++ b/docs/recipes/single_provider_coding_agents.md
@@ -26,22 +26,24 @@ Save as `codex-routing.toml`:
```toml
schema_version = 1
-[llm_clients.chatgpt]
+[llm_clients.chatgpt_backend]
format = "openai_responses"
base_url = "https://chatgpt.com/backend-api/codex"
forward_auth = true
[targets.capable]
-id = "gpt-5.6-sol"
-llm_client = "chatgpt"
+id = "gpt-6-sol"
+llm_client = "chatgpt_backend"
[targets.efficient]
-id = "gpt-5.6-luna"
-llm_client = "chatgpt"
+id = "gpt-6-luna"
+llm_client = "chatgpt_backend"
+extra_body = { store = false, stream = true }
+omit_body_fields = ["max_output_tokens"]
-[targets.judge]
-id = "gpt-5.6-terra"
-llm_client = "chatgpt"
+[targets.terra]
+id = "gpt-6-luna"
+llm_client = "chatgpt_backend"
extra_body = { store = false, stream = true }
omit_body_fields = ["max_output_tokens"]
@@ -50,7 +52,7 @@ id = "switchyard"
type = "composite"
[routes.switchyard.classifier]
-target = "judge"
+target = "terra"
base_threshold = 0.5
classify_trigger = "user_turn"
diff --git a/scripts/config/codex.sy.toml b/scripts/config/codex.sy.toml
new file mode 100644
index 000000000..9ecdff1ef
--- /dev/null
+++ b/scripts/config/codex.sy.toml
@@ -0,0 +1,8 @@
+model = "switchyard"
+model_provider = "sy"
+
+[model_providers.sy]
+name = "Switchyard"
+base_url = "http://127.0.0.1:@SY_PORT@/v1"
+wire_api = "responses"
+requires_openai_auth = true
diff --git a/scripts/config/composite.toml b/scripts/config/composite.toml
new file mode 100644
index 000000000..2e0ba560d
--- /dev/null
+++ b/scripts/config/composite.toml
@@ -0,0 +1,40 @@
+schema_version = 1
+
+[llm_clients.chatgpt_backend]
+format = "openai_responses"
+base_url = "https://chatgpt.com/backend-api/codex"
+forward_auth = true
+
+[targets.capable]
+id = "gpt-6-sol"
+llm_client = "chatgpt_backend"
+
+[targets.efficient]
+id = "gpt-6-luna"
+llm_client = "chatgpt_backend"
+extra_body = { store = false, stream = true }
+omit_body_fields = ["max_output_tokens"]
+
+# chatgpt.com/backend-api/codex is Codex CLI's own private endpoint, not the
+# public OpenAI Responses API. It 400s unless store=false and stream=true are
+# set explicitly, and it rejects max_output_tokens outright, so the
+# classifier's own token cap has to be dropped before the request goes out.
+[targets.terra]
+id = "gpt-6-luna"
+llm_client = "chatgpt_backend"
+extra_body = { store = false, stream = true }
+omit_body_fields = ["max_output_tokens"]
+
+[routes.switchyard]
+id = "switchyard"
+type = "composite"
+
+[routes.switchyard.classifier]
+target = "terra"
+base_threshold = 0.5
+classify_trigger = "user_turn"
+
+[routes.switchyard.stage]
+capable_target = "capable"
+efficient_target = "efficient"
+confidence_threshold = 0.5
diff --git a/scripts/linux/install.sh b/scripts/linux/install.sh
index 7bf19e422..247bf8c6f 100755
--- a/scripts/linux/install.sh
+++ b/scripts/linux/install.sh
@@ -116,48 +116,7 @@ run mkdir -p "$SY_HOME/bin"
run install -m 755 "$REPO_ROOT/target/release/switchyard-server" "$SY_HOME/bin/switchyard-server"
step "Writing server config"
-# The composite router from examples/run_codex.sh: Terra classifies each user
-# turn and sets the tier, Stage drives the tool loop underneath it.
-write_once "$SY_HOME/composite.toml" <<'EOF'
-schema_version = 1
-
-[llm_clients.chatgpt_backend]
-format = "openai_responses"
-base_url = "https://chatgpt.com/backend-api/codex"
-forward_auth = true
-
-[targets.capable]
-id = "gpt-5.6-sol"
-llm_client = "chatgpt_backend"
-
-[targets.efficient]
-id = "gpt-5.6-luna"
-llm_client = "chatgpt_backend"
-
-# chatgpt.com/backend-api/codex is Codex CLI's own private endpoint, not the
-# public OpenAI Responses API. It 400s unless store=false and stream=true are
-# set explicitly, and it rejects max_output_tokens outright, so the
-# classifier's own token cap has to be dropped before the request goes out.
-[targets.terra]
-id = "gpt-5.6-terra"
-llm_client = "chatgpt_backend"
-extra_body = { store = false, stream = true }
-omit_body_fields = ["max_output_tokens"]
-
-[routes.switchyard]
-id = "switchyard"
-type = "composite"
-
-[routes.switchyard.classifier]
-target = "terra"
-base_threshold = 0.5
-classify_trigger = "user_turn"
-
-[routes.switchyard.stage]
-capable_target = "capable"
-efficient_target = "efficient"
-confidence_threshold = 0.5
-EOF
+write_once "$SY_HOME/composite.toml" < "$REPO_ROOT/scripts/config/composite.toml"
step "Validating the server config"
if (( DRY_RUN )); then
@@ -195,16 +154,7 @@ step "Adding the sy Codex profile"
# This profile only changes which router answers. Approval and sandbox
# settings are deliberately left out, so the profile cannot loosen how Codex
# asks before it acts. Set those yourself if you want them.
-write_with_backup "$CODEX_PROFILE_CONFIG" <<EOF
-model = "switchyard"
-model_provider = "sy"
-
-[model_providers.sy]
-name = "Switchyard"
-base_url = "http://127.0.0.1:$SY_PORT/v1"
-wire_api = "responses"
-requires_openai_auth = true
-EOF
+sed "s/@SY_PORT@/$SY_PORT/g" "$REPO_ROOT/scripts/config/codex.sy.toml" | write_with_backup "$CODEX_PROFILE_CONFIG"
step "Done"
say "Server: http://127.0.0.1:$SY_PORT"
diff --git a/tests/test_linux_install.py b/tests/test_linux_install.py
index e41dde9f7..33b029beb 100644
--- a/tests/test_linux_install.py
+++ b/tests/test_linux_install.py
@@ -18,6 +18,7 @@ RC = f"before\n{START}\nalias codex='codex -p sy'\n{END}\nafter\n"
def setup(tmp_path):
scripts = tmp_path / "repo" / "scripts" / "linux"
shutil.copytree(REPO / "scripts" / "linux", scripts)
+ shutil.copytree(REPO / "scripts" / "config", scripts.parent / "config")
home = tmp_path / "home"
home.mkdir()
bin_dir = tmp_path / "bin"