◉CLAUDE LABJP
●SONNET 4.5 — Sonnet 4.5 was retired from the Claude API on 11/30. Calls now return an error. Move to Sonnet 5.5●PROJECTS — The Enterprise Analytics API now reports daily usage for the new projects experience (beta)●OPUS 4.5 — claude-opus-4-5 retires on 2027/1/22, 52 days from now. The replacement is claude-opus-5-5●LANGUAGE — Some users say Claude switches to another language mid-session while they write in English●NEW — New: Weekly usage looks like it jumped right after a plan upgrade? Check this first●COWORK — Handing Cowork a folder for the first time? Start with a task that only reads files●SONNET 4.5 — Sonnet 4.5 was retired from the Claude API on 11/30. Calls now return an error. Move to Sonnet 5.5●PROJECTS — The Enterprise Analytics API now reports daily usage for the new projects experience (beta)●OPUS 4.5 — claude-opus-4-5 retires on 2027/1/22, 52 days from now. The replacement is claude-opus-5-5●LANGUAGE — Some users say Claude switches to another language mid-session while they write in English●NEW — New: Weekly usage looks like it jumped right after a plan upgrade? Check this first●COWORK — Handing Cowork a folder for the first time? Start with a task that only reads files
Articles/API & SDK
⬡ API & SDK/2026-05-22Intermediate

Designing a Model-Selection Fallback That Survives this model is currently unavailable on Claude API

When Claude API says a model is currently unavailable, treating it like a 529 or 429 sends you the long way round. Ahead of the November 30 Sonnet 4.5 retirement, here is how I check model lifecycle and thinking support through the Models API at startup, tell refusals apart by SDK exception class, and avoid the 400 that hits when the backup model wants thinking written differently.

claude-api85model-availabilityfallback9error-handling11troubleshooting108

One evening, right after I deployed a routine batch job, the API started answering "this model is currently unavailable." I retried the same call about ten times and succeeded only in fattening the logs.

It took me a while to see that a retry means "try the same conditions again." If the thing being refused is the model ID itself, waiting changes nothing. What you need is a design that switches the request, not one that waits.

This feels closer to home in November 2026 than it did when I first wrote about it. On the Claude API, claude-sonnet-4-5-20250929 is scheduled to retire on November 30, and the official deprecations page says the undated claude-sonnet-4-5 retires with it. My earlier fallback table had exactly that ID sitting in the "backup" column.

Below is how I separate this error from 529 and 429, how I ask the Models API about a model's lifecycle and capabilities at startup, and how I switch models per request. I've left in the places where my earlier version was simply wrong, because those taught me the most.

The short version

Three things, up front:

  1. Switch models only when the model itself can't be accepted. Congestion (529) and your own usage (429) belong to the SDK's retries.
  2. Don't paper over a 403 permission error with a fallback. Tell a human.
  3. A backup model may want thinking written differently. Swap only the model ID and you can trade a 404 for a 400.

The third one is the easiest to miss. I hit it once: the fallback kicked in, and the backup immediately failed with a different error.

What this error is actually telling you

A 529 Overloaded or a 429 Rate Limit is about congestion or your own usage. Waiting usually works, so the SDK's automatic retries are the right tool. The official TypeScript SDK retries connection errors, 429s and 5xx responses twice by default with exponential backoff, and you can change that with the client's maxRetries option (checked against the official errors page, November 2026).

This error is different: "the model ID you named can't be accepted on this route." Sometimes it clears; for a retired model, it never will. If you handle both families with one net, you either push load onto your fallback during a congested spell or keep retrying a permanent refusal.

Here are the entries from the official error list that matter for this article:

StatustypeMeaning (paraphrasing the docs)What I do
400invalid_request_errorSomething is wrong with the request's format or contentFix the request. Fall back only if the message points at the model
403permission_errorThe key lacks permission for the resourceNo fallback. Notify a human
404not_found_errorThe requested resource was not foundFall back
429rate_limit_errorA rate limit or spend cap was hitNo fallback. Let the SDK retry
529overloaded_errorThe API is temporarily overloadedNo fallback. Let the SDK retry

The error text varies by route (Anthropic direct or a cloud provider) and over time, and the docs themselves recommend branching on the SDK's typed exceptions rather than matching strings. The deprecations page only says that requests to retired models "fail"; it doesn't name a status code, and I haven't verified every route myself. Please log the response you actually get once, in your own setup.

Telling the causes apart

In what I've seen, refusals fall into roughly six situations. I haven't measured frequencies, so I won't rank them.

SymptomLikely causeHow to checkFix
An ID that worked yesterday now returns 404The model retiredLook up its lifecycle in the Models API; compare with the deprecations pageMove to the recommended replacement; let the fallback cover the gap
Only a brand-new ID failsNot yet on this route or region, or a typoQuery the ID through the Models API with the same keyKeep the previous generation as primary for now
Fails only on Bedrock or Vertex AIProviders set their own model lists and datesCheck that provider's model table; Anthropic's dates cover Anthropic-operated routesKeep a candidate list per route
400 right after switching to the backupThe backup rejects the thinking settingRead the error and capabilities.thinking.types from the Models APIBuild thinking per model
403The key or workspace lacks accessCheck org and workspace settings in the ConsoleSwitching won't fix it. Notify and fix by hand
429 or 529 keeps coming backUsage or congestionIs there a retry-after header? A spend-cap 429 has noneRetry and throttle. Keep the model

Row five may be the one that matters most. Never hide a permission refusal behind a fallback. If the switch "works," you lose sight of a configuration mismatch you really needed to notice.

Ask the Models API at startup

I used to keep model capabilities and lifetimes in a hand-written table. It was only a matter of time before that went stale, and it did. These days I call the Models API (GET /v1/models/{model_id}) once when the process starts and cache the result.

According to the reference, the response carries lifecycle (active, deprecated or retired), retires_at (the scheduled retirement time), and, under capabilities.thinking.types, whether the model accepts adaptive, enabled, disabled and so on.

import Anthropic from "@anthropic-ai/sdk";
 
// Only the parts of the Models API response this article uses
interface ModelProbe {
  id: string;
  lifecycle: "active" | "deprecated" | "retired";
  retiresAt: string | null;
  thinkingAdaptive: boolean;
  thinkingEnabled: boolean;
}
 
async function probeModel(client: Anthropic, id: string): Promise<ModelProbe | null> {
  try {
    // Older SDK versions may not type the newer fields, so read them after the call
    const info = (await client.models.retrieve(id)) as unknown as Record<string, any>;
    const types = info.capabilities?.thinking?.types ?? {};
    return {
      id: info.id,
      lifecycle: info.lifecycle ?? "active",
      retiresAt: info.retires_at ?? null,
      thinkingAdaptive: Boolean(types.adaptive?.supported),
      thinkingEnabled: Boolean(types.enabled?.supported),
    };
  } catch (err) {
    if (err instanceof Anthropic.NotFoundError) return null; // no such ID
    throw err;
  }
}
 
async function probeChain(client: Anthropic, ids: string[]): Promise<Map<string, ModelProbe>> {
  const usable = new Map<string, ModelProbe>();
  for (const id of ids) {
    const p = await probeModel(client, id);
    if (!p) {
      console.error(`[models] ${id} not found — remove it from the chain`);
      continue;
    }
    if (p.lifecycle === "retired") {
      console.error(`[models] ${id} is retired`);
      continue;
    }
    if (p.lifecycle === "deprecated") {
      console.warn(`[models] ${id} is deprecated, retires_at=${p.retiresAt}`);
    }
    usable.set(id, p);
  }
  return usable;
}

This tells you, before any real traffic, whether every ID in your table exists and whether one is about to retire. The day the deprecated warning first appears is the day to start migrating. The docs also note that retires_at can be revised until retirement happens, and a past date on a deprecated model means retirement is overdue, not done — lifecycle is the actual signal. So I don't decide on the date alone.

Keep a fallback table

Next comes a table of "preferred model" and "backup" per use case. I used only IDs listed as Active on the official deprecations page as of November 2026.

type ModelTier = "frontier" | "balanced" | "fast";
 
interface ModelFallbackChain {
  primary: string;
  fallbacks: string[];
}
 
// Before editing, confirm each ID against the official models and deprecations pages
const FALLBACK_CHAINS: Record<ModelTier, ModelFallbackChain> = {
  frontier: { primary: "claude-opus-5-5", fallbacks: ["claude-opus-5", "claude-opus-4-8"] },
  balanced: { primary: "claude-sonnet-5-5", fallbacks: ["claude-sonnet-5", "claude-sonnet-4-6"] },
  fast: { primary: "claude-haiku-5-5", fallbacks: ["claude-sonnet-5"] },
};

My previous version had claude-sonnet-4-5 as the balanced backup. After November 30, that backup stops being one. An even older version listed IDs like claude-haiku-4 that I had never confirmed existed. The backup column turned out to be the place that needs the most care.

Audit the backup column as often as the primary. Rows that only run when something breaks are exactly the rows nobody reads, so they rot first.

Tell the rejections apart by exception class

I branch on the type of exception the SDK throws, not on substrings of the message. Wording changes; the meaning of a status code tends not to.

type Verdict = "fallback" | "alert" | "rethrow";
 
// 404: model not found -> switch
// 403: no permission -> don't switch, tell a human
// 429 / 529 / anything else: leave it to SDK retries, no fallback
function classify(err: unknown): Verdict {
  if (err instanceof Anthropic.NotFoundError) return "fallback";
  if (err instanceof Anthropic.PermissionDeniedError) return "alert";
  if (err instanceof Anthropic.BadRequestError) {
    // 400 also covers bad parameters; switch only when the message points at the model
    const msg = (err.message ?? "").toLowerCase();
    if (msg.includes("unavailable") || msg.includes("not available")) return "fallback";
  }
  return "rethrow";
}
 
async function invokeWithFallback(
  client: Anthropic,
  tier: ModelTier,
  usable: Map<string, ModelProbe>,
  buildRequest: (probe: ModelProbe) => Anthropic.Messages.MessageCreateParamsNonStreaming
): Promise<{ message: Anthropic.Messages.Message; depth: number }> {
  const chain = FALLBACK_CHAINS[tier];
  const candidates = [chain.primary, ...chain.fallbacks].filter((id) => usable.has(id));
  let lastError: unknown = new Error(`no usable model for tier ${tier}`);
 
  for (const [depth, modelId] of candidates.entries()) {
    try {
      const message = await client.messages.create(buildRequest(usable.get(modelId)!));
      return { message, depth };
    } catch (err) {
      const verdict = classify(err);
      if (verdict === "fallback") {
        console.warn(`model ${modelId} rejected, trying next`);
        lastError = err;
        continue;
      }
      if (verdict === "alert") {
        await notifyOwner(`permission denied for ${modelId}`); // wire this to your own channel
      }
      throw err; // anything we don't switch on goes back up, unswallowed
    }
  }
  throw lastError;
}

IDs that failed the startup probe never enter the candidate list. I keep 429 and 529 outside the fallback on purpose: moving the same load onto a backup during congestion doesn't, in my view, make anything better. Retries are the SDK's job via maxRetries; switching is reserved for "this model can't be accepted."

The backup may want thinking written differently

The trap I stepped in hardest is the thinking setting. The official thinking page has a per-model table of how each thinking value is handled. As of November 2026 it boils down to this:

Model generationNo thinking fieldtype: "adaptive"type: "enabled" + budget_tokens
Opus 5.5 / Sonnet 5.5 / Haiku 5.5 / Opus 5 / Sonnet 5Adaptive thinkingAccepted400
Opus 4.8 / Opus 4.7Thinking offAccepted400
Opus 4.6 / Sonnet 4.6Thinking offAcceptedAccepted (deprecated)
Opus 4.5 / Sonnet 4.5 / Haiku 4.5Thinking off400Accepted

So a budget_tokens request that falls over to a 5-series model gets a 400, and an adaptive request that falls back to the 4.5 generation gets a 400 too. My old code guessed capabilities from model names in a hand-written table, and on top of that passed budget_tokens: 16384 with max_tokens: 4096. The budget has to be smaller than max_tokens, so that request failed on the very first call, fallback or not. I "knew" it worked only because I had tested the path with thinking off.

Now I build the request from the ModelProbe captured at startup:

function buildRequestFor(
  probe: ModelProbe,
  prompt: string
): Anthropic.Messages.MessageCreateParamsNonStreaming {
  const base = {
    model: probe.id,
    max_tokens: 16000,
    messages: [{ role: "user" as const, content: prompt }],
  };
  if (probe.thinkingAdaptive) {
    // 5-series thinks adaptively even without this; 4.6–4.8 only think when it's set
    return { ...base, thinking: { type: "adaptive" } } as Anthropic.Messages.MessageCreateParamsNonStreaming;
  }
  if (probe.thinkingEnabled) {
    // Manual budget for the 4.5 generation; keep budget_tokens below max_tokens
    return { ...base, thinking: { type: "enabled", budget_tokens: 8000 } };
  }
  return base; // models without thinking get nothing extra
}

The as cast is there because some SDK versions don't type adaptive yet. If yours does, drop it. The rule hasn't changed from before: when unsure, remove features and make sure an answer comes back.

Claude Code's fallback versus a hand-rolled one

Claude Code has its own "fallback model chain" that moves to the next model when the primary is overloaded or unavailable. Per the official model configuration page, it never switches on authentication, billing, rate-limit or request-size errors; the switch lasts for the current turn only, so the next message tries the primary first again; and chains are capped at three models after removing duplicates.

AspectClaude Code fallback model chainThe hand-rolled version here
Switches onOverloaded, unavailable, other non-retryable server errors404, and 400s whose message points at the model
Never switches onAuth, billing, rate limit, size, transport403, 429, 529, everything else
How long the switch lastsOne turnOne request
Per-model feature handlingHandled by Claude CodeYours to write (thinking and more)

The two disagree on overload. For an interactive tool, getting some answer from another model is usually the kinder outcome. For the batch jobs I write, a change in output quality is itself the risk, so I'd rather wait. Interactive tools should keep answering; routine jobs should stay consistent. Which side you pick depends on what the job is for.

Common misunderstandings

"An undated ID won't retire." It will. The deprecations page states that the Sonnet 4.5 retirement includes the undated claude-sonnet-4-5. Writing the alias doesn't quietly move you to a successor.

"Bedrock and Vertex AI stop on the same day." The dates on the deprecations page apply to Anthropic-operated routes such as the Claude API; Amazon Bedrock and Google-managed Google Cloud set their own schedules. A different route can mean a different date.

"budget_tokens works on every model." On Opus 4.7 and later and on the 5 series it's a 400. On 4.6 it's accepted but deprecated. The more generations your chain mixes, the more likely you are to hit this.

Record that a switch happened

A fallback gets harder to notice the better it works. If the primary stays down and the backup quietly carries the load, everything still looks like success on screen.

interface ModelInvocationLog {
  timestamp: string;
  intendedModel: string;
  actualModel: string; // the response's model field
  fallbackDepth: number; // 0 = primary succeeded
  taskType: string;
  outcome: "success" | "all_failed";
}

I aggregate this once a week and look at the share of calls with fallbackDepth of 1 or more. The threshold worth acting on depends on how critical the job is, so I'd suggest watching a few weeks of real numbers before choosing one. I didn't pick a number up front either; I started by collecting. The docs also say the Console's Usage page can export a CSV broken down by API key and model, which is a handy way to see which key is still calling an ID that's about to retire.

Reproduce this path in development

Errors that only show up in production tend to get tested last. Passing a non-existent ID such as claude-opus-99-test as model should return a not-found error. Log the response you actually get once and use it as test data for classify, so CI can confirm each stage of the chain moves on correctly.

You can reproduce the thinking mismatch the same way. Sending type: "enabled" with budget_tokens to a 5-series model should return a 400; keep that response as a fixture for buildRequestFor.

Realising "I never tested this path" at the moment a model drops in production is a stomach-turning experience. Since that night I also test the case where every stage fails and the code reaches throw lastError.

Where people get stuck next

Once a fallback is in place, the next wall is usually the inventory: which IDs are written where. If an old ID survives in an environment variable or a saved setting, not just in code constants, the fallback will drop to the same backup every time.

Whether an undated alias escapes the retirement is covered in the undated claude-sonnet-4-5 and the November 30 deadline. Finding retiring models in the usage CSV is in inventorying usage CSVs before the Sonnet 4.5 retirement. For checking IDs against the catalog before a bulk replace, see catalog lookup before bulk-replacing model IDs, and for the wider picture of staying available across models, multi-model fallback for high availability may help.

One thing to do today

At startup, query every ID in your fallback table through the Models API once, and log any whose lifecycle isn't active. With November 30 coming up, that alone shows whether a retiring ID is hiding in your backup column.

That was my first step too, and it's how I ended up rewriting the backup column. The classify function that separates 404 from 403 can come after; I think that order is enough.

Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

If you found this article helpful, a small tip ($1.50) would mean a lot to us. Your support helps keep this site ad-free and covers server and hosting costs.

Related Articles

⬡ API & SDK2026-11-20
When the Claude API Only Says “Connection error.”, Follow the Exception Three Levels Down and Sort It Into Four Causes
The Python SDK raises the same APIConnectionError message for DNS, proxy, certificate, and timeout failures. Here is a script that walks __cause__, the real output from reproducing all four, and the order I fix them in.
⬡ API & SDK2026-05-22
Why tool_result could not be submitted Keeps Coming Back, and How to Build a Recovery Handler That Actually Holds
Run a Claude agent long enough and one day it starts: 'tool_result could not be submitted', back to back, and retries change nothing. The error message hides four completely different root causes. Here is what I learned debugging it on the always-on agent jobs I run as an indie developer, with the TypeScript recovery handler I now ship in production.
⬡ API & SDK2026-05-09
A Five-Layer Preflight Design for Claude API — Stopping Avoidable 400/422/529 Errors Before the Call
A production-tested five-layer preflight design that catches Claude API failures before the network call — schema, token budget, model capability, content policy, and spend cap — with a TypeScript implementation and the changes I saw in production.