{
  "name": "Havis AI - Nano Banana 2",
  "nodes": [
    {
      "id": "0822a508-a188-44e4-a927-79a7de68fdba",
      "name": "Sticky Note - Workflow Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -144,
        896
      ],
      "parameters": {
        "width": 512,
        "height": 848,
        "content": "## Havis AI - Nano Banana 2\n\n### How it works\n\n1. The workflow shows a public n8n form for collecting a Nano Banana 2 request and a Havis API key.\n2. It converts the form values into the JSON payload expected by the Havis API.\n3. It submits the job to `https://havis.ai/api/nano-banana-2` and receives a task ID.\n4. It polls `https://havis.ai/api/task/{task_id}` until the job finishes or fails.\n5. It returns the task metadata, credit usage, payload, and generated result URLs.\n\n### Setup steps\n\n- [ ] Create a Havis API key at https://havis.ai/manager/profile.\n- [ ] Open the form trigger URL after importing this workflow into n8n.\n- [ ] Enter the required Nano Banana 2 inputs: prompt, mode, aspect_ratio, resolution, output_format, image_url_1.\n- [ ] Confirm your Havis account has enough credits before running the workflow.\n- [ ] Adjust the polling wait time if your executions need faster or slower status checks.\n\n### Customization\n\nChange default prompt values, optional fields, polling interval, or the final output fields to match your automation. Keep the Havis domain fixed unless you intentionally publish a separate private workflow."
      },
      "typeVersion": 1
    },
    {
      "id": "0882d3c6-c218-47ee-b5f2-eccb87127160",
      "name": "Sticky Note - Request Input",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        448,
        944
      ],
      "parameters": {
        "color": 7,
        "width": 320,
        "height": 384,
        "content": "## Collect request inputs\n\nThe form trigger captures the Havis API key plus the Nano Banana 2 inputs from the user.\n\nKey fields: prompt, mode, aspect_ratio, resolution, output_format, image_url_1, image_url_2, image_url_3, ...."
      },
      "typeVersion": 1
    },
    {
      "id": "f1820040-0a46-419a-af25-1e8a2a6c0a90",
      "name": "Sticky Note - Payload Preparation",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        848,
        944
      ],
      "parameters": {
        "color": 7,
        "width": 320,
        "height": 384,
        "content": "## Build API payload\n\nThe code node trims blank values, applies default options, and builds a clean JSON body. Optional images, video URLs, audio URLs, tags, modes, or resolution fields are only included when provided."
      },
      "typeVersion": 1
    },
    {
      "id": "f9fb3649-b11d-448c-92c9-e7af1d81e218",
      "name": "Sticky Note - API Submission",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1248,
        944
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 384,
        "content": "## Submit generation job\n\nThe HTTP request sends the prepared payload to Havis AI with a bearer token. A successful response should include a `task_id` and the number of credits used for the request."
      },
      "typeVersion": 1
    },
    {
      "id": "dbbb80ed-ca49-4bb9-b92a-da3e816b1e55",
      "name": "Sticky Note - Polling and Output",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1696,
        832
      ],
      "parameters": {
        "color": 7,
        "width": 880,
        "height": 720,
        "content": "## Poll and return result\n\nThe workflow waits, checks task status, branches on completed or failed states, and loops while the job is still processing. Completed runs return result URLs; failed runs return a readable error object."
      },
      "typeVersion": 1
    },
    {
      "id": "0f89b8b7-55a6-91d7-1d41-5a79bc4cb4fd",
      "name": "Form - Nano Banana 2",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        520,
        1120
      ],
      "parameters": {
        "options": {},
        "formTitle": "Havis AI - Nano Banana 2",
        "formFields": {
          "values": [
            {
              "fieldLabel": "api_key",
              "placeholder": "YOUR_HAVIS_API_KEY",
              "requiredField": true
            },
            {
              "fieldType": "textarea",
              "fieldLabel": "prompt",
              "placeholder": "A cyberpunk cityscape at night, ultra detailed",
              "requiredField": true
            },
            {
              "fieldType": "dropdown",
              "fieldLabel": "mode [optional]",
              "fieldOptions": {
                "values": [
                  {
                    "option": "text-to-image"
                  },
                  {
                    "option": "edit-image"
                  }
                ]
              }
            },
            {
              "fieldType": "dropdown",
              "fieldLabel": "aspect_ratio [optional]",
              "fieldOptions": {
                "values": [
                  {
                    "option": "1:1"
                  },
                  {
                    "option": "16:9"
                  },
                  {
                    "option": "9:16"
                  },
                  {
                    "option": "4:3"
                  },
                  {
                    "option": "3:4"
                  }
                ]
              }
            },
            {
              "fieldType": "dropdown",
              "fieldLabel": "resolution [optional]",
              "fieldOptions": {
                "values": [
                  {
                    "option": "1K"
                  },
                  {
                    "option": "2K"
                  },
                  {
                    "option": "4K"
                  }
                ]
              }
            },
            {
              "fieldType": "dropdown",
              "fieldLabel": "output_format [optional]",
              "fieldOptions": {
                "values": [
                  {
                    "option": "png"
                  },
                  {
                    "option": "jpg"
                  },
                  {
                    "option": "jpeg"
                  }
                ]
              }
            },
            {
              "fieldLabel": "image_url_1 [optional]",
              "placeholder": "https://example.com/source.png"
            },
            {
              "fieldLabel": "image_url_2 [optional]",
              "placeholder": "https://example.com/source.png"
            },
            {
              "fieldLabel": "image_url_3 [optional]",
              "placeholder": "https://example.com/source.png"
            },
            {
              "fieldLabel": "image_url_4 [optional]",
              "placeholder": "https://example.com/source.png"
            },
            {
              "fieldLabel": "image_url_5 [optional]",
              "placeholder": "https://example.com/source.png"
            },
            {
              "fieldLabel": "image_url_6 [optional]",
              "placeholder": "https://example.com/source.png"
            },
            {
              "fieldLabel": "image_url_7 [optional]",
              "placeholder": "https://example.com/source.png"
            },
            {
              "fieldLabel": "image_url_8 [optional]",
              "placeholder": "https://example.com/source.png"
            },
            {
              "fieldLabel": "tag [optional]",
              "placeholder": "n8n-nano-banana-2"
            }
          ]
        },
        "formDescription": "Submit a Nano Banana 2 job through Havis AI and poll until it completes."
      },
      "typeVersion": 2.2
    },
    {
      "id": "abc09e54-de2b-0417-9f6c-23e3611f37e1",
      "name": "Build Payload",
      "type": "n8n-nodes-base.code",
      "position": [
        920,
        1120
      ],
      "parameters": {
        "jsCode": "const input = $json;\nconst clean = (value) => value === undefined || value === null ? '' : String(value).trim();\nconst body = {};\nconst apiKey = clean(input.api_key);\nfunction put(name, label, type, required) {\n  const value = clean(input[label]);\n  if (!value && !required) return;\n  if (type === \"number\") { const n = Number(value); if (!Number.isNaN(n)) body[name] = n; return; }\n  if (type === \"boolean\") { body[name] = value === \"true\" || value === \"1\" || value.toLowerCase() === \"yes\"; return; }\n  body[name] = value;\n}\nput(\"prompt\", \"prompt\", \"string\", true);\nput(\"mode\", \"mode [optional]\", \"string\", false);\nput(\"aspect_ratio\", \"aspect_ratio [optional]\", \"string\", false);\nput(\"resolution\", \"resolution [optional]\", \"string\", false);\nput(\"output_format\", \"output_format [optional]\", \"string\", false);\nif (body[\"mode\"] === undefined || body[\"mode\"] === '') body[\"mode\"] = \"text-to-image\";\nif (body[\"aspect_ratio\"] === undefined || body[\"aspect_ratio\"] === '') body[\"aspect_ratio\"] = \"1:1\";\nif (body[\"resolution\"] === undefined || body[\"resolution\"] === '') body[\"resolution\"] = \"1K\";\nif (body[\"output_format\"] === undefined || body[\"output_format\"] === '') body[\"output_format\"] = \"png\";\nconst arr0 = [\"image_url_1 [optional]\",\"image_url_2 [optional]\",\"image_url_3 [optional]\",\"image_url_4 [optional]\",\"image_url_5 [optional]\",\"image_url_6 [optional]\",\"image_url_7 [optional]\",\"image_url_8 [optional]\"].map(label => clean(input[label])).filter(Boolean);\nif (arr0.length) body[\"images\"] = arr0;\nbody.tag = clean(input['tag [optional]']) || \"n8n-nano-banana-2\";\nreturn [{ json: { api_key: apiKey, body } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "c7163876-7390-e820-6b79-af2247f331dd",
      "name": "Submit - Havis API",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1320,
        1120
      ],
      "parameters": {
        "url": "https://havis.ai/api/nano-banana-2",
        "method": "POST",
        "options": {},
        "jsonBody": "={{ $json.body }}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "=Bearer {{ $json.api_key }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "109f31d6-14c6-a287-7d1a-0be6cf63c52b",
      "name": "Wait 8s",
      "type": "n8n-nodes-base.wait",
      "position": [
        1520,
        1120
      ],
      "parameters": {
        "unit": "seconds",
        "amount": 8
      },
      "typeVersion": 1.1
    },
    {
      "id": "fbfaa109-ff8c-941a-018a-c58188385137",
      "name": "Check Task Status",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1720,
        1120
      ],
      "parameters": {
        "url": "={{ 'https://havis.ai/api/task/' + $('Submit - Havis API').first().json.task_id }}",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Build Payload').first().json.api_key }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "f9685fb8-1fbf-6041-5bf2-21e753844160",
      "name": "Is Completed?",
      "type": "n8n-nodes-base.if",
      "position": [
        1920,
        1120
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "d0888e4c-26e4-7dc1-0f26-aba22899a8d6",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.status }}",
              "rightValue": "completed"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "26c9e4d9-c929-cba3-867f-ec4c0fb2948c",
      "name": "Is Failed?",
      "type": "n8n-nodes-base.if",
      "position": [
        2120,
        1240
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "baea6bd6-a5ba-fd80-b43a-76d7eab14209",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.status }}",
              "rightValue": "failed"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "adbb2981-bce0-5673-ab64-b9b56385587e",
      "name": "Wait 8s (loop)",
      "type": "n8n-nodes-base.wait",
      "position": [
        2320,
        1360
      ],
      "parameters": {
        "unit": "seconds",
        "amount": 8
      },
      "typeVersion": 1.1
    },
    {
      "id": "af2cd67c-68c0-94b6-4e0f-aeb192ddd828",
      "name": "Return Result",
      "type": "n8n-nodes-base.set",
      "position": [
        2320,
        1040
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "485df9e9-95d1-232c-630d-c46fa9f97fd7",
              "name": "task_id",
              "type": "string",
              "value": "={{ $('Submit - Havis API').first().json.task_id }}"
            },
            {
              "id": "57c7501a-202a-6b9c-93e7-0b2da467e658",
              "name": "status",
              "type": "string",
              "value": "={{ $json.status }}"
            },
            {
              "id": "2a661a89-2a0f-cea2-a223-63df9e6c98f3",
              "name": "model",
              "type": "string",
              "value": "={{ $json.model }}"
            },
            {
              "id": "bbda75ad-2ffc-02cb-d8a6-657004ebc020",
              "name": "result_urls",
              "type": "string",
              "value": "={{ JSON.stringify($json.result_urls || []) }}"
            },
            {
              "id": "ce80511c-ae21-c2ee-42ae-4bbabc7c3368",
              "name": "credits_used",
              "type": "string",
              "value": "={{ $('Submit - Havis API').first().json.creditsUsed || $('Submit - Havis API').first().json.credits_used || '' }}"
            },
            {
              "id": "36a17aa1-85bc-8de6-7381-0c6d05fbd464",
              "name": "submitted_payload",
              "type": "string",
              "value": "={{ JSON.stringify($('Build Payload').first().json.body) }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "d2c2a832-7d3a-4c57-8638-66ff122f1208",
      "name": "Return Error",
      "type": "n8n-nodes-base.set",
      "position": [
        2320,
        1200
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "b5d90309-f7cc-39dc-c95e-bd46b21a6d0a",
              "name": "task_id",
              "type": "string",
              "value": "={{ $('Submit - Havis API').first().json.task_id }}"
            },
            {
              "id": "1b488e6c-796c-32cf-0163-b4ab2628a69c",
              "name": "status",
              "type": "string",
              "value": "={{ $json.status }}"
            },
            {
              "id": "f04bb68c-1127-9374-71e4-f77ba0614ce6",
              "name": "model",
              "type": "string",
              "value": "={{ $json.model }}"
            },
            {
              "id": "897a1619-d54a-8402-6eed-f03d056de08e",
              "name": "error_message",
              "type": "string",
              "value": "={{ $json.error_message || $json.message || \"Generation failed\" }}"
            },
            {
              "id": "15bcbe63-e19a-e2c0-251a-885db5d89249",
              "name": "credits_used",
              "type": "string",
              "value": "={{ $('Submit - Havis API').first().json.creditsUsed || $('Submit - Havis API').first().json.credits_used || '' }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    }
  ],
  "connections": {
    "Wait 8s": {
      "main": [
        [
          {
            "node": "Check Task Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Failed?": {
      "main": [
        [
          {
            "node": "Return Error",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait 8s (loop)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Payload": {
      "main": [
        [
          {
            "node": "Submit - Havis API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Completed?": {
      "main": [
        [
          {
            "node": "Return Result",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Is Failed?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 8s (loop)": {
      "main": [
        [
          {
            "node": "Check Task Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Task Status": {
      "main": [
        [
          {
            "node": "Is Completed?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Submit - Havis API": {
      "main": [
        [
          {
            "node": "Wait 8s",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Form - Nano Banana 2": {
      "main": [
        [
          {
            "node": "Build Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}