opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Implement exponential back-off when hitting rate limits

Open BigMitchGit opened this issue 5 months ago • 9 comments

OpenAI has some brutal RPM rate limits on tier 1, which will often abruptly stop opencode and requires me to manually resume by sending 'continue' message.

An exponential back-off with auto-retry would keep the agent loop running, it'd just take a bit longer to complete when rate limits are hit.

BigMitchGit avatar Aug 08 '25 11:08 BigMitchGit

If that helps here is error you get when you hit rate limit:

{"type":"error","sequence_number":2,"error":{"type":"tokens","code":"rate_limit_exceeded","message":"Rate limit reached
for gpt-5-mini in organization org-XXXXXXXXXXXXXX on tokens per min (TPM): Limit 200000, Used 124035,
Requested 79017. Please try again in 915ms. Visit https://platform.openai.com/account/rate-limits to learn
more.","param":null}}

daliusd avatar Aug 08 '25 17:08 daliusd

Same here: {"type":"error","sequence_number":2,"error":{"type":"tokens","code":"rate_limit_exceeded","message":"Rate limit reached for gpt-5 in organization org-************* on tokens per min (TPM): Limit 30000, Used 14582, Requested 21045. Please try again in 11.254s. Visit https://platform.openai.com/account/rate-limits to learn more.","param":null}}

AlexeyYar avatar Aug 09 '25 03:08 AlexeyYar

Yeah, Cerebras and Groq are currently unusable with Opencode right now still because of this.

Constant errors like:

AI_RetryError: Failed after 4 attempts. Last error: Too Many Requests

WilliamAGH avatar Aug 11 '25 19:08 WilliamAGH

Same, AI_RetryError: Failed after 4 attempts. Last error: Requests per second limit exceeded - too many requests sent.

cerebras with Qwen 3 Coder 480B

I can't get through the /init without the being blocked by this error, and unfortunately you can't resume the init.

JC1738 avatar Aug 14 '25 20:08 JC1738

Same here. On each message.

jsugg-qventus avatar Sep 12 '25 01:09 jsugg-qventus

After these rate limit stops, what do you type to make it continue? I've not had great luck.. Cerebras is awesome until the brick wall per minute limit

sra avatar Dec 09 '25 21:12 sra

We have backoff for ratelimits, and we respect the retry-after type headers so once it is ready to retry it should automatically go through

rekram1-node avatar Dec 09 '25 22:12 rekram1-node