{
  "id": "ly3YenqBdwoSpMEK",
  "name": "3. Generate Images with Realistic Inpainting using Simbrams Ri AI",
  "tags": [],
  "nodes": [
    {
      "id": "78c6eede-65a8-4f0e-86a9-a4a4faa6ade9",
      "name": "On clicking 'execute'",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -416,
        -192
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "39899545-740f-45eb-a325-c01352512fb7",
      "name": "Set API Key",
      "type": "n8n-nodes-base.set",
      "position": [
        -208,
        -192
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "64cd57c7-2224-48a6-88df-c37b310f8eb3",
              "name": "replicate_api_key",
              "type": "string",
              "value": "YOUR_REPLICATE_API_KEY"
            }
          ]
        }
      },
      "typeVersion": 3.3
    },
    {
      "id": "4d417d50-2ca9-4183-8d53-f2abfc099ce6",
      "name": "Create Prediction",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        32,
        -192
      ],
      "parameters": {
        "url": "https://api.replicate.com/v1/predictions",
        "method": "POST",
        "options": {
          "timeout": 60000
        },
        "jsonBody": "{\n  \"version\": \"1713fdec48707483a50e950ae63212c59293e6abff8abd1834c911b75b881d70\",\n  \"input\": {\n    \"image\": \"https://example.com/input.image\",\n    \"mask\": \"https://example.com/input.image\",\n    \"seed\": 1,\n    \"steps\": 20,\n    \"strength\": 0.8,\n    \"blur_mask\": true,\n    \"merge_m_s\": true\n  }\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "={{ 'Bearer ' + $('Set API Key').item.json.replicate_api_key }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "2a20626f-9dee-4d8c-a89d-6072cb95288d",
      "name": "Extract Prediction ID",
      "type": "n8n-nodes-base.code",
      "position": [
        240,
        -192
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Extract prediction ID and initial status\\nconst prediction = $input.item.json;\\nconst predictionId = prediction.id;\\nconst initialStatus = prediction.status;\\n\\n// Store the prediction ID for polling\\nreturn {\\n  predictionId: predictionId,\\n  status: initialStatus,\\n  predictionUrl: `https://api.replicate.com/v1/predictions/${predictionId}`\\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "23999701-4f37-4f44-af5e-f22930f20cea",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "position": [
        464,
        -192
      ],
      "parameters": {
        "unit": "seconds",
        "amount": 2
      },
      "typeVersion": 1
    },
    {
      "id": "1c024d8b-df2f-4dbf-823f-1576530b1ef2",
      "name": "Check Prediction Status",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        688,
        -192
      ],
      "parameters": {
        "url": "={{ $json.predictionUrl }}",
        "options": {},
        "sendHeaders": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "={{ 'Bearer ' + $('Set API Key').item.json.replicate_api_key }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "31b34b8e-9ff3-487f-af3c-ee55c1b10505",
      "name": "Check If Complete",
      "type": "n8n-nodes-base.if",
      "position": [
        912,
        -192
      ],
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.status }}",
              "value2": "succeeded"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b43dccd2-aa67-46a3-a8b3-03d4564c96fe",
      "name": "Process Result",
      "type": "n8n-nodes-base.code",
      "position": [
        1168,
        -304
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Process the completed prediction\\nconst result = $input.item.json;\\n\\nreturn {\\n  status: result.status,\\n  output: result.output,\\n  metrics: result.metrics,\\n  created_at: result.created_at,\\n  completed_at: result.completed_at,\\n  model: 'simbrams/ri',\\n  image_url: result.output\\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "4317bcbb-507a-4860-88e1-b84582dce079",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -480,
        -736
      ],
      "parameters": {
        "color": 2,
        "width": 438,
        "height": 751,
        "content": "## \ud83d\udccc Section 1: Trigger & Authentication\n\n### \u26a1 On Clicking \u2018Execute\u2019 (Manual Trigger)\n\n* **Purpose**: Starts the workflow manually.\n* **Benefit**: Useful for testing and running on demand.\n\n### \ud83d\udd11 Set API Key (Set Node)\n\n* **Purpose**: Stores your **Replicate API key** inside the workflow.\n* **Benefit**: Keeps credentials secure and ensures other nodes can reuse them.\n\n---\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "9bbe9a46-4abb-4b4c-a6e2-ac9d39d199b2",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2160,
        -928
      ],
      "parameters": {
        "color": 4,
        "width": 1300,
        "height": 320,
        "content": "=======================================\n            WORKFLOW ASSISTANCE\n=======================================\nFor any questions or support, please contact:\n    Yaron@nofluff.online\n\nExplore more tips and tutorials here:\n   - YouTube: https://www.youtube.com/@YaronBeen/videos\n   - LinkedIn: https://www.linkedin.com/in/yaronbeen/\n=======================================\n"
      },
      "typeVersion": 1
    },
    {
      "id": "acc9ee21-e337-4d97-84ca-766367765af0",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2160,
        -592
      ],
      "parameters": {
        "color": 4,
        "width": 1289,
        "height": 2590,
        "content": "# Generate Images with Realistic Inpainting using Simbrams Ri AI\n\nThis n8n workflow integrates with **Replicate\u2019s `simbrams/ri` model** to generate images. It takes an input image and mask, applies transformations based on your parameters, and returns the final generated output automatically.\n\n---\n\n## \ud83d\udccc Section 1: Trigger & Authentication\n\n### \u26a1 On Clicking \u2018Execute\u2019 (Manual Trigger)\n\n* **Purpose**: Starts the workflow manually.\n* **Benefit**: Useful for testing and running on demand.\n\n### \ud83d\udd11 Set API Key (Set Node)\n\n* **Purpose**: Stores your **Replicate API key** inside the workflow.\n* **Benefit**: Keeps credentials secure and ensures other nodes can reuse them.\n\n---\n\n## \ud83d\udccc Section 2: Sending the Image Generation Request\n\n### \ud83d\uddbc\ufe0f Create Prediction (HTTP Request Node)\n\n* **Purpose**: Sends a POST request to Replicate\u2019s API to start generating an image.\n* **Input Parameters**:\n\n  * **image**: Input image URL\n  * **mask**: Mask image URL\n  * **seed**: Randomness control (for reproducibility)\n  * **steps**: Number of refinement steps\n  * **strength**: Intensity of modification (0\u20131)\n  * **blur\\_mask**: Whether to blur the mask edges\n  * **merge\\_m\\_s**: Whether to merge mask with source\n* **Benefit**: Gives full control over how the model modifies your image.\n\n### \ud83c\udd94 Extract Prediction ID (Code Node)\n\n* **Purpose**: Extracts the **Prediction ID**, **status**, and **URL** from Replicate\u2019s response.\n* **Benefit**: Required to check the status of the generation later.\n\n---\n\n## \ud83d\udccc Section 3: Polling & Waiting\n\n### \u23f3 Wait (Wait Node)\n\n* **Purpose**: Pauses the workflow for 2 seconds before rechecking.\n* **Benefit**: Prevents hitting Replicate\u2019s API too quickly.\n\n### \ud83d\udd04 Check Prediction Status (HTTP Request Node)\n\n* **Purpose**: Checks whether the prediction is complete using the stored Prediction ID.\n* **Benefit**: Automates monitoring of job progress.\n\n### \u2705 Check If Complete (If Node)\n\n* **Purpose**: Decides if the prediction has finished.\n* **Paths**:\n\n  * **True** \u2192 Sends result to processing.\n  * **False** \u2192 Loops back to Wait and keeps checking.\n* **Benefit**: Ensures the workflow only ends when a valid image is ready.\n\n---\n\n## \ud83d\udccc Section 4: Processing the Result\n\n### \ud83d\udce6 Process Result (Code Node)\n\n* **Purpose**: Cleans up the completed API response and extracts:\n\n  * Status\n  * Output (final generated image)\n  * Metrics\n  * Created & completed timestamps\n  * Model name (`simbrams/ri`)\n  * Final **image URL**\n* **Benefit**: Delivers a structured and ready-to-use result for display, storage, or further automation.\n\n---\n\n## \ud83d\udcca Workflow Overview Table\n\n| Section           | Node Name               | Purpose                              |\n| ----------------- | ----------------------- | ------------------------------------ |\n| 1. Trigger & Auth | On Clicking \u2018Execute\u2019   | Starts the workflow manually         |\n|                   | Set API Key             | Stores API credentials               |\n| 2. AI Request     | Create Prediction       | Sends image generation request       |\n|                   | Extract Prediction ID   | Extracts ID + status for tracking    |\n| 3. Polling        | Wait                    | Adds delay between checks            |\n|                   | Check Prediction Status | Monitors job progress                |\n|                   | Check If Complete       | Routes based on job completion       |\n| 4. Result         | Process Result          | Extracts and cleans the final output |\n\n---\n\n## \ud83c\udfaf Key Benefits\n\n* \ud83d\udd10 **Secure authentication** with API key management.\n* \ud83d\uddbc\ufe0f **Custom image generation** with parameters like mask, strength, and steps.\n* \ud83d\udd04 **Automatic polling** ensures results are fetched only when ready.\n* \ud83d\udce6 **Clean structured output** with final image URL for easy use.\n\n---"
      },
      "typeVersion": 1
    },
    {
      "id": "aec13325-a44c-4237-8847-ac5f72c05dca",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -16,
        -912
      ],
      "parameters": {
        "color": 5,
        "width": 422,
        "height": 927,
        "content": "## \ud83d\udccc Section 2: Sending the Image Generation Request\n\n### \ud83d\uddbc\ufe0f Create Prediction (HTTP Request Node)\n\n* **Purpose**: Sends a POST request to Replicate\u2019s API to start generating an image.\n* **Input Parameters**:\n\n  * **image**: Input image URL\n  * **mask**: Mask image URL\n  * **seed**: Randomness control (for reproducibility)\n  * **steps**: Number of refinement steps\n  * **strength**: Intensity of modification (0\u20131)\n  * **blur\\_mask**: Whether to blur the mask edges\n  * **merge\\_m\\_s**: Whether to merge mask with source\n* **Benefit**: Gives full control over how the model modifies your image.\n\n### \ud83c\udd94 Extract Prediction ID (Code Node)\n\n* **Purpose**: Extracts the **Prediction ID**, **status**, and **URL** from Replicate\u2019s response.\n* **Benefit**: Required to check the status of the generation later.\n\n---\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "f9fbe6b7-da48-41c7-9a4b-9453f0fca6b7",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        432,
        -816
      ],
      "parameters": {
        "color": 6,
        "width": 598,
        "height": 831,
        "content": "## \ud83d\udccc Section 3: Polling & Waiting\n\n### \u23f3 Wait (Wait Node)\n\n* **Purpose**: Pauses the workflow for 2 seconds before rechecking.\n* **Benefit**: Prevents hitting Replicate\u2019s API too quickly.\n\n### \ud83d\udd04 Check Prediction Status (HTTP Request Node)\n\n* **Purpose**: Checks whether the prediction is complete using the stored Prediction ID.\n* **Benefit**: Automates monitoring of job progress.\n\n### \u2705 Check If Complete (If Node)\n\n* **Purpose**: Decides if the prediction has finished.\n* **Paths**:\n\n  * **True** \u2192 Sends result to processing.\n  * **False** \u2192 Loops back to Wait and keeps checking.\n* **Benefit**: Ensures the workflow only ends when a valid image is ready.\n\n---\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "96b87521-c75e-44b4-a7a9-048762dd27af",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1056,
        -848
      ],
      "parameters": {
        "color": 3,
        "width": 326,
        "height": 863,
        "content": "## \ud83d\udccc Section 4: Processing the Result\n\n### \ud83d\udce6 Process Result (Code Node)\n\n* **Purpose**: Cleans up the completed API response and extracts:\n\n  * Status\n  * Output (final generated image)\n  * Metrics\n  * Created & completed timestamps\n  * Model name (`simbrams/ri`)\n  * Final **image URL**\n* **Benefit**: Delivers a structured and ready-to-use result for display, storage, or further automation.\n\n---\n\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "a2791c4a-70cc-41b3-85c5-f3d6974174ee",
  "connections": {
    "Wait": {
      "main": [
        [
          {
            "node": "Check Prediction Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set API Key": {
      "main": [
        [
          {
            "node": "Create Prediction",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check If Complete": {
      "main": [
        [
          {
            "node": "Process Result",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Prediction": {
      "main": [
        [
          {
            "node": "Extract Prediction ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Prediction ID": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On clicking 'execute'": {
      "main": [
        [
          {
            "node": "Set API Key",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Prediction Status": {
      "main": [
        [
          {
            "node": "Check If Complete",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}