Skip to main content
The Cloudflare SDK provides configurable timeout and retry mechanisms to handle network issues and transient failures.

Timeout configuration

Requests time out after 60 seconds (60,000 milliseconds) by default.

Global timeout

Set a default timeout for all requests:

Per-request timeout

Override the timeout for individual requests:
Timeout values are specified in milliseconds. The default timeout is 60000 (1 minute).

Timeout errors

When a request times out, the SDK throws APIConnectionTimeoutError:

Retry behavior

The SDK automatically retries failed requests with exponential backoff.

Default retry policy

1

Retry attempts

Failed requests are retried up to 2 times by default (3 total attempts).
2

Retryable conditions

The following errors trigger automatic retries:
  • Connection errors (network failures)
  • 408 Request Timeout
  • 409 Conflict
  • 429 Rate Limit
  • ≥500 Internal Server Error
3

Exponential backoff

Retry delays increase exponentially:
  • Initial delay: 0.5 seconds
  • Maximum delay: 8 seconds
  • Jitter: Up to 25% variance

Configuring retries

Set the default retry behavior for all requests:
number
default:"2"
Maximum number of retry attempts. Set to 0 to disable retries.

Retry timing

The SDK uses exponential backoff with jitter to calculate retry delays:

Example retry timeline

Retry headers

The SDK respects server-provided retry timing:
Server-provided retry delays are only used if they fall within 0-60 seconds. Otherwise, the default exponential backoff applies.

Timeout and retry interaction

Timeouts apply to each individual request attempt, not the total time including retries:

Managing total time

To limit the total time including retries, use AbortSignal:

Request cancellation

Cancel in-flight requests using AbortSignal:
Cancelling a request does not guarantee the operation won’t complete on the server. Use idempotent operations when possible.

Best practices

1

Set appropriate timeouts

Choose timeout values based on expected operation duration:
2

Use retries for transient failures

Enable retries for operations that can safely be retried:
3

Monitor timeout errors

Track timeout patterns to identify issues:
4

Implement circuit breakers

Prevent cascading failures with circuit breaker patterns:
5

Handle rate limits gracefully

Respect 429 responses and retry headers:

Configuration reference

Complete ClientOptions for timeouts and retries:

Per-request options