◉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-04-26Intermediate

When Claude's API Returns 'Spanner Temporarily Unavailable': Triage and Retry Design

What to check first when the Claude API returns 'Spanner temporarily unavailable': telling your code apart from the provider side, exponential backoff with jitter, model fallback, and when a nightly batch should simply wait.

Claude API150Error Handling6SpannerTroubleshooting31RetriesReliability5

import { Callout } from '@/components/ui/callout';

I once found a nightly job, the one that generates image descriptions for my wallpaper apps, stopped about halfway at dawn. The log held the same line over and over.

Error: spanner temporarily unavailable

The status code was 503 some days and 500 on others, and resending the request a few dozen seconds later just worked. With nothing to reproduce, I couldn't tell whether my code or the API was at fault. It's the kind of error that makes your stomach sink a little.

The short version up front: most of the time the cause is a transient problem on the far side of the API, not in your request. But "just retry" is where the second incident begins. Here is what I worked through, in the order I worked through it.

What the Message Tells You, and What It Doesn't

"Spanner" is the name of a Google Cloud distributed database, so it's natural to read this as a data layer around the model being briefly unresponsive rather than the model itself failing. Anthropic hasn't published its internals, though, so that's my guess and nothing more.

Two things I'm fairly sure of:

  • It's transient; the same request often succeeds a little later
  • It's a different animal from a malformed request or bad credentials (those come back as 4xx)

The body usually looks something like this:

{
  "type": "error",
  "error": {
    "type": "api_error",
    "message": "Spanner temporarily unavailable. Please retry after a brief delay."
  }
}

Wording and types can change, so I match on status code first and treat the message text as a secondary hint.

The First Three Minutes of Triage

Right after seeing the error, I check three things.

First, Anthropic Status. If it's listed, you're done. But a short, localized blip often isn't listed, so I don't conclude "it must be me" just because the page is green.

Second, the request-id response header. Without it, support has almost nothing to investigate. I make sure it's written into the error log every time.

Third, whether my own retries are misbehaving. That's where I made my first mistake.

Three Ways a Naive Retry Loop Hurts

The first time I hit this, I ran something close to while True with immediate retries. It did not go well.

  • You add load to a system that's trying to recover, and slow it down
  • Your own connections pile up and healthy requests start waiting too
  • Failed attempts can still add to your usage

Only later did I see that staying quiet while the other side recovers is the most cooperative thing a client can do. These days I follow three rules: don't hit it immediately, don't hit it in sync, and don't hit it forever.

Backoff with Jitter, Then a Fallback

Short waits for short blips, wider gaps if it drags on, and finally a step down to a lighter model.

import random
import time
 
from anthropic import Anthropic, APIStatusError
 
client = Anthropic()
TRANSIENT = (500, 502, 503, 504, 529)
 
 
def is_transient(e: APIStatusError) -> bool:
    text = str(e).lower()
    return e.status_code in TRANSIENT or "temporarily unavailable" in text
 
 
def call_with_resilience(messages, model="claude-sonnet-4-6",
                         fallback="claude-haiku-4-5-20251001"):
    last = None
    # For brief blips: two quick tries
    delays = [0.2, 0.4]
    # For longer trouble: exponential backoff + jitter
    delays += [(2 ** n) + random.random() for n in range(3)]
 
    for d in delays:
        try:
            return client.messages.create(
                model=model, max_tokens=1024, messages=messages)
        except APIStatusError as e:
            if not is_transient(e):
                raise
            last = e
            time.sleep(d + random.random() * 0.2)
 
    # Last resort: step down to a lighter model
    try:
        return client.messages.create(
            model=fallback, max_tokens=1024, messages=messages)
    except APIStatusError:
        raise last

Three points matter here.

  • Add jitter. Without it, many processes retry at the same instant and create a second spike
  • Never retry 4xx errors (auth, malformed input). Hammering something that can't fix itself helps no one
  • Only fall back to a lighter model where lower quality is acceptable, and always log that the fallback happened

I've seen days when Sonnet struggled while Haiku went through. Routing may differ per model, but I can't say for sure.

Nightly Batches Should Lean Toward Waiting

What helped most in that dawn incident wasn't a cleverer retry; it was a decision to let things wait.

Unlike a chat screen, a few minutes' delay in a nightly batch bothers nobody. So I move failed items to a separate queue and reprocess them in the morning.

def process_batch(items):
    deferred = []
    for item in items:
        try:
            save(item, call_with_resilience(item.messages))
        except APIStatusError as e:
            if is_transient(e):
                deferred.append(item)
            else:
                raise
    if deferred:
        enqueue_for_retry(deferred, delay_hours=12)

If hours of latency are fine, you can also hand the work to the Message Batches API. It's built on an asynchronous premise, so short disruptions are easier to absorb.

Noticing Before the Official Page Does

The status page is coarse, and a few minutes of trouble rarely appears on it. So I keep a few small gauges inside the application.

  • Error rate per model over a five-minute window
  • Count of calls classified as transient errors
  • Number of times the model fallback fired

None of this needs special infrastructure. Increment a counter inside the retry function, and post a single line to Slack when it crosses a threshold. Knowing "something is wrong right now" before any announcement made my first response to users noticeably faster. Too many alerts get ignored, though, so I start with a high threshold, watch for about a week, and lower it gradually.

What Your Users Should See

I'd rather not show spanner temporarily unavailable to end users. What I do instead:

  • While retrying internally, say something soft like "It's a little busy right now"
  • If it still fails, show only "Please try again," and keep the details in server logs
  • For long forms, stash the input in the browser before asking them to retry

You can't reduce errors to zero. But how much they hurt your users is a design decision you control.

Telling Look-Alike Errors Apart

Errors that look alike call for different responses.

TypeTypical situationBasic response
overloaded (529)The model side is congestedBackoff, fallback
rate_limit_error (429)Your key is overusedReduce usage, follow retry-after
api_error (500)Internal faultRetry; if it persists, contact support with the request-id
spanner temporarily unavailablePresumed transient data-layer troubleThe three-step approach above

Logging both error.type and error.message saves you from guessing when you line the causes up later.

Next Step

If the same error keeps appearing in a short window, suspect the shape of your own requests before blaming the provider. Are you sending extremely long inputs back to back? Is Prompt Caching failing so every call goes out in full? In my case, it was the latter.

Start by pulling one request-id and timestamp from today's error log into a small table. Let the machine do the waiting; keep the judgment with me. That's a line I try to hold even when I'm woken up at night.

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-10-28
When web fetch fails, a 400 and a 200 point to different places
Does adding web fetch to tools return a 400, or a 200 with an error_code inside the result block? A two-layer triage across org settings, domain rules, and where a URL came from, plus a small Python helper whose branches I checked.
⬡ API & SDK2026-11-30
The unit price drops 20%, yet the bill may rise: estimating the Opus 4.5 to 5.5 switch before January 22
claude-opus-4-5-20251101 retires on January 22, 2027, and the official replacement is claude-opus-5-5. Prices fall by a fifth, but the tokenizer changes and thinking can no longer be turned off. You will be able to count the cost per 1,000 of your own requests and pick a replacement and an effort level.
⬡ API & SDK2026-11-25
After Sonnet 4.5 Retired: Checking the Three Things That Change Without an Error, Even When the Old Model No Longer Answers
claude-sonnet-4-5 retired from the Claude API on November 30, 2026, and calls now return a 404. Switching to claude-sonnet-5-5 raises no 400, yet thinking runs by default, max_tokens covers more than the answer, and stop_reason shifts. Three ways to fill the 'before' column after retirement (old logs, Bedrock, thinking on vs. off), a troubleshooting table, and how to get ahead of the Opus 4.5 deadline.