arazzo: 1.0.1 info: title: Claude Batch Process and Retrieve Results summary: Submit a message batch, poll until it ends, then retrieve the JSONL results. description: >- The canonical asynchronous batch flow. The workflow submits a batch of message-creation requests for processing, polls the batch's status on a loop until its processing_status becomes ended (batches can take up to 24 hours and are billed at a 50 percent discount), and then retrieves the results as a JSONL stream. Polling uses a retry loop with a delay, and a branch routes the flow to result retrieval only once the batch has ended. Every step spells out its request inline — including the required x-api-key and anthropic-version headers — so the flow can be read and executed without opening the underlying OpenAPI description. version: 1.0.0 sourceDescriptions: - name: claudeApi url: ../openapi/claude-messages-api.yml type: openapi workflows: - workflowId: batch-process-and-retrieve-results summary: Create a message batch, wait for it to end, and pull its results. description: >- Submits a batch of requests, polls retrieveMessageBatch until processing ends, then streams the JSONL results. inputs: type: object required: - apiKey - requests properties: apiKey: type: string description: Anthropic API key sent in the x-api-key header. anthropicVersion: type: string description: Value for the required anthropic-version header. default: '2023-06-01' requests: type: array description: >- Array of batch request items, each with a custom_id and a params object matching a Create Message request. items: type: object steps: - stepId: submitBatch description: >- Submit the batch of message-creation requests for asynchronous processing, capturing the batch id and initial processing status. operationId: createMessageBatch parameters: - name: x-api-key in: header value: $inputs.apiKey - name: anthropic-version in: header value: $inputs.anthropicVersion requestBody: contentType: application/json payload: requests: $inputs.requests successCriteria: - condition: $statusCode == 200 outputs: batchId: $response.body#/id processingStatus: $response.body#/processing_status - stepId: pollBatchStatus description: >- Poll the batch status. While processing_status is not "ended", retry this step after a delay; once ended, proceed to retrieve the results. operationId: retrieveMessageBatch parameters: - name: x-api-key in: header value: $inputs.apiKey - name: anthropic-version in: header value: $inputs.anthropicVersion - name: message_batch_id in: path value: $steps.submitBatch.outputs.batchId successCriteria: - condition: $statusCode == 200 outputs: processingStatus: $response.body#/processing_status resultsUrl: $response.body#/results_url requestCounts: $response.body#/request_counts onSuccess: - name: retryWhileProcessing type: retry retryAfter: 30 retryLimit: 2880 criteria: - context: $response.body condition: $.processing_status != "ended" type: jsonpath - name: batchEnded type: goto stepId: retrieveResults criteria: - context: $response.body condition: $.processing_status == "ended" type: jsonpath - stepId: retrieveResults description: >- Stream the completed batch results as a JSONL file once the batch has ended. operationId: retrieveMessageBatchResults parameters: - name: x-api-key in: header value: $inputs.apiKey - name: anthropic-version in: header value: $inputs.anthropicVersion - name: message_batch_id in: path value: $steps.submitBatch.outputs.batchId successCriteria: - condition: $statusCode == 200 outputs: results: $response.body outputs: batchId: $steps.submitBatch.outputs.batchId requestCounts: $steps.pollBatchStatus.outputs.requestCounts resultsUrl: $steps.pollBatchStatus.outputs.resultsUrl results: $steps.retrieveResults.outputs.results