Jibu.Batches (Jibu v0.2.1)

Copy Markdown View Source

The Message Batches API: many Messages requests processed asynchronously at half price.

{:ok, batch} =
  Jibu.Batches.create(client, %{
    requests: [%{custom_id: "a", params: %{model: "claude-opus-5-5", max_tokens: 1024, messages: messages}}]
  })

Poll get/2 until processing_status is "ended". Then read results/2. Results arrive in any order. Match them by custom_id. Results are the API's JSON with string keys. See the batches guide.

Summary

Functions

Cancels a batch. Requests already processed keep their results.

Creates a batch. The body is sent unchanged.

Deletes a batch that has ended.

Retrieves a batch, including its processing_status and request_counts.

Returns one page. query takes the API's parameters, such as :limit and :after_id.

Fetches the results of an ended batch and returns them as a lazily decoded stream of maps.

Streams all batches across pages, forward only. Raises Jibu.Error when a page fails.

Functions

cancel(client, id)

@spec cancel(Req.Request.t(), String.t()) :: {:ok, map()} | {:error, Jibu.Error.t()}

Cancels a batch. Requests already processed keep their results.

create(client, body)

@spec create(Req.Request.t(), map()) :: {:ok, map()} | {:error, Jibu.Error.t()}

Creates a batch. The body is sent unchanged.

delete(client, id)

@spec delete(Req.Request.t(), String.t()) :: {:ok, map()} | {:error, Jibu.Error.t()}

Deletes a batch that has ended.

get(client, id)

@spec get(Req.Request.t(), String.t()) :: {:ok, map()} | {:error, Jibu.Error.t()}

Retrieves a batch, including its processing_status and request_counts.

list(client, query \\ [])

@spec list(Req.Request.t(), keyword()) :: {:ok, map()} | {:error, Jibu.Error.t()}

Returns one page. query takes the API's parameters, such as :limit and :after_id.

results(client, id)

@spec results(Req.Request.t(), String.t()) ::
  {:ok, Enumerable.t()} | {:error, Jibu.Error.t()}

Fetches the results of an ended batch and returns them as a lazily decoded stream of maps.

The whole JSONL body is held in memory while the stream is consumed.

stream(client, query \\ [])

@spec stream(Req.Request.t(), keyword()) :: Enumerable.t()

Streams all batches across pages, forward only. Raises Jibu.Error when a page fails.