The Route: Support bot
The request goes to OpenAI first, and to Anthropic only when that fails.
A worked example: one endpoint that asks gpt-6.1-sol first and claude-fable-5-1 when that fails, called from the OpenAI SDK with nothing changed but its base URL and key.
The request goes to OpenAI first, and to Anthropic only when that fails.
You need a Model Waygate account and an API key of your own with each provider. Model Waygate stores the provider keys encrypted and uses them only to forward your requests; your application only ever holds a gateway key.
OpenAI with your OpenAI key, then an Anthropic provider named Anthropic with your Anthropic key. Each row's Test button asks the provider for its models, which proves the key works before any request depends on it.Support bot. The slug fills in as support-bot and becomes part of the endpoint's URL, never to change.A backup model. Tries the first model, and the backup whenever the first fails, for whatever reason.OpenAI, Model gpt-6.1-sol; Backup provider Anthropic, Backup model claude-fable-5-1. The wizard suggests each provider's own models and refuses a backup that is the same provider and model as the first.mw_ and is shown once) and copy the endpoint's URL beside it.The diagram above is the endpoint's whole route: the request goes into a fallback, which asks its first child and moves to the second only when the first fails. It opens in the route editor like any route you draw yourself, so you can change it later; each change you publish becomes a new version, deployed when you choose.
fallback#1 → OpenAI (gpt-6.1-sol) when the first model answered, fallback#2 → Anthropic (claude-fable-5-1) when the backup did.model field names the provider model that actually answered, so your code can tell a backup answer from a first-choice one without asking the dashboard.Point the SDK at the endpoint's URL, https://modelwaygate.com/USER_ID/support-bot/api/v1, with the gateway key in place of an OpenAI key. USER_ID is your account's public id, which the endpoint's URL on the dashboard already carries. Nothing else in your code changes, and the same code keeps working when the first provider is down.
mw_your_gateway_key stands for the key you minted. Keep it in an environment variable or a secret store, never in source control.curl https://modelwaygate.com/USER_ID/support-bot/api/v1/chat/completions \
-H "Authorization: Bearer mw_your_gateway_key" \
-H "Content-Type: application/json" \
-d '{
"model": "support-bot",
"messages": [
{"role": "system", "content": "You answer questions about orders in one short paragraph."},
{"role": "user", "content": "Where is order 1042?"}
]
}'
from openai import OpenAI
client = OpenAI(base_url="https://modelwaygate.com/USER_ID/support-bot/api/v1", api_key="mw_your_gateway_key")
response = client.chat.completions.create(
model="support-bot",
messages=[
{"role": "system", "content": "You answer questions about orders in one short paragraph."},
{"role": "user", "content": "Where is order 1042?"},
],
)
print(response.model, response.choices[0].message.content)
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://modelwaygate.com/USER_ID/support-bot/api/v1", apiKey: "mw_your_gateway_key" });
const response = await client.chat.completions.create({
model: "support-bot",
messages: [
{ role: "system", content: "You answer questions about orders in one short paragraph." },
{ role: "user", content: "Where is order 1042?" },
],
});
console.log(response.model, response.choices[0].message.content);
OkHttpClient client = new OkHttpClient();
String json = "{\"model\": \"support-bot\", \"messages\": ["
+ "{\"role\": \"system\", \"content\": \"You answer questions about orders in one short paragraph.\"}, "
+ "{\"role\": \"user\", \"content\": \"Where is order 1042?\"}]}";
Request request = new Request.Builder()
.url("https://modelwaygate.com/USER_ID/support-bot/api/v1/chat/completions")
.header("Authorization", "Bearer mw_your_gateway_key")
.post(RequestBody.create(json, MediaType.get("application/json")))
.build();
try (Response response = client.newCall(request).execute()) {
System.out.println(response.body().string());
}
import Data.Aeson (encode, object, (.=))
import Network.HTTP.Client
import Network.HTTP.Client.TLS (tlsManagerSettings)
main :: IO ()
main = do
manager <- newManager tlsManagerSettings
initial <- parseRequest "POST https://modelwaygate.com/USER_ID/support-bot/api/v1/chat/completions"
let turn role content = object ["role" .= (role :: String), "content" .= (content :: String)]
body = object ["model" .= ("support-bot" :: String), "messages" .= [turn "system" "You answer questions about orders in one short paragraph.", turn "user" "Where is order 1042?"]]
request = initial{requestHeaders = [("Authorization", "Bearer mw_your_gateway_key"), ("Content-Type", "application/json")], requestBody = RequestBodyLBS (encode body)}
response <- httpLbs request manager
print (responseBody response)
The wizard's fallback moves on after any failure short of an answer, and your code sees only the backup's answer. The first provider's failure is recorded on the request's page, beside the call that answered.
upstream_error when it answered and upstream_unreachable when it could not be reached.A fallback only judges what its children answer. Some failures happen before the route runs, or stop the whole request, and a backup cannot help with them.
unreachable, server_error, rate_limited, empty_reply, circuit_open, limit_refused: an outage, exhausted quota, an empty reply or a full concurrency limit, where a backup helps. A request the first provider refused as invalid (400) or a key it refused (401) then comes back at once with that provider's status, rather than being sent to a backup that would most likely refuse it too, and the backup is not called.Add stream=True (stream: true) and the same route streams from whichever provider it reaches, in OpenAI's event format either way. A stream can fall back only until it begins.
The wizard offers three more starting routes with a backup, each drawn the same way and editable afterwards.