Skip to content

Anthropic "Extra usage is required for long context requests" causes infinite retries #18684

@brendandebeasi

Description

@brendandebeasi

Bug description

When Anthropic returns the error "Extra usage is required for long context requests" (billing tier context limit), opencode classifies it as a retryable API error and retries indefinitely with exponential backoff (observed up to attempt #7 with 2-minute delays).

This error means the prompt exceeds the user's billing tier context window — retrying will never succeed. The correct behavior is to treat it as a context overflow and trigger compaction.

Steps to reproduce

  1. Use an Anthropic API key on a billing tier with a standard context limit
  2. Have a session grow large enough that the prompt exceeds the tier's context window
  3. Observe: Extra usage is required for long context requests. [retrying in 2m attempt #7]

Expected behavior

The error should be classified as context_overflow (same as "prompt is too long"), triggering compaction to reduce context size.

Actual behavior

Classified as a retryable API error. Retries indefinitely, never compacts, and can corrupt session message state from repeated partial writes.

Environment

  • opencode version: v1.3.0 / custom-build
  • Provider: Anthropic
  • OS: macOS

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