stream_anthropic: Stream from Anthropic API

View source: R/provider_anthropic.R

stream_anthropicR Documentation

Stream from Anthropic API

Description

Makes a streaming POST request to Anthropic and processes their SSE format. Anthropic uses event types like content_block_delta instead of OpenAI's format. Also handles OpenAI-compatible format for proxy servers.

Usage

stream_anthropic(
  url,
  headers,
  body,
  callback,
  max_retries = 5,
  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).

callback

A function called for each text delta.

max_retries

Maximum number of connection/first-event retries before any stream chunk has been delivered.

initial_delay_ms

Initial delay in milliseconds.

backoff_factor

Multiplier for delay on each retry.

timeout_seconds

Legacy alias for total_timeout_seconds.

total_timeout_seconds

Optional total stream timeout in seconds.

first_byte_timeout_seconds

Optional time-to-first-byte timeout in seconds.

connect_timeout_seconds

Optional connection-establishment timeout in seconds.

idle_timeout_seconds

Optional stall timeout in seconds.

Value

A GenerateResult object.


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