longrun.
Batch processing
Build with LongRun / Batch processing

Batch processing

Let’s decide whether your files should become one result or be processed individually. That choice determines how we build the request.

1. Repeat a step for each file

Suppose you want to process ten documents independently. In the workflow builder, create a list input named documents and configure the processing step to map over it. Bind its file input to the current item, then return the mapped results.

Start by testing with two files. Once it works, publish the workflow and send their uploaded file IDs as shown below. Replace WORKFLOW_ID with your workflow ID too.

Send two uploaded file IDs
curl --request POST "https://api.uselongrun.app/v1/workflows/${WORKFLOW_ID}/runs" \
  --header "Authorization: Bearer ${API_KEY}" \
  --header "Content-Type: application/json" \
  --data "$(jq -n --arg FIRST_FILE_ID "${FIRST_FILE_ID}" --arg SECOND_FILE_ID "${SECOND_FILE_ID}" '{
  "inputs": {
    "documents": [
      $FIRST_FILE_ID,
      $SECOND_FILE_ID
    ]
  }
}')"

2. Or combine the files into one result

Now imagine you want those two PDFs joined together. You don’t need to repeat a step: Merge PDFs already accepts a list and combines it.

The example below puts FIRST_FILE_ID before SECOND_FILE_ID. Replace them with your uploaded IDs. This request produces one merged PDF.

Combine two PDFs into one
curl --request POST "https://api.uselongrun.app/v1/pdf/merge" \
  --header "Authorization: Bearer ${API_KEY}" \
  --header "Content-Type: application/json" \
  --data "$(jq -n --arg FIRST_FILE_ID "${FIRST_FILE_ID}" --arg SECOND_FILE_ID "${SECOND_FILE_ID}" '{
  "inputs": {
    "files": [
      $FIRST_FILE_ID,
      $SECOND_FILE_ID
    ]
  }
}')"

3. Check what the action accepts

A single-file input and a list input are different. Before sending several values, check the action reference to confirm that the field accepts a list and how many items it permits.

If a mapped run fails, inspect its step details to find the item that failed. Don’t assume the whole batch succeeded just because some files were processed.

4. Check the result

Replace RUN_ID with the returned id and poll until a terminal status, waiting between checks. A mapped workflow returns the names you configured in Return outputs. Merge PDFs returns one file under outputs.file. Download each resulting LongRun file by its id.

Check the run
curl --request GET "https://api.uselongrun.app/v1/runs/${RUN_ID}" \
  --header "Authorization: Bearer ${API_KEY}"
Download the result
curl --fail-with-body "https://api.uselongrun.app/v1/files/${FILE_ID}/content" \
  --header "Authorization: Bearer ${API_KEY}" \
  --output result.pdf