View Source Anthropic.HTTPTransport (anthropic_community v0.5.0)

The single internal request-sending layer. Anthropic.Messages.create/2 (via post/3), Anthropic.Models/Anthropic.Batches (via get/2, post/3, and delete/2), and Anthropic.Messages.stream/2 (via stream/3) all funnel through this module, so header-building, retry/backoff, and error-mapping are defined exactly once and never diverge between request styles.

Summary

Functions

Like delete/2, but accepts extra request-specific headers.

Like get/2, but accepts extra request-specific headers (e.g. the anthropic-beta header Anthropic.Files requires) without touching Client.default_headers.

Like get_raw/2, but for binary (non-text) response bodies — currently only used by Anthropic.Files.download/2. extra_headers works the same as post_multipart/4.

Like get/2, but takes a full URL and returns the raw text body rather than JSON-decoding it — used to fetch batch results (results_url), which is JSONL, not a single JSON document.

Sends a multipart/form-data POST (currently only used by Anthropic.Files.create/2). extra_headers lets callers add request-specific headers (e.g. the anthropic-beta header the Files API currently requires) without touching Client.default_headers.

Returns a lazy Stream.t() of Anthropic.Messages.StreamEvent structs for a POST-with-SSE-response request (currently only used by Anthropic.Messages.stream/2).

Functions

@spec delete(Anthropic.Client.t(), path :: String.t()) ::
  {:ok, map()} | {:error, Anthropic.Error.t()}
Link to this function

delete(client, path, extra_headers)

View Source
@spec delete(Anthropic.Client.t(), path :: String.t(), [{String.t(), String.t()}]) ::
  {:ok, map()} | {:error, Anthropic.Error.t()}

Like delete/2, but accepts extra request-specific headers.

@spec get(Anthropic.Client.t(), path :: String.t()) ::
  {:ok, map()} | {:error, Anthropic.Error.t()}
Link to this function

get(client, path, extra_headers)

View Source
@spec get(Anthropic.Client.t(), path :: String.t(), [{String.t(), String.t()}]) ::
  {:ok, map()} | {:error, Anthropic.Error.t()}

Like get/2, but accepts extra request-specific headers (e.g. the anthropic-beta header Anthropic.Files requires) without touching Client.default_headers.

Link to this function

get_binary(client, path, extra_headers \\ [])

View Source
@spec get_binary(Anthropic.Client.t(), path :: String.t(), [{String.t(), String.t()}]) ::
  {:ok, binary()} | {:error, Anthropic.Error.t()}

Like get_raw/2, but for binary (non-text) response bodies — currently only used by Anthropic.Files.download/2. extra_headers works the same as post_multipart/4.

@spec get_raw(Anthropic.Client.t(), url :: String.t()) ::
  {:ok, String.t()} | {:error, Anthropic.Error.t()}

Like get/2, but takes a full URL and returns the raw text body rather than JSON-decoding it — used to fetch batch results (results_url), which is JSONL, not a single JSON document.

Link to this function

post(client, path, params)

View Source
@spec post(Anthropic.Client.t(), path :: String.t(), params :: map()) ::
  {:ok, map()} | {:error, Anthropic.Error.t()}
Link to this function

post_multipart(client, path, fields, extra_headers \\ [])

View Source
@spec post_multipart(
  Anthropic.Client.t(),
  path :: String.t(),
  [Anthropic.HTTPTransport.Multipart.field()],
  [{String.t(), String.t()}]
) :: {:ok, map()} | {:error, Anthropic.Error.t()}

Sends a multipart/form-data POST (currently only used by Anthropic.Files.create/2). extra_headers lets callers add request-specific headers (e.g. the anthropic-beta header the Files API currently requires) without touching Client.default_headers.

Link to this function

stream(client, path, params)

View Source
@spec stream(Anthropic.Client.t(), path :: String.t(), params :: map()) ::
  Enumerable.t()

Returns a lazy Stream.t() of Anthropic.Messages.StreamEvent structs for a POST-with-SSE-response request (currently only used by Anthropic.Messages.stream/2).

The initial connection attempt goes through the same retry/backoff as post/4 (a 429/5xx before any bytes arrive is retried); once streaming has started, a mid-stream failure is delivered as a final %Anthropic.Messages.StreamEvent.Error{} element instead of raising or silently retrying (which would require replaying partial content).