post_to_api: Post to API with Retry

View source: R/utils_http.R

post_to_apiR Documentation

Post to API with Retry

Description

Makes a POST request to an API endpoint with automatic retry on failure. Implements exponential backoff and respects retry-after headers.

Usage

post_to_api(
  url,
  headers,
  body,
  max_retries = 2,
  initial_delay_ms = 2000,
  backoff_factor = 2,
  timeout_seconds = NULL,
  total_timeout_seconds = NULL,
  first_byte_timeout_seconds = NULL,
  connect_timeout_seconds = NULL,
  idle_timeout_seconds = NULL
)

Arguments

url

The API endpoint URL.

headers

A named list of HTTP headers.

body

The request body (will be converted to JSON).

max_retries

Maximum number of retries (default: 2).

initial_delay_ms

Initial delay in milliseconds (default: 2000).

backoff_factor

Multiplier for delay on each retry (default: 2).

timeout_seconds

Legacy alias for total_timeout_seconds.

total_timeout_seconds

Optional total request timeout in seconds. Defaults to getOption("aisdk.http_total_timeout_seconds"), then AISDK_HTTP_TOTAL_TIMEOUT_SECONDS, then legacy aisdk.http_timeout_seconds / AISDK_HTTP_TIMEOUT_SECONDS. No total timeout is applied by default.

first_byte_timeout_seconds

Optional time-to-first-byte timeout in seconds. Defaults to getOption("aisdk.http_first_byte_timeout_seconds"), then AISDK_HTTP_FIRST_BYTE_TIMEOUT_SECONDS, then 300.

connect_timeout_seconds

Optional connection-establishment timeout in seconds. Defaults to getOption("aisdk.http_connect_timeout_seconds"), then AISDK_HTTP_CONNECT_TIMEOUT_SECONDS, then 10.

idle_timeout_seconds

Optional stall timeout in seconds. When set, the request is aborted only if transfer progress drops below 1 byte/second for the full interval. Defaults to getOption("aisdk.http_idle_timeout_seconds"), then AISDK_HTTP_IDLE_TIMEOUT_SECONDS, then 120.

Value

The parsed JSON response.


aisdk documentation built on May 29, 2026, 9:07 a.m.