OpenCode error
OpenCode: AI_RetryError: Failed after 4 attempts. Last error: Too Many Requests
AI_RetryError: Failed after 4 attempts. Last error: Too Many RequestsStatus: WorkaroundLast verified 3 documented fixes2 sources
What it means
OpenCode retried a request that the provider kept rejecting and gave up after the last attempt. A maintainer: "The retry message you see is taken directly from the response from the server". A Bedrock variant reads "AI_RetryError: Failed after 3 attempts, Last error: undefined: Too many tokens, please wait before trying again." (#545).
Causes
- Provider rate limiting. A maintainer replied "You may be getting rate limited?" (#2398).
- A low Bedrock rate limit allocation. A maintainer: "what is your rate limit allocated with bedrock? default is low but they will increase it" (#545).
How to fix it
- Fix 1.
For GitHub Copilot, check your Copilot dashboard. You can also log out and log back in (maintainer, #2398).
Terminalopencode auth logout - Fix 2.
For Amazon Bedrock, check your account's rate limit allocation and ask AWS to raise it if needed (maintainer, #545).
- Fix 3.
Upgrade. The retry count was raised to 10 in v0.1.183 (maintainer, #545).
Terminalopencode upgrade
More OpenCode errors
All 17 OpenCode errorsProviderModelNotFoundErrorStatus: By designProviderInitErrorStatus: WorkaroundAI_APICallErrorStatus: WorkaroundThis credential is only authorized for use with Claude Code and cannot be used for other API requests.Status: By designAI_APICallError: messages.13: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01CfJCsh21fK1pAXsXWYJYBA, toolu_01NoqnwsaxoK3AYM2FyrxmjN. Each `tool_use` block must have a corresponding `tool_result` block in the next message.Status: Fixed in releasemessages.3.content.0.type: Expected `thinking` or `redacted_thinking`, but found `tool_use`. When `thinking` is enabled, a final `assistant` message must start with a thinking block (preceeding the lastmost set of `tool_use` and `tool_result` blocks). We recommend you include thinking blocks from previous turns. To avoid this requirement, disable `thinking`.Status: WorkaroundError: Unexpected error, check log file at [user-home]/.local/share/opencode/log/2025-08-26T215857.log for more detailsStatus: Workaroundundefined: The provided model identifier is invalid.Status: Fixed in release
Related reading
- Give Every Agent PR a Live Preview: Railway Environments for AI Pull RequestsRailway preview environments for agent pull requests: an isolated copy of your whole stack for every PR, so you verify agent changes by running them.
- Put an AI Agent Behind a Webhook: Turn GitHub Issues into Pull RequestsDeploy an AI agent behind a GitHub webhook on Railway with OpenCode headless, so a labeled issue becomes a tested pull request. The full build, step by step.
- OpenCode Cache Warming: What v2.2.7 Changed and When to Turn It OnOpenCode v2.2.7 makes cache warming time its pings from the model cache TTL. The config, the cost of idle pings, and when warming is a bad trade.
- T3 Code: Open-Source GUI for Claude Code and CodexT3 Code is a free, MIT-licensed desktop, web and mobile app that drives Claude Code, Codex, Cursor, OpenCode and more. What it is, how remote access works, and what to check first.
- OpenCode Hacked: What the Console Breach Means for Your API KeysOpenCode disclosed a breach of its Console that may have exposed provider keys. Who is affected, what to rotate today, and why hosted key gateways are the real risk.
- OpenCode 2: How to Upgrade From v1 Without Breaking Your SetupOpenCode 2 upgrade from v1: what the migration guide says breaks (plugins, server API, TUI config), what carries over, and a safe checklist before you switch.
FAQ
What does "AI_RetryError: Failed after 4 attempts. Last error: Too Many Requests" mean in OpenCode?
OpenCode retried a request that the provider kept rejecting and gave up after the last attempt. A maintainer: "The retry message you see is taken directly from the response from the server". A Bedrock variant reads "AI_RetryError: Failed after 3 attempts, Last error: undefined: Too many tokens, please wait before trying again." (#545).
How do I fix "AI_RetryError: Failed after 4 attempts. Last error: Too Many Requests"?
There are 3 documented fixes. Start with the first: For GitHub Copilot, check your Copilot dashboard. You can also log out and log back in (maintainer, #2398).
Is this OpenCode error fixed?
Status: Workaround. No release removes the cause. The documented fixes work around it. Affected versions: Reported mid-2025 (v0.1.x to v1.0.126).
Sources
Last verified against 2 sources: official docs, maintainer replies and release notes.
Newsletter
Fixes for the tools you use, weekly
One email per week. New coding agent releases, what broke, and how developers are working around it.