View Source Anthropic.Pagination (anthropic_community v0.5.0)

Auto-paginating Stream helper for cursor-based list endpoints (Anthropic.Models.list_all/2, Anthropic.Batches.list_all/2). Walks pages forward via after_id/last_id, fetching each page lazily as the stream is consumed, until the API reports has_more: false (or a page comes back with no last_id to continue from).

A page-fetch failure raises Anthropic.Error from within the Stream — unlike Anthropic.Messages.stream/2, there's no typed "error event" in the wire protocol for list endpoints to deliver as a stream element instead, so raising (rescue-able, since Anthropic.Error is an exception) is the idiomatic Elixir way to surface it.

Summary

Types

@type fetch_page() :: (keyword() -> {:ok, page()} | {:error, Anthropic.Error.t()})
@type page() :: %{data: [term()], has_more: boolean(), last_id: String.t() | nil}

Functions

Link to this function

stream(opts, fetch_page)

View Source
@spec stream(
  keyword(),
  fetch_page()
) :: Enumerable.t()