Skip to content

Return a clear error when the Anthropic usage limit is hit - #64

Merged
mattgodbolt merged 1 commit into
mainfrom
molty/usage-limit-error
Oct 31, 2026
Merged

mattgodbolt merged 1 commit into
mainfrom
molty/usage-limit-error

Conversation

@mattgodbolt-molty

Copy link
Copy Markdown
Contributor

From 2026-10-29 10:23 UTC until the limit was raised on 2026-10-30, every Claude Explain request returned a bare 500 Internal Server Error. The workspace had hit its monthly API spend limit, and Anthropic reports that as a 400 invalid_request_error ("You have reached your specified workspace API usage limits...") rather than a 429. Only 408/409/429/5xx were handled, so the 400 was re-raised and became a 500. That's 67 failed requests in CloudWatch, and the first we heard of it was a user on Discord.

Change

  • A 400 whose message mentions the usage limit now returns a structured error ("Claude Explain has reached its usage limit and is unavailable for now. Please try again later."), which the CE frontend already displays. It emits a new ClaudeExplainUsageLimit metric and logs at ERROR.
  • Any other API error that still propagates (e.g. a real malformed request) now emits ClaudeExplainApiError before re-raising, so unknown failures are countable too.
  • The timeout/transient path and the new path share one _failed_call_response helper. Behaviour and metrics on the existing paths are unchanged.
  • One line in CLAUDE.md's Anthropic gotchas notes the 400 and the separate workspace limit.

Testing

  • New tests: a usage-limit 400 gives the structured error and metric, and another 400 still raises and is counted.
  • uv run pytest passes (226), and uv run pre-commit run --all-files is clean.

The alarm on both metrics, and the image_tag bump that deploys this, are in an infra PR to follow.

🤖 Generated with Claude Code

Anthropic reports a spent workspace limit as a 400 invalid_request_error,
which fell through to a bare 500. Match it and return a structured error
with a ClaudeExplainUsageLimit metric, and count any other unhandled API
error as ClaudeExplainApiError so both can be alarmed on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mattgodbolt
mattgodbolt merged commit 6026fa1 into main Oct 31, 2026
2 checks passed
@mattgodbolt
mattgodbolt deleted the molty/usage-limit-error branch October 31, 2026 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants