⚒️ Batch process prompts with Anthropic Claude API

1,974 views · ⚒️ Engineering

💡 Pro Tip — HTTP Request scraping tends to break when sites update their markup. If you’re scraping a major platform, check if ScraperNode covers it — it has maintained scrapers for LinkedIn, Instagram, TikTok, YouTube, and 20+ other platforms that return structured data.

View All Scrapers

Description

This workflow template provides a robust solution for efficiently sending multiple prompts to Anthropic’s Claude models in a single batch request and retrieving the results. It leverages the Anthropic Batch API endpoint (/v1/messages/batches) for optimized processing and outputs each result as a separate item.

Core Functionality & Example Usage Included

This template includes:

  1. The Core Batch Processing Workflow: Designed to be called by another n8n workflow.
  2. An Example Usage Workflow: A separate branch demonstrating how to prepare data and trigger the core workflow, including examples using simple strings and n8n’s Langchain Chat Memory nodes.

Who is this for?

This template is designed for:

What problem does this workflow solve?

Sending prompts to language models one by one can be slow and inefficient, especially when dealing with hundreds or thousands of requests. This workflow addresses that by:

Use Cases:

What the Core Workflow does

(Triggered by the ‘When Executed by Another Workflow’ node)

  1. Receive Input: The workflow starts when called by another workflow (e.g., using the ‘Execute Workflow’ node). It expects input data containing:
    • anthropic-version (string, e.g., “2023-06-01”)
    • requests (JSON array, where each object represents a single prompt request conforming to the Anthropic Batch API schema).
  2. Submit Batch Job: Sends the formatted requests data via POST to the Anthropic API /v1/messages/batches endpoint to create a new batch job. Requires Anthropic credentials.
  3. Wait & Poll: Enters a loop:
    • Checks if the processing_status of the batch job is ended.
    • If not ended, it waits for a set interval (10 seconds by default in the ‘Batch Status Poll Interval’ node).
    • It then checks the batch job status again via GET to /v1/messages/batches/{batch_id}. Requires Anthropic credentials.
    • This loop continues until the status is ended.
  4. Retrieve Results: Once the batch job is complete, it fetches the results file by making a GET request to the results_url provided in the batch status response. Requires Anthropic credentials.
  5. Parse Results: The results are typically returned in JSON Lines (.jsonl) format. The ‘Parse response’ Code node splits the response text by newlines and parses each line into a separate JSON object, storing them in an array field (e.g., parsed).
  6. Split Output: The ‘Split Out Parsed Results’ node takes the array of parsed results and outputs each result object as an individual item from the workflow.

Prerequisites

Setup

  1. Import Template: Add this template to your n8n instance.
  2. Configure Credentials:
    • Navigate to the ‘Credentials’ section in your n8n instance.
    • Click ‘Add Credential’.
    • Search for ‘Anthropic’ and select the Anthropic API credential type.
    • Enter your Anthropic API Key and save the credential (e.g., name it “Anthropic account”).
  3. Assign Credentials: Open the workflow and locate the three HTTP Request nodes in the core workflow:
    • Submit batch
    • Check batch status
    • Get results In each of these nodes, select the Anthropic credential you just configured from the ‘Credential for Anthropic API’ dropdown.
  4. Review Input Format: Understand the required input structure for the When Executed by Another Workflow trigger node. The primary inputs are anthropic-version (string) and requests (array). Refer to the Sticky Notes in the template and the Anthropic Batch API documentation for the exact schema required within the requests array.
  5. Activate Workflow: Save and activate the core workflow so it can be called by other workflows.

➡️ Quick Start & Input/Output Examples: Look for the Sticky Notes within the workflow canvas! They provide crucial information, including examples of the required input JSON structure and the expected output format.

How to customize this workflow

Example Usage Branch (Manual Trigger)

This template also contains a separate branch starting with the Run example Manual Trigger node.

Notes

🔗 Nodes Used

HTTP Request, Execute Sub-workflow, Execute Workflow Trigger, Filter, Execution Data, Simple Memory

📥 Import

Download workflow.json and import into n8n: Workflow menu → Import from File

📖 Importing guide · 🔑 Credential setup