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 lastThree 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.
| Type | Typical situation | Basic response |
|---|---|---|
| overloaded (529) | The model side is congested | Backoff, fallback |
| rate_limit_error (429) | Your key is overused | Reduce usage, follow retry-after |
| api_error (500) | Internal fault | Retry; if it persists, contact support with the request-id |
| spanner temporarily unavailable | Presumed transient data-layer trouble | The 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.