← nopea.tech
ScaneaConsenteaMaskeaBundlesPricing
Providers

Claude fallback when GPT-5 is rate limited

Wrap each provider in its own Nopea instance, then catch a retry-exhausted OpenAI call and fail over to Claude.

← All recipes
import { Maskea, retries } from "@nopeatech/maskea";
import OpenAI from "openai";
import Anthropic from "@anthropic-ai/sdk";

const openai = new OpenAI();
const anthropic = new Anthropic();

const primary = new Maskea()
  .use(retries({ max: 2 }))
  .wrap(openai.chat.completions.create.bind(openai.chat.completions));

const fallback = new Maskea()
  .use(retries({ max: 2 }))
  .wrap(anthropic.messages.create.bind(anthropic.messages));

async function chat(prompt: string) {
  try {
    return await primary({ model: "gpt-4o-mini", messages: [{ role: "user", content: prompt }] });
  } catch {
    return await fallback({ model: "claude-3-5-haiku-20241022", max_tokens: 1024, messages: [{ role: "user", content: prompt }] });
  }
}

Checked against the shipped @nopeatech/maskea API. Full docs at nopea.tech/maskea/docs.

More in Providers

OpenAI + exponential backoff →Anthropic Claude with retries + secret masking →Google Gemini →OpenRouter (OpenAI-compatible endpoint) →