Skip to content

Add --num-retries option to control API retry behavior #4659

@potatoqualitee

Description

@potatoqualitee

Issue

Problem

When API calls fail (due to configuration errors, auth issues, rate limits, etc.), aider uses litellm's default retry behavior which can cause users to wait extended periods (60+ seconds) before getting an error message. This is particularly frustrating when the underlying issue isn't transient and retries won't help.

For example, with Azure configuration errors, users currently experience:

Retrying in 8.0 seconds...
Retrying in 16.0 seconds...
Retrying in 32.0 seconds...

This adds up to nearly 1.5 minutes of waiting before seeing the actual error.

Proposed Solution

Add a --num-retries flag (and corresponding AIDER_NUM_RETRIES environment variable) to allow users to control retry behavior:

aider --num-retries 0  # Disable retries completely
aider --num-retries 1  # Retry once

This value should be passed through to litellm's num_retries parameter in completion calls.

Use Cases

  • Development/debugging: When testing API configurations, developers want immediate feedback rather than waiting through retry cycles
  • CI/CD environments: Automated systems benefit from fast failures
  • Production applications: Some users prefer to handle retries at a higher level in their architecture
  • Cost control: Fewer retries = fewer billable API calls when issues occur

Alternative Considered

Users could set LITELLM_NUM_RETRIES=0, but it's unclear if aider respects this environment variable, and an explicit aider flag would be more discoverable and consistent with aider's configuration patterns.

Version and model info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions