Skip to main content
The SDK automatically retries failed requests for transient errors like rate limits and server errors, with configurable back-off strategies.

Default Behavior

By default, the client retries requests up to 2 times with exponential back-off:
This means a request can be attempted up to 3 times total (1 initial + 2 retries).

Which Errors Are Retried

The SDK retries different error codes based on their characteristics:

Always Retried

Rate Limits (429) - Retried for all HTTP methods:
Rate limit errors respect the retry-after header when present.

Retried for Idempotent Methods

Server Errors (500, 503) - Only retried for GET and DELETE:
Server errors are only retried for idempotent methods (GET, DELETE) to avoid duplicate side effects like creating the same page twice.

Never Retried

These errors indicate client problems and are never retried:
  • unauthorized (401)
  • object_not_found (404)
  • validation_error (400)
  • invalid_request (400)
  • conflict_error (409)
  • Client-side errors (timeout, invalid path)

Retry Configuration

Customize retry behavior with RetryOptions:

RetryOptions

maxRetries
number
default:2
Maximum number of retry attempts. Set to 0 to disable retries.
initialRetryDelayMs
number
default:1000
Initial delay between retries in milliseconds. Used as base for exponential back-off when retry-after header is absent.
maxRetryDelayMs
number
default:60000
Maximum delay between retries in milliseconds. Caps both exponential back-off and retry-after values.

Disabling Retries

Set retry: false to disable all automatic retries:
This is useful when:
  • You want full control over retry logic
  • You’re implementing your own retry wrapper
  • You need predictable request timing for testing

Retry Delay Calculation

The SDK uses two strategies to determine retry delays:

1. Retry-After Header (Preferred)

When the API includes a retry-after header, the SDK waits for that duration:
The retry-after header supports two formats:
  • Delta-seconds: retry-after: 120 (wait 120 seconds)
  • HTTP-date: retry-after: Wed, 21 Oct 2026 07:28:00 GMT

2. Exponential Back-off with Jitter

When no retry-after header is present, the SDK uses exponential back-off with jitter:
Example delays with initialRetryDelayMs: 1000:
  • Attempt 1: 750-1500ms (1000 * 1 * (0.5 to 1.5))
  • Attempt 2: 1500-3000ms (1000 * 2 * (0.5 to 1.5))
  • Attempt 3: 3000-6000ms (1000 * 4 * (0.5 to 1.5))
Jitter prevents thundering herd when many clients retry simultaneously.

Examples

Aggressive Retries

Retry quickly with more attempts:

Conservative Retries

Retry slowly with fewer attempts:

No Retries

Disable retries completely:

Custom Retry Logic

Implement your own retry wrapper:

Retry Logging

Set logLevel to INFO or DEBUG to see retry attempts:
See Logging for more details.

Best Practices

  1. Use default retry settings - They work well for most use cases
  2. Don’t disable retries - Unless you have a specific reason
  3. Respect rate limits - The SDK handles this automatically
  4. Monitor retry patterns - Frequent retries may indicate API issues
  5. Set appropriate timeouts - Match timeoutMs to your retry strategy
Setting timeoutMs lower than your maximum retry delay can cause requests to timeout before retries complete.