Skip to content

Claude/Anthropic 500/502/503/504 server errors are not retried #21420

@rich-jojo

Description

@rich-jojo

Bug Report

What happened?

When Anthropic's API returns a transient server error (HTTP 500, 502, 503, or 504), OpenCode does not retry the request — it immediately fails with an error like:

{"type":"api_error","message":"Claude API returned a server error. This is usually temporary — try again in a moment."}

Expected behavior

Transient server errors should be retried with exponential backoff, the same way rate-limit errors (429) and overload errors (529) already are.

Root cause

In packages/opencode/src/provider/error.ts, parseAPICallError() trusts input.error.isRetryable from the Vercel AI SDK for non-OpenAI providers. The @ai-sdk/anthropic package only marks status codes 429 and 529 as isRetryable: true. Generic 500/502/503/504 responses get isRetryable: false, so SessionRetry.retryable() returns undefined and the retry loop stops immediately.

OpenAI already has a special override in isOpenAiErrorRetryable() — the same approach needs to be applied universally.

Environment

  • OpenCode version: latest dev
  • Provider: Anthropic (Claude)

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions