-
Notifications
You must be signed in to change notification settings - Fork 623
UN-3344 [FIX] Activate litellm retry for all LLM providers #1867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
2ae9c3f
[FIX] Activate litellm retry for all LLM providers
chandrasekharan-zipstack 9467015
[FIX] Zero out max_retries to prevent double-retry with SDK providers
chandrasekharan-zipstack a02f0d9
UN-3344 [FIX] Honor explicit max_retries=0 and tighten retry param ty…
chandrasekharan-zipstack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
[FIX] Activate litellm retry for all LLM providers
litellm's wrapper-level retry (completion_with_retries) works for all providers including httpx-based ones (Anthropic, Vertex, Bedrock, Mistral, Azure AI Foundry), but only activates when num_retries is set in kwargs. Our adapters pass max_retries (from user UI config) which only works for SDK-based providers (OpenAI, Azure). httpx-based providers silently ignored it, resulting in zero retries on transient errors (500, 502, 503). Bridge the gap by copying the user's max_retries value into num_retries and setting retry_strategy to exponential_backoff_retry before calling litellm.completion(). litellm internally zeroes max_retries during wrapper retries to prevent double-retry with SDK providers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Loading branch information
commit 2ae9c3fd380ca424729d6690cf8ccbc476aadef4
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -207,6 +207,7 @@ def complete(self, prompt: str, **kwargs: object) -> dict[str, object]: | |
|
|
||
| completion_kwargs = self.adapter.validate({**self.kwargs, **kwargs}) | ||
| completion_kwargs.pop("cost_model", None) | ||
| self._set_litellm_retry_params(completion_kwargs) | ||
|
|
||
| # if hasattr(self, "model") and self.model not in O1_MODELS: | ||
| # completion_kwargs["temperature"] = 0.003 | ||
|
|
@@ -295,6 +296,7 @@ def stream_complete( | |
|
|
||
| completion_kwargs = self.adapter.validate({**self.kwargs, **kwargs}) | ||
| completion_kwargs.pop("cost_model", None) | ||
| self._set_litellm_retry_params(completion_kwargs) | ||
|
|
||
| for chunk in litellm.completion( | ||
| messages=messages, | ||
|
|
@@ -363,6 +365,7 @@ async def acomplete(self, prompt: str, **kwargs: object) -> dict[str, object]: | |
|
|
||
| completion_kwargs = self.adapter.validate({**self.kwargs, **kwargs}) | ||
| completion_kwargs.pop("cost_model", None) | ||
| self._set_litellm_retry_params(completion_kwargs) | ||
|
|
||
| response = await litellm.acompletion( | ||
| messages=messages, | ||
|
|
@@ -454,6 +457,24 @@ def get_metrics(self) -> dict[str, object]: | |
| def get_usage_reason(self) -> object: | ||
| return self.platform_kwargs.get("llm_usage_reason") | ||
|
|
||
| @staticmethod | ||
| def _set_litellm_retry_params(completion_kwargs: dict) -> None: | ||
| """Activate litellm's wrapper-level retry for all providers. | ||
|
|
||
| litellm's retry mechanism (completion_with_retries) only activates when | ||
| num_retries is set. Our adapters pass max_retries (from user UI config) | ||
| which only works for SDK-based providers (OpenAI, Azure). This bridges | ||
| the gap by copying max_retries into num_retries so httpx-based providers | ||
| (Anthropic, Vertex, Bedrock, Mistral, etc.) also get retries. | ||
|
|
||
| litellm internally sets max_retries=0 during wrapper retries to prevent | ||
| double-retry with SDK providers. | ||
| """ | ||
| max_retries = completion_kwargs.get("max_retries") | ||
| if max_retries: | ||
| completion_kwargs["num_retries"] = max_retries | ||
| completion_kwargs["retry_strategy"] = "exponential_backoff_retry" | ||
|
Comment on lines
+474
to
+480
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle zero and invalid retry counts explicitly. At Line 474, using a truthy check skips an explicit Suggested patch max_retries = completion_kwargs.get("max_retries")
- if max_retries:
- completion_kwargs["num_retries"] = max_retries
- completion_kwargs["retry_strategy"] = "exponential_backoff_retry"
+ if max_retries is None:
+ return
+ if not isinstance(max_retries, int) or max_retries < 0:
+ raise SdkError("Invalid max_retries: expected a non-negative integer")
+ completion_kwargs["num_retries"] = max_retries
+ if max_retries > 0:
+ completion_kwargs["retry_strategy"] = "exponential_backoff_retry"🤖 Prompt for AI Agents |
||
|
|
||
| def _record_usage( | ||
| self, | ||
| model: str, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.