Repository navigation
fix(anthropic): better 429/529 handling - #22
Conversation
|
hold off on merging this, it doesn't seem to resolve the 429 issue, still digging |
|
Are you able to figure out what rate limit we are hitting? I think it could be multiple things, maybe I am not managing something as I should 🤔 |
|
@adamdottv if you need to get more info you could log more stuff here https://github.com/kujtimiihoxha/termai/blob/main/internal/llm/agent/agent.go#L95 |
|
It is weird that I have not seen the same issues? (you are using it more than me 😂 💯 ) |
|
going to take a look this morning but realizing i'm not sure if the streaming response API call does retries at all, going to ask the stainless folks. |
|
yep! looks that way, i'll try to take this on this morning! |
|
ok, i've got anthropic 429s handled with eb8f2f5. i'll need to make similar changes to the other providers, will get on that shortly.
|
|
That is awesome 🙌 |
| } | ||
|
|
||
| // Inform user we're retrying with attempt number | ||
| eventChan <- ProviderEvent{ |
There was a problem hiding this comment.
Ok so I did not want to go through the trouble of forking the fork but here is a diff making some changes to how I handle the status bar messages that will allow you to now send messages to the status bar letting the user know about stuff like this.
I did not directly test this but let me know if it works for you.
Also we should most likely move the backoff logic to some util function.
Another thing to check is if there is a way to get that retry-after header to use here.
Our rate limits for the Messages API are measured in requests per minute (RPM), input tokens per minute (ITPM), and output tokens per minute (OTPM) for each model class. If you exceed any of the rate limits you will get a 429 error describing which rate limit was exceeded, along with a retry-after header indicating how long to wait.
|
@kujtimiihoxha sorry, this week getting busy real quick, back and forth getting bits of time on this and the current code is working, albeit with some minor UX issues (the status messages disappearing can feel bad when you've got a lmk what you think, once we're good with the anthropic version i can take a look at the other providers. |
|
forgot to call out that efea3f8 has the |
|
also noticed that anthropic will send 529's when they're "overloaded", so handling that in the same way as 429 |
| } | ||
|
|
||
| // Calculate backoff with exponential backoff and jitter | ||
| backoffMs := 2000 * (1 << (attempts - 1)) // 2s, 4s, 8s, 16s, 32s |
There was a problem hiding this comment.
I think since we now have retry-after exponential backoff should only be used when the error was the overloaded_error.
There was a problem hiding this comment.
I think you tried handling this by
// Fall back to exponential backoff if Retry-After parsing failed
But i think the code will always reach here and wait for an additional amount of time
There was a problem hiding this comment.
I will merge what is here so far and clean in up after.
|
@adamdottv here is what I changed 99630a5 Thanks again for helping out here, I did not even reach these limits so would never found this really appreciate your help man. |
|
THANK YOU lol, i started a task i didn't end up having consistent time to finish up, but this is huge for me to use the tool, i hit the throttle constantly (when not using Bedrock) |
fix(anthropic): better 429/529 handling


i'm getting a lot of 429 throttling responses from Anthropic, and it looks like the Anthropic SDK (along with all Stainless SDKs) defaults to just 2 retries. i've noticed claude code uses max 8 retries, so i went with that. (note: it handles the retries using exponential backoff with jitter.)