class

Anthropic::AutoPaginator(T)

Inherits Enumerable < Reference < Object

Auto-paginating iterator for cursor-based list endpoints. Takes a fetcher proc that retrieves a single page and iterates across all pages automatically using after_id cursor tokens.

Example:

paginator = client.files.list_all(limit: 20)
paginator.each do |file|
  puts file.filename
end

Constructors

new(fetcher : Proc(ListParams, Page(T)), initial_limit : Int32 | Nil = nil)

Creates a new auto-paginator with the given fetcher proc. The fetcher should accept ListParams and return a Page(T).

Source
new(*, limit : Int32 | Nil = nil, &fetcher : ListParams -> Page(T))

Creates a new auto-paginator with a block. The block should accept ListParams and return a Page(T).

Source

Instance methods

each

Iterates over all items across all pages. Fetches pages lazily using after_id cursor until has_more? is false.

Source
to_a

Returns all items as an array (fetches all pages eagerly).

Source