{"meta":{"instanceId":"workflow-e53175dc","versionId":"1.0.0","createdAt":"2025-09-29T07:07:58.915533","updatedAt":"2025-09-29T07:07:58.915549","owner":"n8n-user","license":"MIT","category":"automation","status":"active","priority":"high","environment":"production"},"nodes":[{"id":"fa4f8fd6-3272-4a93-8547-32d13873bbc1","name":"Submit batch","type":"n8n-nodes-base.httpRequest","position":[180,40],"parameters":{"url":"{{ $env.API_BASE_URL }}","method":"POST","options":{},"jsonBody":"={ \"requests\": {{ JSON.stringify($json.requests) }} }","sendBody":true,"sendQuery":true,"sendHeaders":true,"specifyBody":"json","authentication":"{{ $credentials.predefinedCredentialType }}","queryParameters":{"parameters":[{}]},"headerParameters":{"parameters":[{"name":"anthropic-version","value":"={{ $json[\"anthropic-version\"] }}"}]},"nodeCredentialType":"YOUR_CREDENTIAL_HERE"},"credentials":{"anthropicApi":{"id":"ub0zN7IP2V83OeTf","name":"Anthropic account"}},"typeVersion":4.2,"notes":"This httpRequest node performs automated tasks as part of the workflow."},{"id":"2916dc85-829d-491a-a7a8-de79d5356a53","name":"Check batch status","type":"n8n-nodes-base.httpRequest","position":[840,115],"parameters":{"url":"{{ $env.BASE_URL }}","options":{},"sendHeaders":true,"authentication":"{{ $credentials.predefinedCredentialType }}","headerParameters":{"parameters":[{"name":"anthropic-version","value":"={{ $('When Executed by Another Workflow').item.json[\"anthropic-version\"] }}"}]},"nodeCredentialType":"YOUR_CREDENTIAL_HERE"},"credentials":{"anthropicApi":{"id":"ub0zN7IP2V83OeTf","name":"Anthropic account"}},"typeVersion":4.2,"notes":"This httpRequest node performs automated tasks as part of the workflow."},{"id":"1552ec92-2f18-42f6-b67f-b6f131012b3c","name":"When Executed by Another Workflow","type":"n8n-nodes-base.executeWorkflowTrigger","position":[-40,40],"parameters":{"workflowInputs":{"values":[{"name":"anthropic-version"},{"name":"requests","type":"array"}]}},"typeVersion":1.1,"notes":"This executeWorkflowTrigger node performs automated tasks as part of the workflow."},{"id":"4bd40f02-caf1-419d-8261-a149cd51a534","name":"Get results","type":"n8n-nodes-base.httpRequest","position":[620,-160],"parameters":{"url":"{{ $env.BASE_URL }}","options":{},"sendHeaders":true,"authentication":"{{ $credentials.predefinedCredentialType }}","headerParameters":{"parameters":[{"name":"anthropic-version","value":"={{ $('When Executed by Another Workflow').item.json[\"anthropic-version\"] }}"}]},"nodeCredentialType":"YOUR_CREDENTIAL_HERE"},"credentials":{"anthropicApi":{"id":"ub0zN7IP2V83OeTf","name":"Anthropic account"}},"typeVersion":4.2,"notes":"This httpRequest node performs automated tasks as part of the workflow."},{"id":"5df366af-a54d-4594-a1ab-7a9df968101e","name":"Parse response","type":"n8n-nodes-base.code","notes":"JSONL separated by newlines","position":[840,-160],"parameters":{"jsCode":"for (const item of $input.all()) {\n  if (item.json && item.json.data) {\n    // Split the string into individual JSON objects\n    const jsonStrings = item.json.data.split('\\n');\n\n    // Parse each JSON string and store them in an array\n    const parsedData = jsonStrings.filter(str => str.trim() !== '').map(str => JSON.parse(str));\n\n    // Replace the original json with the parsed array.\n    item.json.parsed = parsedData;\n  }\n}\n\nreturn $input.all();"},"notesInFlow":true,"typeVersion":2},{"id":"68aa4ee2-e925-4e30-a7ab-317d8df4d9bc","name":"If ended processing","type":"n8n-nodes-base.if","position":[400,40],"parameters":{"options":{},"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"combinator":"and","conditions":[{"id":"9494c5a3-d093-49c5-837f-99cd700a2f13","operator":{"type":"string","operation":"equals"},"leftValue":"={{ $json.processing_status }}","rightValue":"ended"}]}},"typeVersion":2.2,"notes":"This if node performs automated tasks as part of the workflow."},{"id":"2b974e3b-495b-48af-8080-c7913d7a2ba8","name":"Sticky Note","type":"n8n-nodes-base.stickyNote","position":[-200,-720],"parameters":{"width":1060,"height":520,"content":"### This workflow automates sending batched prompts to Claude using the Anthropic API. It submits multiple prompts at once and retrieves the results.\n\n#### How to use\n\nCall this workflow with array of `requests`\n\n```json\n{\n    \"anthropic-version\": \"2023-06-01\",\n    \"requests\": [\n        {\n            \"custom_id\": \"first-prompt-in-my-batch\",\n            \"params\": {\n                \"max_tokens\": 100,\n                \"messages\": [\n                    {\n                        \"content\": \"Hey Claude, tell me a short fun fact about video games!\",\n                        \"role\": \"user\"\n                    }\n                ],\n                \"model\": \"claude-3-5-haiku-20241022\"\n            }\n        }\n    ]\n}\n```\n"},"typeVersion":1,"notes":"This stickyNote node performs automated tasks as part of the workflow."},{"id":"928a30b5-5d90-4648-a82e-e4f1a01e47a5","name":"Sticky Note1","type":"n8n-nodes-base.stickyNote","position":[1200,-720],"parameters":{"width":980,"height":600,"content":"#### Results\n\nThis workflow returns an array of results with custom_ids.\n\n```json\n[\n    {\n        \"custom_id\": \"first-prompt-in-my-batch\",\n        \"result\": {\n            \"message\": {\n                \"content\": [\n                    {\n                        \"text\": \"Did you know that the classic video game Tetris was...\",\n                        \"type\": \"text\"\n                    }\n                ],\n                \"id\": \"msg_01AiLiVZT18XnoBD4r2w9x2t\",\n                \"model\": \"claude-3-5-haiku-20241022\",\n                \"role\": \"assistant\",\n                \"stop_reason\": \"end_turn\",\n                \"stop_sequence\": null,\n                \"type\": \"message\",\n                \"usage\": {\n                    \"cache_creation_input_tokens\": 0,\n                    \"cache_read_input_tokens\": 0,\n                    \"input_tokens\": 45,\n                    \"output_tokens\": 83\n                }\n            },\n            \"type\": \"succeeded\"\n        }\n    }\n]\n```"},"typeVersion":1,"notes":"This stickyNote node performs automated tasks as part of the workflow."},{"id":"5dcb554e-32df-4883-b5a1-b40305756201","name":"Batch Status Poll Interval","type":"n8n-nodes-base.wait","position":[620,40],"webhookId":"7efafe72-063a-45c6-8775-fcec14e1d263","parameters":{"amount":10},"typeVersion":1.1,"notes":"This wait node performs automated tasks as part of the workflow."},{"id":"c25cfde5-ab83-4e5a-a66f-8cc9f23a01f6","name":"Sticky Note2","type":"n8n-nodes-base.stickyNote","position":[-160,325],"parameters":{"color":4,"width":340,"height":620,"content":"# Usage example"},"typeVersion":1,"notes":"This stickyNote node performs automated tasks as part of the workflow."},{"id":"6062ca7c-aa08-4805-9c96-65e5be8a38fd","name":"Run example","type":"n8n-nodes-base.manualTrigger","position":[-40,625],"parameters":{},"typeVersion":1,"notes":"This manualTrigger node performs automated tasks as part of the workflow."},{"id":"9878729a-123d-4460-a582-691ca8cedf98","name":"One query example","type":"n8n-nodes-base.set","position":[634,775],"parameters":{"options":{},"assignments":{"assignments":[{"id":"1ea47ba2-64be-4d69-b3db-3447cde71645","name":"query","type":"string","value":"Hey Claude, tell me a short fun fact about bees!"}]}},"typeVersion":3.4,"notes":"This set node performs automated tasks as part of the workflow."},{"id":"df06c209-8b6a-4b6d-8045-230ebdfcfbad","name":"Delete original properties","type":"n8n-nodes-base.set","position":[1528,775],"parameters":{"options":{},"assignments":{"assignments":[{"id":"d238d62b-2e91-4242-b509-8cfc698d2252","name":"custom_id","type":"string","value":"={{ $json.custom_id }}"},{"id":"21e07c09-92e3-41e7-8335-64653722e7e9","name":"params","type":"object","value":"={{ $json.params }}"}]}},"typeVersion":3.4,"notes":"This set node performs automated tasks as part of the workflow."},{"id":"f66d6a89-ee33-4494-9476-46f408976b29","name":"Construct 'requests' array","type":"n8n-nodes-base.aggregate","position":[1968,625],"parameters":{"options":{},"aggregate":"aggregateAllItemData","destinationFieldName":"requests"},"typeVersion":1,"notes":"This aggregate node performs automated tasks as part of the workflow."},{"id":"0f9eb605-d629-4cb7-b9cb-39702d201567","name":"Set desired 'anthropic-version'","type":"n8n-nodes-base.set","notes":"2023-06-01","position":[2188,625],"parameters":{"options":{},"assignments":{"assignments":[{"id":"9f9e94a0-304b-487a-8762-d74421ef4cc0","name":"anthropic-version","type":"string","value":"2023-06-01"}]},"includeOtherFields":true},"notesInFlow":true,"typeVersion":3.4},{"id":"f71f261c-f4ad-4c9f-bd72-42ab386a65e1","name":"Execute Workflow 'Process Multiple Prompts in Parallel with Anthropic Claude Batch API'","type":"n8n-nodes-base.executeWorkflow","notes":"See above","position":[2408,625],"parameters":{"options":{"waitForSubWorkflow":true},"workflowId":{"__rl":true,"mode":"list","value":"xQU4byMGhgFxnTIH","cachedResultName":"Process Multiple Prompts in Parallel with Anthropic Claude Batch API"},"workflowInputs":{"value":{"requests":"={{ $json.requests }}","anthropic-version":"={{ $json['anthropic-version'] }}"},"schema":[{"id":"anthropic-version","type":"string","display":true,"removed":false,"required":false,"displayName":"anthropic-version","defaultMatch":false,"canBeUsedToMatch":true},{"id":"requests","type":"array","display":true,"removed":false,"required":false,"displayName":"requests","defaultMatch":false,"canBeUsedToMatch":true}],"mappingMode":"defineBelow","matchingColumns":["requests"],"attemptToConvertTypes":true,"convertFieldsToString":true}},"notesInFlow":true,"typeVersion":1.2},{"id":"bd27c1a6-572c-420d-84ab-4d8b7d14311b","name":"Build batch 'request' object for single query","type":"n8n-nodes-base.code","position":[1308,775],"parameters":{"jsCode":"// Loop over input items and modify them to match the response example, then return input.all()\nfor (const item of $input.all()) {\n  item.json.params = {\n    max_tokens: item.json.max_tokens,\n    messages: [\n      {\n        content: item.json.query,\n        role: \"user\"\n      }\n    ],\n    model: item.json.model\n  };\n}\n\nreturn $input.all();\n"},"typeVersion":2,"notes":"This code node performs automated tasks as part of the workflow."},{"id":"fa342231-ea94-43ab-8808-18c8d04fdaf8","name":"Simple Memory Store","type":"n8n-nodes-base.noOp","position":[644,595],"parameters":{"sessionKey":"YOUR_CREDENTIAL_HERE","sessionIdType":"customKey"},"typeVersion":1,"notes":"This memoryBufferWindow node performs automated tasks as part of the workflow."},{"id":"67047fe6-8658-45ba-be61-52cf6115f4e4","name":"Fill Chat Memory with example data","type":"n8n-nodes-base.noOp","position":[556,375],"parameters":{"mode":"insert","messages":{"messageValues":[{"message":"You are a helpful AI assistant"},{"type":"user","message":"Hey Claude, tell me a short fun fact about video games!"},{"type":"ai","message":"short fun fact about video games!"},{"type":"user","message":"No, an actual fun fact"}]}},"typeVersion":1,"notes":"This memoryManager node performs automated tasks as part of the workflow."},{"id":"dbb295b8-01fd-445f-ab66-948442b6c71d","name":"Build batch 'request' object from Chat Memory and execution data","type":"n8n-nodes-base.code","position":[1528,475],"parameters":{"jsCode":"const output = [];\n\nfor (const item of $input.all()) {\n  const inputMessages = item.json.messages;\n  const customId = item.json.custom_id;\n  const model = item.json.model;\n  const maxTokens = item.json.max_tokens;\n\n  if (inputMessages && inputMessages.length > 0) {\n    let systemMessageContent = undefined;\n    const transformedMessages = [];\n\n    // Process each message entry in sequence\n    for (const messageObj of inputMessages) {\n      // Extract system message if present\n      if ('system' in messageObj) {\n        systemMessageContent = messageObj.system;\n      }\n      \n      // Process human and AI messages in the order they appear in the object keys\n      // We need to determine what order the keys appear in the original object\n      const keys = Object.keys(messageObj);\n      \n      for (const key of keys) {\n        if (key === 'human') {\n          transformedMessages.push({\n            role: \"user\",\n            content: messageObj.human\n          });\n        } else if (key === 'ai') {\n          transformedMessages.push({\n            role: \"assistant\",\n            content: messageObj.ai\n          });\n        }\n        // Skip 'system' as we already processed it\n      }\n    }\n\n    const params = {\n      model: model,\n      max_tokens: maxTokens,\n      messages: transformedMessages\n    };\n\n    if (systemMessageContent !== undefined) {\n      params.system = systemMessageContent;\n    }\n\n    output.push({\n      custom_id: customId,\n      params: params\n    });\n  }\n}\n\nreturn output;"},"typeVersion":2,"notes":"This code node performs automated tasks as part of the workflow."},{"id":"f9edb335-c33d-45fc-8f9b-12d7f37cc23e","name":"Load Chat Memory Data","type":"n8n-nodes-base.noOp","position":[932,475],"parameters":{"options":{}},"typeVersion":1,"notes":"This memoryManager node performs automated tasks as part of the workflow."},{"id":"22399660-ebe5-4838-bad3-c542d6d921a3","name":"First Prompt Result","type":"n8n-nodes-base.executionData","position":[2848,525],"parameters":{"dataToSave":{"values":[{"key":"YOUR_CREDENTIAL_HERE","value":"={{ $json.result.message.content[0].text }}"}]}},"typeVersion":1,"notes":"This executionData node performs automated tasks as part of the workflow."},{"id":"0e7f44f4-c931-4e0f-aebc-1b8f0327647f","name":"Second Prompt Result","type":"n8n-nodes-base.executionData","position":[2848,725],"parameters":{"dataToSave":{"values":[{"key":"YOUR_CREDENTIAL_HERE","value":"={{ $json.result.message.content[0].text }}"}]}},"typeVersion":1,"notes":"This executionData node performs automated tasks as part of the workflow."},{"id":"e42b01e0-8fc5-42e1-aa45-aa85477e766b","name":"Split Out Parsed Results","type":"n8n-nodes-base.splitOut","position":[1060,-160],"parameters":{"options":{},"fieldToSplitOut":"parsed"},"typeVersion":1,"notes":"This splitOut node performs automated tasks as part of the workflow."},{"id":"343676b9-f147-4981-b555-8af570374e8c","name":"Filter Second Prompt Results","type":"n8n-nodes-base.filter","position":[2628,725],"parameters":{"options":{},"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"combinator":"and","conditions":[{"id":"9e4b3524-7066-46cc-a365-8d23d08c1bda","operator":{"name":"filter.operator.equals","type":"string","operation":"equals"},"leftValue":"={{ $json.custom_id }}","rightValue":"={{ $('Append execution data for single query example').item.json.custom_id }}"}]}},"typeVersion":2.2,"notes":"This filter node performs automated tasks as part of the workflow."},{"id":"c9f5f366-27c4-4401-965b-67c314036fb6","name":"Filter First Prompt Results","type":"n8n-nodes-base.filter","position":[2628,525],"parameters":{"options":{},"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"combinator":"and","conditions":[{"id":"9e4b3524-7066-46cc-a365-8d23d08c1bda","operator":{"name":"filter.operator.equals","type":"string","operation":"equals"},"leftValue":"={{ $json.custom_id }}","rightValue":"={{ $('Append execution data for chat memory example').item.json.custom_id }}"}]}},"typeVersion":2.2,"notes":"This filter node performs automated tasks as part of the workflow."},{"id":"0a5b9c3d-665b-4e35-be9e-c8297314969d","name":"Sticky Note3","type":"n8n-nodes-base.stickyNote","position":[110,-100],"parameters":{"height":300,"content":"## Submit batch request to Anthropic"},"typeVersion":1,"notes":"This stickyNote node performs automated tasks as part of the workflow."},{"id":"f19813a5-f669-45dd-a446-947a30b02b09","name":"Sticky Note4","type":"n8n-nodes-base.stickyNote","position":[350,-5],"parameters":{"width":640,"height":300,"content":"## Loop until processing status is 'ended'"},"typeVersion":1,"notes":"This stickyNote node performs automated tasks as part of the workflow."},{"id":"9f424fce-5610-4b85-9be6-4c2c403002db","name":"Sticky Note5","type":"n8n-nodes-base.stickyNote","position":[500,-200],"parameters":{"width":280,"height":180,"content":"### Retrieve Message Batch Results\n\n[User guide]({{ $env.WEBHOOK_URL }}"},"typeVersion":1,"notes":"This stickyNote node performs automated tasks as part of the workflow."},{"id":"b87673b1-f08d-4c51-8ee5-4d54557cb382","name":"Sticky Note6","type":"n8n-nodes-base.stickyNote","position":[900,380],"parameters":{"color":5,"width":820,"height":340,"content":"# Example usage with Chat History Node"},"typeVersion":1,"notes":"This stickyNote node performs automated tasks as part of the workflow."},{"id":"d6d8ac02-7005-40a1-9950-9517e98e315c","name":"Sticky Note7","type":"n8n-nodes-base.stickyNote","position":[180,720],"parameters":{"width":1540,"height":220,"content":"# Example usage with single query string"},"typeVersion":1,"notes":"This stickyNote node performs automated tasks as part of the workflow."},{"id":"0d63deb0-dece-4502-9020-d67c1f194466","name":"Sticky Note8","type":"n8n-nodes-base.stickyNote","position":[180,320],"parameters":{"color":3,"width":660,"height":400,"content":"# Environment setup\nFor Chat History Node"},"typeVersion":1,"notes":"This stickyNote node performs automated tasks as part of the workflow."},{"id":"cab94e09-6b84-4a38-b854-670241744db5","name":"Sticky Note9","type":"n8n-nodes-base.stickyNote","position":[2120,800],"parameters":{"height":220,"content":"## anthropic-version\n\n[Documentation]({{ $env.API_BASE_URL }}\n\nWhen making API requests, you must send an anthropic-version request header. For example, anthropic-version: `2023-06-01` (latest supported version)"},"typeVersion":1,"notes":"This stickyNote node performs automated tasks as part of the workflow."},{"id":"ab0a51a1-3c84-4a88-968b-fd46ab07de85","name":"Sticky Note10","type":"n8n-nodes-base.stickyNote","position":[2560,400],"parameters":{"color":5,"width":480,"height":300,"content":"# Example usage with Chat History Node (result)"},"typeVersion":1,"notes":"This stickyNote node performs automated tasks as part of the workflow."},{"id":"d91b9be7-ef32-48d6-b880-cab0e99ba9bc","name":"Sticky Note11","type":"n8n-nodes-base.stickyNote","position":[2560,700],"parameters":{"width":480,"height":300,"content":"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n# Example usage with single query string (result)"},"typeVersion":1,"notes":"This stickyNote node performs automated tasks as part of the workflow."},{"id":"341811e9-6677-42d9-be28-c388dbf68101","name":"Join two example requests into array","type":"n8n-nodes-base.merge","position":[1748,625],"parameters":{},"typeVersion":3.1,"notes":"This merge node performs automated tasks as part of the workflow."},{"id":"45a09f05-7610-4b0a-ab7f-0094c4b3f318","name":"Append execution data for single query example","type":"n8n-nodes-base.set","notes":"custom_id, model and max tokens","position":[1010,775],"parameters":{"options":{},"assignments":{"assignments":[{"id":"8276602f-689f-45c2-bce0-5df8500912b6","name":"custom_id","type":"string","value":"second-prompt-in-my-batch"},{"id":"2c513dc2-d8cb-4ba3-b3c1-ea79517b9434","name":"model","type":"string","value":"claude-3-5-haiku-20241022"},{"id":"b052140b-1152-4327-9c5a-5030b78990b7","name":"max_tokens","type":"number","value":100}]},"includeOtherFields":true},"notesInFlow":true,"typeVersion":3.4},{"id":"c4e35349-840c-4c81-852c-0d8cd9331364","name":"Append execution data for chat memory example","type":"n8n-nodes-base.set","notes":"custom_id, model and max tokens","position":[1308,475],"parameters":{"options":{},"assignments":{"assignments":[{"id":"8276602f-689f-45c2-bce0-5df8500912b6","name":"custom_id","type":"string","value":"first-prompt-in-my-batch"},{"id":"2c513dc2-d8cb-4ba3-b3c1-ea79517b9434","name":"model","type":"string","value":"claude-3-5-haiku-20241022"},{"id":"b052140b-1152-4327-9c5a-5030b78990b7","name":"max_tokens","type":"number","value":100}]},"includeOtherFields":true},"notesInFlow":true,"typeVersion":3.4},{"id":"058aedb1-fdfe-4edc-8d51-3b93ec7d232d","name":"Truncate Chat Memory","type":"n8n-nodes-base.noOp","notes":"ensure clean state","position":[180,475],"parameters":{"mode":"delete","deleteMode":"all"},"notesInFlow":true,"typeVersion":1}],"connections":{"Submit batch":{"main":[[],[],[],[],[],[],[],[],[]]},"Check batch status":{"main":[[],[],[],[],[],[],[],[],[]]},"Get results":{"main":[[],[],[],[],[],[],[],[],[]]}},"name":"Httprequest Workflow","settings":{"executionOrder":"v1","saveManualExecutions":true,"callerPolicy":"workflowsFromSameOwner","errorWorkflow":null,"timezone":"UTC","executionTimeout":3600,"maxExecutions":1000,"retryOnFail":true,"retryCount":3,"retryDelay":1000},"description":"Automated workflow: Httprequest Workflow. This workflow integrates 17 different services: stickyNote, httpRequest, filter, wait, executionData. It contains 45 nodes and follows best practices for error handling and security.","notes":"Excellent quality workflow: Httprequest Workflow. This workflow has been optimized for production use with comprehensive error handling, security, and documentation."}