Anthropic MessageBatch

Anthropic MessageBatch

Certified

Create, retrieve, or cancel an Anthropic Message Batch

Submits a batch of Messages API requests, retrieves one that already exists, or cancels it. Retrieving returns status and request counts; once status is ended, it also returns the results URL. Per-request outputs are written to internal storage (uri) unless fetchType is FETCH, FETCH_ONE, or NONE. Repeat RETRIEVE from a LoopUntil task until status is ended. Batches run asynchronously — most finish within an hour and all end within 24 hours — and are billed at half the real-time Messages API rate. Refer to the Anthropic Console for an API key and the Message Batches guide for API behavior.

yaml
type: io.kestra.plugin.anthropic.MessageBatch

Submit a message batch and retrieve it until processing ends.

yaml
id: anthropic_message_batch
namespace: company.team

tasks:
  - id: create_batch
    type: io.kestra.plugin.anthropic.MessageBatch
    apiKey: "{{ secret('ANTHROPIC_API_KEY') }}"
    mode: CREATE
    requests:
      - customId: capital-japan
        model: claude-sonnet-4-6
        maxTokens: 64
        messages:
          - type: USER
            content: "What is the capital of Japan? Answer with one word and no punctuation."
      - customId: capital-france
        model: claude-sonnet-4-6
        maxTokens: 64
        messages:
          - type: USER
            content: "What is the capital of France? Answer with one word and no punctuation."

  - id: wait_until_ended
    type: io.kestra.plugin.core.flow.LoopUntil
    condition: "{{ outputs.retrieve.status == 'ended' }}"
    checkFrequency:
      interval: PT30S
      maxDuration: PT24H
    tasks:
      - id: retrieve
        type: io.kestra.plugin.anthropic.MessageBatch
        apiKey: "{{ secret('ANTHROPIC_API_KEY') }}"
        mode: RETRIEVE
        fetchType: STORE
        batchId: "{{ outputs.create_batch.batchId }}"
        retry:
          type: constant
          interval: PT30S
          maxAttempts: 3
          warningOnRetry: true

Cancel an in-progress message batch.

yaml
id: anthropic_cancel_message_batch
namespace: company.team

inputs:
  - id: batchId
    type: STRING

tasks:
  - id: cancel_batch
    type: io.kestra.plugin.anthropic.MessageBatch
    apiKey: "{{ secret('ANTHROPIC_API_KEY') }}"
    mode: CANCEL
    batchId: "{{ inputs.batchId }}"
Properties

Anthropic API Key

Possible Values
CREATERETRIEVECANCEL

Mode

CREATE submits requests and returns a batch id. RETRIEVE reads status and request counts for a batchId. When status is ended, it also returns request results according to fetchType. CANCEL asks Anthropic to stop a batch that has not ended yet.

Assets this task consumes as inputs or produces as outputs, for lineage tracking and the asset graph (Enterprise Edition). A flow declaring this property on a task is rejected in the open-source edition.

Definitions
assetFailureBehaviorstring
Possible Values
IGNOREFAILWARN

Asset failure behavior

Behavior applied to the task state when a declared asset fails to render, emit, or be persisted (e.g. a lock conflict): FAIL escalates it to FAILED, WARN (default) warns it if it would otherwise succeed, IGNORE leaves the state untouched.

enableAutobooleanstring

Whether to auto-register assets referenced dynamically at runtime that are not statically declared in inputs or outputs.

inputsarray

The assets consumed as inputs.

id*string
Min length1
typestring
outputs

The assets produced as outputs.

id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*string
Min length1

Custom asset type

descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150

Batch ID

Required when mode is RETRIEVE or CANCEL. Use the batchId output of CREATE.

DefaultSTORE
Possible Values
STOREFETCHFETCH_ONENONE

Fetch type

How to return per-request results once status is ended. Ignored unless mode is RETRIEVE. STORE (default) writes every row to Kestra internal storage as an ION file and sets uri and size. FETCH returns every row on results. FETCH_ONE returns only the first row on results. NONE skips the download and returns status only. A batch can hold 100,000 requests, so STORE avoids keeping the result file in memory and in the execution.

Requests

Required when mode is CREATE. Each item is one Messages API call. customId must be unique within the batch.

Definitions
customId*string
Validation RegExp^[a-zA-Z0-9_-]{1,64}$
Min length1

Custom ID

Developer-provided id, unique within the batch. Letters, digits, '_' and '-' only, 1-64 characters. Sent unchanged. Results are not ordered, so match them on this id.

messages*array
Min items1

Messages

Ordered chat turns for this request. Include at least one USER message.

contentstring
typestring
Possible Values
ASSISTANTUSER
model*string
Min length1

Model

Claude model for this request (for example, claude-sonnet-4-6).

maxTokensinteger
Minimum>= 1

Max tokens

Maximum tokens Anthropic can generate for this request. Defaults to 1024. Must be at least 1.

promptCachingboolean

Prompt caching

Cache the longest cacheable prefix of this request. Cached tokens are billed at a reduced rate.

systemstring

System prompt

Optional system instructions for this request.

temperaturenumber
Minimum>= 0
Maximum<= 1

Temperature

Sampling randomness from 0.0 to 1.0. Unset by default and only sent when provided.

topKinteger
Minimum>= 1

Top K

Sample only from the top K tokens. Unset by default. Must be at least 1 when set.

topPnumber
Minimum>= 0
Maximum<= 1

Top P

Nucleus sampling cap from 0.0 to 1.0. Unset by default.

Batch ID

Anthropic id of the Message Batch.

Request counts

Tallies by status. Counts other than processing stay at zero until the whole batch ends.

Definitions
canceledinteger

Canceled

Requests that were canceled.

erroredinteger

Errored

Requests that failed.

expiredinteger

Expired

Requests that expired before processing finished.

processinginteger

Processing

Requests still processing. This is the only non-zero tally until the batch ends.

succeededinteger

Succeeded

Requests that completed successfully.

Results

Per-request outputs. Set when fetchType is FETCH or FETCH_ONE and status is ended. Null for STORE, which writes uri instead. Match rows on customId; order is not guaranteed.

Definitions
cacheCreationInputTokensinteger

Cache creation input tokens

Tokens written to the prompt cache for this request.

cacheReadInputTokensinteger

Cache read input tokens

Tokens read from the prompt cache for this request.

customIdstring

Custom ID

The customId of the request this result belongs to.

errorMessagestring

Error message

Anthropic error message when the result type is errored.

outputTextstring

Output text

Assistant text extracted from a succeeded message.

rawResponsestring

Raw response

JSON for the succeeded message, or for the error payload when the request errored.

stopReasonstring

Stop reason

Why the model stopped generating (for example, end_turn or max_tokens).

typestring

Result type

succeeded, errored, canceled, expired, or unknown.

Results URL

URL of the JSONL results file. Present once processing has ended.

Size

Number of result rows stored or returned. Set when mode is RETRIEVE, status is ended, and fetchType is not NONE.

Status

Processing status: in_progress, canceling, or ended.

Formaturi

Results URI

Kestra internal storage URI of the ION results file. Set when fetchType is STORE and status is ended.

Unittoken

Tokens written to the prompt cache by succeeded requests whose results this RETRIEVE read. Emitted once, as a total.

Unittoken

Tokens read from the prompt cache by succeeded requests whose results this RETRIEVE read. Emitted once, as a total.

Unittoken

Input tokens consumed by succeeded requests whose results this RETRIEVE read. Emitted once, as a total.

Unittoken

Output tokens generated by succeeded requests whose results this RETRIEVE read. Emitted once, as a total.