You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LiteLlm retries even when HttpRetryOptions.attempts is 1 #8330
HttpRetryOptions.attempts includes the original request, so attempts=1 means no retries. LiteLlm forwards attempts unchanged as LiteLLM's num_retries, which counts retries after the first call. So attempts=1 still retries, and any other value gives one retry more than requested. ApigeeLlm already treats attempts as the total.
Steps to Reproduce:
Start an HTTP server that answers every POST with 503 and counts requests.
@abhishekacharya200. Reproduced on main: attempts=1 sends 3 requests here too.
One thing I noticed while testing: with num_retries = attempts - 1, attempts=3 still sends 5 requests, because LiteLLM copies num_retries into the SDK's max_retries and then retries again on top of that.
A workaround that worked for me is to send max_retries = max(attempts - 1, 0) and not set num_retries at all. Locally that gave exactly 1/2/3 requests for attempts=1/2/3.
Could you try that on your side and see if it holds up, ideally on a non-OpenAI provider too? If it works, please test it properly before updating #8331 with it.
Thanks for reproducing this and for the max_retries idea, it was worth testing properly.
I ran it against a local server that returns 503 to every POST and counts requests (LiteLLM 1.111.0, tiny backoff). Requests sent for attempts = 1 / 2 / 3:
Your max_retries version gives exactly 1/2/3 on openai/, same as you saw. It doesn't hold up on the other routes though: only the OpenAI SDK reads max_retries, so on anthropic/, ollama_chat/, hosted_vllm/ and the rest it sends a single request whatever attempts is, which turns retries off completely.
From the LiteLLM source: num_retries is applied by its own wrapper on every route (retry the call after a failure), and completion() also copies it into max_retries for provider SDKs. That second copy is why OpenAI-SDK-backed routes (openai/, lm_studio/, perplexity/, litellm_proxy/, github/ and some others) send more than asked with num_retries=attempts-1: 1/3/5 instead of 1/2/3. Passing both doesn't help because num_retries overrides max_retries.
So #8331 keeps num_retries = max(attempts - 1, 0). attempts=1 now means exactly one request on every route I tried, and the count is exact for attempts=2, 3 on non-OpenAI-SDK routes, but OpenAI-SDK routes still send extra requests when attempts > 1. I added a code comment about this and a test asserting max_retries isn't set. Making it exact everywhere would need ADK to own the retry loop and pass num_retries=0 to LiteLLM, which is a bigger change. If you'd rather go that way I'm happy to look at it as a follow-up.
Good catch @abhishekacharya200, and you're right. I'd only tested openai/ before. Rerunning on LiteLLM 1.111.0 gives your numbers: max_retries alone sends one request on anthropic/ and ollama_chat/ whatever attempts is, so it would switch retries off for most providers.
num_retries = max(attempts - 1, 0) as in #8331 is the better trade-off. attempts=1 is exact everywhere, and only OpenAI-SDK routes still overshoot for attempts >= 2, which your code comment covers. The retry tests pass on the branch, the same 4 fail on main, and it still merges cleanly.
Making it exact on every route by having ADK own the retry loop sounds like a sensible follow-up, but I'd keep it as a separate issue rather than grow this PR.
From my side #8331 looks good to go. It now needs a maintainer to approve the workflows and review it.
Activity
surajksharma07 commentedon Nov 25, 2026
@abhishekacharya200. Reproduced on main: attempts=1 sends 3 requests here too.
One thing I noticed while testing: with num_retries = attempts - 1, attempts=3 still sends 5 requests, because LiteLLM copies num_retries into the SDK's max_retries and then retries again on top of that.
A workaround that worked for me is to send max_retries = max(attempts - 1, 0) and not set num_retries at all. Locally that gave exactly 1/2/3 requests for attempts=1/2/3.
Could you try that on your side and see if it holds up, ideally on a non-OpenAI provider too? If it works, please test it properly before updating #8331 with it.
abhishekacharya200 commentedon Nov 25, 2026
Thanks for reproducing this and for the max_retries idea, it was worth testing properly.
I ran it against a local server that returns 503 to every POST and counts requests (LiteLLM 1.111.0, tiny backoff). Requests sent for attempts = 1 / 2 / 3:
Your max_retries version gives exactly 1/2/3 on openai/, same as you saw. It doesn't hold up on the other routes though: only the OpenAI SDK reads max_retries, so on anthropic/, ollama_chat/, hosted_vllm/ and the rest it sends a single request whatever attempts is, which turns retries off completely.
From the LiteLLM source: num_retries is applied by its own wrapper on every route (retry the call after a failure), and completion() also copies it into max_retries for provider SDKs. That second copy is why OpenAI-SDK-backed routes (openai/, lm_studio/, perplexity/, litellm_proxy/, github/ and some others) send more than asked with num_retries=attempts-1: 1/3/5 instead of 1/2/3. Passing both doesn't help because num_retries overrides max_retries.
So #8331 keeps num_retries = max(attempts - 1, 0). attempts=1 now means exactly one request on every route I tried, and the count is exact for attempts=2, 3 on non-OpenAI-SDK routes, but OpenAI-SDK routes still send extra requests when attempts > 1. I added a code comment about this and a test asserting max_retries isn't set. Making it exact everywhere would need ADK to own the retry loop and pass num_retries=0 to LiteLLM, which is a bigger change. If you'd rather go that way I'm happy to look at it as a follow-up.
surajksharma07 commentedon Nov 27, 2026
Good catch @abhishekacharya200, and you're right. I'd only tested openai/ before. Rerunning on LiteLLM 1.111.0 gives your numbers: max_retries alone sends one request on anthropic/ and ollama_chat/ whatever attempts is, so it would switch retries off for most providers.
num_retries = max(attempts - 1, 0) as in #8331 is the better trade-off. attempts=1 is exact everywhere, and only OpenAI-SDK routes still overshoot for attempts >= 2, which your code comment covers. The retry tests pass on the branch, the same 4 fail on main, and it still merges cleanly.
Making it exact on every route by having ADK own the retry loop sounds like a sensible follow-up, but I'd keep it as a separate issue rather than grow this PR.
From my side #8331 looks good to go. It now needs a maintainer to approve the workflows and review it.