Plugin event hook: How to detect 429 rate limit errors? #7475

Closed
opened 2026-02-16 18:07:18 -05:00 by yindo · 3 comments
Owner

Originally created by @cvrt-jh on GitHub (Jan 24, 2026).

Originally assigned to: @thdxr on GitHub.

Question

I'm developing a multi-account OAuth plugin that needs to detect 429 rate limit errors to automatically switch between accounts. However, I can't find a way to capture these errors through the plugin event system.

What I've tried

In my plugin's event hook, I'm listening for various event types:

async event({ event }) {
  // Checking for 429 in multiple locations
  if (event.type === "session.error") {
    const error = event.properties?.error;
    if (error?.data?.statusCode === 429) {
      // Handle rate limit
    }
  }
  
  if (event.type === "message.error") {
    // ...
  }
  
  // Also checking session.status with error type
}

When a rate limit occurs, OpenCode displays:

This request would exceed your account's rate limit. Please try again later. [retrying in 2h 45m attempt #1]

But no event is emitted through the plugin event system that I can detect.

Expected behavior

I would expect one of these:

  1. A session.error event with the 429 status code
  2. A message.error event with rate limit info
  3. Some other event type that indicates a rate limit occurred

Use case

My plugin manages multiple Claude Pro/Max OAuth accounts. When one account hits a rate limit, I want to automatically switch to another account and retry the request. This requires detecting the 429 error.

Questions

  1. Is there currently a way for plugins to detect 429 rate limit errors?
  2. If not, would you consider adding an event for this? Something like:
    event.type === "api.error" // or "rate_limit"
    event.properties.statusCode === 429
    event.properties.retryAfter === 9900 // seconds
    

Environment

  • OpenCode version: 1.1.34
  • Plugin: Custom OAuth multi-auth plugin

Thank you!

Originally created by @cvrt-jh on GitHub (Jan 24, 2026). Originally assigned to: @thdxr on GitHub. ## Question I'm developing a multi-account OAuth plugin that needs to detect 429 rate limit errors to automatically switch between accounts. However, I can't find a way to capture these errors through the plugin event system. ## What I've tried In my plugin's `event` hook, I'm listening for various event types: ```javascript async event({ event }) { // Checking for 429 in multiple locations if (event.type === "session.error") { const error = event.properties?.error; if (error?.data?.statusCode === 429) { // Handle rate limit } } if (event.type === "message.error") { // ... } // Also checking session.status with error type } ``` When a rate limit occurs, OpenCode displays: ``` This request would exceed your account's rate limit. Please try again later. [retrying in 2h 45m attempt #1] ``` But **no event is emitted** through the plugin event system that I can detect. ## Expected behavior I would expect one of these: 1. A `session.error` event with the 429 status code 2. A `message.error` event with rate limit info 3. Some other event type that indicates a rate limit occurred ## Use case My plugin manages multiple Claude Pro/Max OAuth accounts. When one account hits a rate limit, I want to automatically switch to another account and retry the request. This requires detecting the 429 error. ## Questions 1. Is there currently a way for plugins to detect 429 rate limit errors? 2. If not, would you consider adding an event for this? Something like: ```javascript event.type === "api.error" // or "rate_limit" event.properties.statusCode === 429 event.properties.retryAfter === 9900 // seconds ``` ## Environment - OpenCode version: 1.1.34 - Plugin: Custom OAuth multi-auth plugin Thank you!
yindo closed this issue 2026-02-16 18:07:18 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 24, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #8591: OAuth Marathon - multi-account credential rotation - Proposes automatic account switching on 429 rate limit errors
  • #9971: OAuth Enhancements - Multi-Account, YOLO Mode, Auto-Relogin - Includes multi-account OAuth rotation with automatic failover on rate limits
  • #1712: Implement exponential back-off when hitting rate limits - Related feature for handling rate limit retries

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 24, 2026): This issue might be a duplicate of existing issues. Please check: - #8591: OAuth Marathon - multi-account credential rotation - Proposes automatic account switching on 429 rate limit errors - #9971: OAuth Enhancements - Multi-Account, YOLO Mode, Auto-Relogin - Includes multi-account OAuth rotation with automatic failover on rate limits - #1712: Implement exponential back-off when hitting rate limits - Related feature for handling rate limit retries Feel free to ignore if none of these address your specific case.
Author
Owner

@cvrt-jh commented on GitHub (Jan 24, 2026):

Found related issue #9971 which proposes a comprehensive solution including:

  • Multi-account OAuth rotation with auto-switch on rate limits
  • Real-time rate limit display in UI
  • Providers tab in Settings

That issue has a working implementation with screenshots. My question about plugin event hooks for 429 detection would be solved if #9971 is merged, as the rate limit handling would be built into OpenCode core.

For now, I'll continue using my plugin with manual switching via CLI. Would love to see #9971 merged!

Closing this as duplicate of #9971.

@cvrt-jh commented on GitHub (Jan 24, 2026): Found related issue #9971 which proposes a comprehensive solution including: - Multi-account OAuth rotation with auto-switch on rate limits - Real-time rate limit display in UI - Providers tab in Settings That issue has a working implementation with screenshots. My question about plugin event hooks for 429 detection would be solved if #9971 is merged, as the rate limit handling would be built into OpenCode core. For now, I'll continue using my plugin with manual switching via CLI. Would love to see #9971 merged! Closing this as duplicate of #9971.
Author
Owner

@cvrt-jh commented on GitHub (Jan 24, 2026):

Closing as duplicate of #9971 which has a comprehensive implementation.

@cvrt-jh commented on GitHub (Jan 24, 2026): Closing as duplicate of #9971 which has a comprehensive implementation.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7475