Routescope APIRoutescope API
Client Tool Setup

Set Backup Models: Switch to Claude / Qwen / DeepSeek When OpenAI Fails

Add model fallback in your own application code so a failed OpenAI request can retry with Claude, Qwen, or DeepSeek.

To switch from OpenAI to Claude / Qwen / DeepSeek when a request fails, catch the failure in your application code and retry with another model.

Step 1: Prepare a fallback model list

Open Model Plaza and copy model names available to your account. Prepare one primary model and 2 to 3 fallback models.

const fallbackModels = [
  "your-openai-model",
  "your-claude-model",
  "your-qwen-model",
  "your-deepseek-model",
];

If your code uses OpenAI-compatible /v1/chat/completions, confirm the fallback models work with that request style. Availability should be verified through Model Plaza and a real test request.

Step 2: Retry only retryable errors

Error typeSwitch model?
Network timeoutYes
429Yes
Upstream 5xxYes
400No, usually a parameter issue
401 / 403No, usually an API Key, quota, or permission issue
404No, usually a model name issue

JavaScript / TypeScript example

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.ROUTESCOPE_API_KEY,
  baseURL: "https://api.routescope.ai/v1",
});

const fallbackModels = [
  "your-openai-model",
  "your-claude-model",
  "your-qwen-model",
  "your-deepseek-model",
];

function shouldRetry(error: any) {
  const status = error?.status;
  return !status || status === 429 || status >= 500;
}

export async function createChatWithFallback(messages: any[]) {
  let lastError: unknown;

  for (const model of fallbackModels) {
    try {
      return await client.chat.completions.create({
        model,
        messages,
      });
    } catch (error) {
      lastError = error;

      if (!shouldRetry(error)) {
        throw error;
      }
    }
  }

  throw lastError;
}

Python example

from openai import OpenAI

client = OpenAI(
    api_key="sk-your-token",
    base_url="https://api.routescope.ai/v1",
)

fallback_models = [
    "your-openai-model",
    "your-claude-model",
    "your-qwen-model",
    "your-deepseek-model",
]


def should_retry(error):
    status = getattr(error, "status_code", None)
    return status is None or status == 429 or status >= 500


def create_chat_with_fallback(messages):
    last_error = None

    for model in fallback_models:
        try:
            return client.chat.completions.create(
                model=model,
                messages=messages,
            )
        except Exception as error:
            last_error = error
            if not should_retry(error):
                raise

    raise last_error

Client tools

If you use a client without custom code, such as an editor extension or desktop client, you usually need to switch models manually. You can save several RouteScope model configurations in the same tool.

ScenarioWhat to do
Primary model fails occasionallyManually switch to a backup model and retry.
You are building your own applicationUse the fallback code above.
Your team gave you a unified model nameUse the model name your team provided.

Verify fallback behavior

For testing, temporarily set the first model name to an unavailable model and confirm your code continues to the next model. Restore the real model name after testing.

In operation records, check:

ItemWhat to verify
Multiple recordsThe failed model and successful model are recorded separately.
Requested modelModels were tried in the order you configured.
Error reasonOnly 429, timeouts, or 5xx caused retries.
Final costCost is based on the model that eventually succeeds and its output tokens.

Last updated on