All Products
Search
Document Center

Alibaba Cloud SDK:Retry mechanism

Last Updated:Sep 26, 2025

The V2.0 software development kit (SDK) has a built-in automatic retry mechanism for network exceptions. If a request fails because of a network issue, the system automatically retries the request to improve service stability and reliability. The SDK does not retry requests that fail because of business logic errors, such as invalid parameters or a resource that does not exist. Your application must handle these errors based on the error message instead of resending the request. This topic describes how to configure the automatic retry mechanism for network exceptions in the V2.0 SDK.

Configuration methods

Note

The priority of configurations is from highest to lowest: RuntimeOptions settings, then default configurations.

  • Use the default configurations. By default, requests are not retried. If you enable retries but do not specify the number of attempts, the system retries a failed request up to three times.

  • Configure retries using runtime parameters (RuntimeOptions).

    use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
    
    // Set runtime parameters. The settings take effect only on requests that use this RuntimeOptions instance.
    $runtime = new RuntimeOptions([
        "autoretry" => true, // Enables retries.
        "maxAttempts" => 3, // The maximum number of retries.
    ]);