Spill Over a Concurrency Limit to a Backup Provider

A worked example: one endpoint that sends at most 4 requests at a time to a model on your own GPU server and every request past those straight to gpt-6.1-sol, without waiting in a queue, called from the OpenAI SDK.

The Route: Order help

At most 4 requests at once go to GPU server; the rest go straight to OpenAI.

Requestfrom your SDK
Fallbackeach in turn
1stConcurrency limitat most 4 at once
2ndOpenAIgpt-6.1-sol
GPU serverqwen3-32b
Requestfrom your SDK
Fallbackeach in turn
1stConcurrency limitat most 4 at once
2ndOpenAIgpt-6.1-sol
GPU serverqwen3-32b

Set up the providers and the endpoint

The model you guard here is one that can only take so many requests at once: a server of your own with a fixed number of GPUs, or a provider plan that caps requests in flight. Past that number it slows everyone down or refuses, so the limit sends the extra requests to a provider that has room. You need a Model Waygate account and a key of your own with each provider; Model Waygate stores the provider keys encrypted and uses them only to forward your requests.

  • 1. Add the providers: on the dashboard's Providers page, add an OpenAI-compatible provider named GPU server with your server's base URL and its key, then an OpenAI provider named OpenAI with your OpenAI key. Each row's Test button asks the provider for its models, which proves the address and the key work before any request depends on them.
  • 2. Name the endpoint: open New endpoint and name it Order help. The slug fills in as order-help and becomes part of the endpoint's URL, never to change.
  • 3. Pick the route: choose Concurrency limit with backup. Lets at most 4 requests at a time through to the first model and sends the rest straight to the backup, without waiting; the limit's side panel in the editor changes how many.
  • 4. Choose the models: Provider GPU server, Model qwen3-32b; Backup provider OpenAI, Backup model gpt-6.1-sol.
  • 5. Mint a key: Create Endpoint opens the endpoint's page. Mint a gateway key there (it starts with mw_ and is shown once) and copy the endpoint's URL beside it.
  • 6. Set the number, if 4 is wrong: open Edit route, select the pool node and set how many requests it lets through at once, from 1 to 1000: as many as your server answers well side by side. Publish the change and deploy it.

The route the wizard draws

The diagram above is the endpoint's whole route: the request goes into a fallback, whose first child is the concurrency limit in front of GPU server and whose second is OpenAI. It opens in the route editor like any route you draw yourself; each change you publish becomes a new version, deployed when you choose.

  • Its places: a request takes one of the limit's 4 places just before its call to GPU server and gives it back when that call's connection closes. A buffered answer holds its place until the whole answer is read, and a stream until its last token, so a few long streams can fill the limit for minutes.
  • How full it is: the endpoint's page lists each limit of the versions serving it and its places in use, such as pool: 3 of 4 in use. The count is shared by every server the gateway runs on.

Send a request with the OpenAI SDK

Point the SDK at the endpoint's URL, https://modelwaygate.com/USER_ID/order-help/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. The code is the same whether the limit has room or not: the route decides, request by request.

  • model: the field is required, but the route decides which model answers, so its value is only a label. Sending the endpoint's slug keeps your logs readable.
  • One dialect, both providers: the request is Chat Completions whichever output answers it. The gateway sends it on to GPU server as an OpenAI-compatible server reads it, and to OpenAI as OpenAI's own API does, so the reply your code reads has the same shape either way.
  • No real keys here: mw_your_gateway_key stands for the key you minted. Keep it in an environment variable or a secret store, never in source control.

Code Examples

curl https://modelwaygate.com/USER_ID/order-help/api/v1/chat/completions \
  -H "Authorization: Bearer mw_your_gateway_key" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "order-help",
  "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/order-help/api/v1", api_key="mw_your_gateway_key")

response = client.chat.completions.create(
    model="order-help",
    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/order-help/api/v1", apiKey: "mw_your_gateway_key" });

const response = await client.chat.completions.create({
  model: "order-help",
  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\": \"order-help\", \"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/order-help/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/order-help/api/v1/chat/completions"
  let turn role content = object ["role" .= (role :: String), "content" .= (content :: String)]
      body = object ["model" .= ("order-help" :: 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)

What your code sees when the limit is full

Nothing different. While 4 requests hold the limit's places, the next request is answered by gpt-6.1-sol, with the same status and shape as any other answer.

  • No wait, no queue: the limit does not hold the request back until a place frees up. It refuses at once, without calling GPU server, and the fallback sends the request to OpenAI in the same moment. The next request after a place frees goes to GPU server again.
  • Below the limit: while fewer than 4 requests are under way, every request goes to GPU server and OpenAI is never asked.
  • The answer says who answered: the response's model field names the model that actually answered, so your code can tell an overflow answer from one your own server gave without asking the dashboard.
  • What it costs: the refusal is the gateway's own decision and makes no call, so it adds nothing: the request is billed as the one answer it got, by the backup. The backup's provider bills you for that call directly.
  • When the first model fails: the fallback moves on after any failure, so the backup answers too when GPU server is down or refuses, as in the fallback guide. A full limit and a failed call look the same to your code: an answer from the backup.

What the route trace shows

Every request records the way it went, on the dashboard's Usage page, on the request's own page and through the control API.

  • Let through: fallback#1 → limit pool 1/4 → GPU server (qwen3-32b) is the first request into an empty limit; the number before the slash counts the places in use with this request's, so the fourth at once shows fallback#1 → limit pool 4/4 → GPU server (qwen3-32b).
  • Spilled over: fallback#2 → OpenAI (gpt-6.1-sol) is a request the full limit sent on. The route taken names only the child that answered; the refusal is listed under the request's route events as Limit full: node pool (qwen3-32b): 4 of 4 in use, so it was not called, and in the control API as a concurrency_limited event naming the node, with the places in use and how many it allows.
  • Not a provider failure: the refusal never counts against GPU server's health or a circuit breaker, since the provider was never asked.

How this differs from a rate limit

A rate limit counts how many requests start in a minute. A concurrency limit counts how many are under way right now. A hundred short requests a minute may never fill 4 places, while 4 long streams fill them for as long as they run.

  • The gateway's rate limits: each gateway key may make 60 requests a minute and each account 600, and an account may have 100 requests in flight at once. Those are answered with a 429 before the route runs, so no fallback sees them and the backup is never asked. Your code has to wait and try again.
  • A provider's rate limit: a provider that answers a 429 was asked, and refused. The fallback moves on after that too, but only once the call was made and counted against your quota. The limit keeps the extra request from being sent at all.
  • Without a backup: a limit with no fallback above it answers a 429 concurrency_limit_reached with Retry-After: 1, saying Concurrency limit pool allows 4 requests at once and all are in use, so its output was not called. That is the shape for a limit that should protect a model without spending on another.

What the limit counts, and what it does not

The limit is the gateway's own count, kept in its database, of requests through this one node of this one endpoint.

  • Per node, not per account: two endpoints, or two limits, in front of GPU server each allow their own 4. To cap the server as a whole, send every caller through the one endpoint.
  • After a crash: the places a gateway server held when it crashed are taken back within 60 seconds, so GPU server can briefly see more than 4 at once.
  • When it cannot count: a limit whose count cannot be read refuses rather than let an unknown number through, and the fallback sends the request to the backup, as it does when the limit is full.
  • A selective fallback: in the route editor a fallback can be made selective, moving on only after the failures you tick. A full limit is the category limit_refused, which a new selective fallback starts with ticked; untick it and a full limit answers the 429 above instead of reaching the backup.

Other shapes with a backup

The wizard offers more starting routes with a backup, each drawn the same way and editable afterwards; a route drawn by hand can also put a limit in front of the backup, or in front of a circuit breaker.

  • A backup model: Tries the first model, and the backup whenever the first fails, for whatever reason.
  • Retried, then backup: Retries the first model up to three times on a transient failure, and sends the request to the backup once every try has failed, or at once on any other failure.
  • Circuit breaker with backup: Tries the first model, and sends the request to the backup when it fails; after five failures in a row the circuit breaker opens and sends requests straight to the backup until it recovers.

Ready to get started?

Create Your API Key