# `Tinkex.API.Retry`
[🔗](https://github.com/North-Shore-AI/tinkex/blob/v0.4.0/lib/tinkex/api/retry.ex#L1)

Retry logic with exponential backoff for Tinkex API requests.

Implements Python SDK parity for retry behavior:
- Exponential backoff with jitter
- Configurable max retries
- Status-based retry decisions (429, 408, 409, 5xx)
- Retry-After header support
- x-should-retry header override

# `calculate_delay`

```elixir
@spec calculate_delay(non_neg_integer()) :: non_neg_integer()
```

Calculates retry delay with exponential backoff and jitter.

Python parity implementation:
- Base delay: INITIAL_RETRY_DELAY * 2^attempt
- Capped at: MAX_RETRY_DELAY
- Jitter: random value in range [0.75, 1.0]

## Examples

    iex> delay = calculate_delay(0)
    iex> delay >= 375 and delay <= 500
    true

    iex> delay = calculate_delay(5)
    iex> delay >= 7500 and delay <= 10000
    true

# `execute`

```elixir
@spec execute(Finch.Request.t(), atom(), timeout(), non_neg_integer(), boolean()) ::
  retry_result()
```

Executes a request with automatic retry logic.

Retries are governed by:
1. max_retries configuration (no wall-clock timeout)
2. Status codes (429, 408, 409, 5xx)
3. Connection errors (transport, HTTP)
4. x-should-retry header override

## Options

- `request` - Finch request to execute
- `pool` - Connection pool name
- `timeout` - Per-request timeout in milliseconds
- `max_retries` - Maximum number of retry attempts
- `dump_headers?` - Whether to log request details

## Returns

`{result, retry_count}` where result is `{:ok, response}` or `{:error, reason}`
and retry_count is the number of retries performed.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
