write me the detailed json file of this n8n workflow , the json file should be suitable…
- User
write me the detailed json file of this n8n workflow , the json file should be suitable with n8n here is the workflow "To implement this in n8n, you can follow these steps:
-
Create a new workflow in n8n.
-
Add an HTTP Request node to send the POST request to create a new prediction. Configure the node as follows:
- HTTP Request Method: POST
- URL:
https://api.replicate.com/v1/predictions - Authentication: Add a new credential of type "Headers" with the following key-value pair:
- Key:
Authorization - Value:
Token <paste-your-token-here>
- Key:
- JSON Parameters: Add the following JSON data:
{ "version": "5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa", "input": { "text": "Alice" } }
-
Add a Function node to parse the response from the previous HTTP Request node and extract the
prediction_idfrom theidproperty. -
Add another HTTP Request node to send the GET request to retrieve the prediction status and output. Configure the node as follows:
- HTTP Request Method: GET
- URL:
https://api.replicate.com/v1/predictions/{{$node["Function"].json["id"]}} - Authentication: Same as the previous HTTP Request node
-
Add a Loop node to continuously check the prediction status until it is completed. Connect the Loop node to the second HTTP Request node.
-
Add a Switch node inside the Loop node to check the prediction status. Configure the Switch node with the following rules:
- If the
statusproperty issucceeded, the workflow can exit the Loop and proceed to the next step. - If the
statusproperty isfailedorcanceled, the workflow can exit the Loop and handle the error case. - If the
statusproperty isstartingorprocessing, the workflow should continue looping.
- If the
-
Add a Delay node inside the Loop node to introduce a delay (e.g., 5 seconds) between each iteration of the Loop to avoid overwhelming the API with too many requests.
-
Add a final node (e.g., Code node or No Operation node) to handle the successful prediction output or the error case.
By following these steps, you can create an n8n workflow that interacts with the Replicate API to create a prediction, continuously check its status, and retrieve the final output or handle any errors that may occur.
Note: You may need to adjust the configuration and add additional nodes based on your specific requirements, such as handling file inputs or outputs, or modifying the input data for different models."
-
- Assistant
Here's an example of the JSON file for the described n8n workflow. This JSON includes most of the setup you'll need to integrate with the Replicate API for creating a prediction and monitoring its status. Please replace
<paste-your-token-here>with your actual token for the workflow to authenticate correctly with the API.{ "name": "Replicate API Prediction Workflow", "nodes": [ { "parameters": { "authentication": "headerAuth", "requestMethod": "POST", "url": "https://api.replicate.com/v1/predictions", "options": {}, "bodyParametersUi": { "parameter": [ { "name": "version", "value": "5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa" }, { "name": "input", "value": "{\"text\":\"Alice\"}" } ] }, "headerParametersUi": { "parameter": [ { "name": "Authorization", "value": "Token <paste-your-token-here>" } ] } }, "name": "HTTP Request", "type": "n8n-nodes-base.httpRequest", "typeVersion": 1, "position": [ 250, 300 ] }, { "parameters": { "functionCode": "return [{json: {id: items[0].json.body.id}}];" }, "name": "Function", "type": "n8n-nodes-base.function", "typeVersion": 1, "position": [ 500, 300 ] }, { "parameters": { "authentication": "headerAuth", "requestMethod": "GET", "url": "={{`https://api.replicate.com/v1/predictions/${$node[\"Function\"].json[\"id\"]}`}}", "headerParametersUi": { "parameter": [ { "name": "Authorization", "value": "Token <paste-your-token-here>" } ] } }, "name": "HTTP Request2", "type": "n8n-nodes-base.httpRequest", "typeVersion": 1, "position": [ 750, 450 ] }, { "parameters": {}, "name": "Loop", "type": "n8n-nodes-base.loop", "typeVersion": 1, "position": [ 750, 300 ] }, { "parameters": { "conditions": { "boolean": [], "string": [ { "value1": "={{$json[\"status\"]}}", "operation": "equals", "value2": "succeeded" } ] } }, "name": "Switch", "type": "n8n-nodes-base.switch", "typeVersion": 1, "position": [ 1000, 300 ] }, { "parameters": { "value": 5 }, "name": "Delay", "type": "n8n-nodes-base.delay", "typeVersion": 1, "position": [ 1250, 300 ] }, { "parameters": {}, "name": "NoOp", "type": "n8n-nodes-base.noOp", "typeVersion": 1, "position": [ 1500, 300 ] } ], "connections": { "HTTP Request": { "main": [ [ { "node": "Function", "type": "main", "index": 0 } ] ] }, "Function": { "main": [ [ { "node": "Loop", "type": "main", "index": 0 } ] ] }, "Loop": { "main": [ [ { "node": "HTTP Request2", "type": "main", "index": 0 } ] ] }, "HTTP Request2": { "main": [ [ { "node": "Switch", "type": "main", "index": 0 } ] ] }, "Switch": { "main": [ [ { "node": "NoOp", "type": "main", "index": 0 } ], [ { "node": "Delay", "type": "main", "index": 0 } ] ] }, "Delay": { "main": [ [ { "node": "Loop", "type": "main", "index": 0 } ] ] } } }This JSON defines a workflow that sends a POST request to Replicate's API, waits for the prediction to be processed, and checks its status in a loop using a Delay node. The
Switchnode is used to handle the prediction's status, leading to a successful output or an error handling step.Remember, before using this workflow, you should replace
<paste-your-token-here>with your actual Replicate API token in the HTTP Request nodes. Additionally, you might need to adjust the flow according to your specific use case or to match the particular details of the API you're interacting with.