{
  "name": "Havis AI - Seedream 5 Lite",
  "nodes": [
    {
      "id": "3fa192a7-1e04-4c1a-bff0-8da649e21b84",
      "name": "Sticky Note - Workflow Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -144,
        896
      ],
      "parameters": {
        "width": 512,
        "height": 848,
        "content": "## Havis AI - Seedream 5 Lite\n\n### How it works\n\n1. The workflow shows a public n8n form for collecting a Seedream 5 Lite 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/seedream-5` 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 Seedream 5 Lite inputs: prompt, mode, aspect_ratio, quality, image_url_1, image_url_2.\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": "aef5e6fd-4571-4c5c-8165-6d1bfcd9b0b8",
      "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 Seedream 5 Lite inputs from the user.\n\nKey fields: prompt, mode, aspect_ratio, quality, image_url_1, image_url_2, image_url_3, image_url_4, ...."
      },
      "typeVersion": 1
    },
    {
      "id": "4d90e112-60e9-41a5-a6c6-1124d06d8829",
      "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": "9333d640-8878-4dff-9cc9-8c0d468fc18c",
      "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": "40437b68-455a-4f07-a1a3-5d81b828904f",
      "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": "b29b9ddf-77a5-8314-0f04-a2beac537842",
      "name": "Form - Seedream 5 Lite",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        520,
        1120
      ],
      "parameters": {
        "options": {},
        "formTitle": "Havis AI - Seedream 5 Lite",
        "formFields": {
          "values": [
            {
              "fieldLabel": "api_key",
              "placeholder": "YOUR_HAVIS_API_KEY",
              "requiredField": true
            },
            {
              "fieldType": "textarea",
              "fieldLabel": "prompt",
              "placeholder": "Ethereal landscape with floating islands",
              "requiredField": true
            },
            {
              "fieldType": "dropdown",
              "fieldLabel": "mode [optional]",
              "fieldOptions": {
                "values": [
                  {
                    "option": "text-to-image"
                  },
                  {
                    "option": "image-to-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": "quality [optional]",
              "fieldOptions": {
                "values": [
                  {
                    "option": "basic"
                  },
                  {
                    "option": "high"
                  }
                ]
              }
            },
            {
              "fieldLabel": "image_url_1 [optional]",
              "placeholder": "https://example.com/reference.jpg"
            },
            {
              "fieldLabel": "image_url_2 [optional]",
              "placeholder": "https://example.com/reference.jpg"
            },
            {
              "fieldLabel": "image_url_3 [optional]",
              "placeholder": "https://example.com/reference.jpg"
            },
            {
              "fieldLabel": "image_url_4 [optional]",
              "placeholder": "https://example.com/reference.jpg"
            },
            {
              "fieldLabel": "image_url_5 [optional]",
              "placeholder": "https://example.com/reference.jpg"
            },
            {
              "fieldLabel": "image_url_6 [optional]",
              "placeholder": "https://example.com/reference.jpg"
            },
            {
              "fieldLabel": "image_url_7 [optional]",
              "placeholder": "https://example.com/reference.jpg"
            },
            {
              "fieldLabel": "image_url_8 [optional]",
              "placeholder": "https://example.com/reference.jpg"
            },
            {
              "fieldLabel": "image_url_9 [optional]",
              "placeholder": "https://example.com/reference.jpg"
            },
            {
              "fieldLabel": "image_url_10 [optional]",
              "placeholder": "https://example.com/reference.jpg"
            },
            {
              "fieldLabel": "image_url_11 [optional]",
              "placeholder": "https://example.com/reference.jpg"
            },
            {
              "fieldLabel": "image_url_12 [optional]",
              "placeholder": "https://example.com/reference.jpg"
            },
            {
              "fieldLabel": "image_url_13 [optional]",
              "placeholder": "https://example.com/reference.jpg"
            },
            {
              "fieldLabel": "image_url_14 [optional]",
              "placeholder": "https://example.com/reference.jpg"
            },
            {
              "fieldLabel": "tag [optional]",
              "placeholder": "n8n-seedream-5"
            }
          ]
        },
        "formDescription": "Submit a Seedream 5 Lite job through Havis AI and poll until it completes."
      },
      "typeVersion": 2.2
    },
    {
      "id": "a61e2727-5afd-eeba-7c3a-9ebae1f6cc48",
      "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(\"quality\", \"quality [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\"] = \"16:9\";\nif (body[\"quality\"] === undefined || body[\"quality\"] === '') body[\"quality\"] = \"basic\";\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]\",\"image_url_9 [optional]\",\"image_url_10 [optional]\",\"image_url_11 [optional]\",\"image_url_12 [optional]\",\"image_url_13 [optional]\",\"image_url_14 [optional]\"].map(label => clean(input[label])).filter(Boolean);\nif (arr0.length) body[\"images\"] = arr0;\nbody.tag = clean(input['tag [optional]']) || \"n8n-seedream-5\";\nreturn [{ json: { api_key: apiKey, body } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "6367ac0b-9d1a-d606-9e40-41d00d886669",
      "name": "Submit - Havis API",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1320,
        1120
      ],
      "parameters": {
        "url": "https://havis.ai/api/seedream-5",
        "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": "5aab1c7d-db2c-aaf7-e383-ae1e0b3bafb4",
      "name": "Wait 8s",
      "type": "n8n-nodes-base.wait",
      "position": [
        1520,
        1120
      ],
      "parameters": {
        "unit": "seconds",
        "amount": 8
      },
      "typeVersion": 1.1
    },
    {
      "id": "a0088d72-8857-7f4d-04dc-44bcf61ca6df",
      "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": "2a4f53c4-520f-a33f-fcd3-9a27e993974b",
      "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": "824845cc-0120-6cd2-f9ae-a4eab6b40fd2",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.status }}",
              "rightValue": "completed"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "8b476a5f-0455-980b-58c5-0a1f33425f66",
      "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": "683dcdd2-2c30-ff39-a4f6-94bbde75448d",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.status }}",
              "rightValue": "failed"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "e1352074-ecb8-a73a-bbbf-f1b9e98b5a16",
      "name": "Wait 8s (loop)",
      "type": "n8n-nodes-base.wait",
      "position": [
        2320,
        1360
      ],
      "parameters": {
        "unit": "seconds",
        "amount": 8
      },
      "typeVersion": 1.1
    },
    {
      "id": "1262f676-603e-801a-8527-51851a4b864b",
      "name": "Return Result",
      "type": "n8n-nodes-base.set",
      "position": [
        2320,
        1040
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "0a5ede94-538d-df32-599d-94730d6d68dc",
              "name": "task_id",
              "type": "string",
              "value": "={{ $('Submit - Havis API').first().json.task_id }}"
            },
            {
              "id": "7a2481f8-dda9-d1bf-3e8b-3d11cc9de357",
              "name": "status",
              "type": "string",
              "value": "={{ $json.status }}"
            },
            {
              "id": "184565c5-8c64-b684-2a7c-1de35b4d61a9",
              "name": "model",
              "type": "string",
              "value": "={{ $json.model }}"
            },
            {
              "id": "2ce37855-2c2d-93eb-2287-62ea727571ca",
              "name": "result_urls",
              "type": "string",
              "value": "={{ JSON.stringify($json.result_urls || []) }}"
            },
            {
              "id": "c923e201-ccff-85f9-aa89-6c660773bcbc",
              "name": "credits_used",
              "type": "string",
              "value": "={{ $('Submit - Havis API').first().json.creditsUsed || $('Submit - Havis API').first().json.credits_used || '' }}"
            },
            {
              "id": "bfa407b8-d4b6-0259-8e14-6d31934b9c17",
              "name": "submitted_payload",
              "type": "string",
              "value": "={{ JSON.stringify($('Build Payload').first().json.body) }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "98c6d21f-0dc1-81a1-ec27-501c25c93c93",
      "name": "Return Error",
      "type": "n8n-nodes-base.set",
      "position": [
        2320,
        1200
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "d2dd91ed-f704-9066-0281-92c9a5ec0892",
              "name": "task_id",
              "type": "string",
              "value": "={{ $('Submit - Havis API').first().json.task_id }}"
            },
            {
              "id": "5ba62eb4-cb1b-2f28-fdb5-d0555e9bc43f",
              "name": "status",
              "type": "string",
              "value": "={{ $json.status }}"
            },
            {
              "id": "e1f77651-370e-7c7a-6e4a-537bee7a5903",
              "name": "model",
              "type": "string",
              "value": "={{ $json.model }}"
            },
            {
              "id": "0e17e300-92f7-d74b-c4cc-dc95d3f3a86b",
              "name": "error_message",
              "type": "string",
              "value": "={{ $json.error_message || $json.message || \"Generation failed\" }}"
            },
            {
              "id": "43479dc3-92fb-6466-2dc0-703ad34586fc",
              "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 - Seedream 5 Lite": {
      "main": [
        [
          {
            "node": "Build Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}