{
  "name": "BananaBanana: image via HTTP Request",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "prompt",
              "name": "prompt",
              "value": "A ripe banana on a wooden desk, soft studio light, photorealistic",
              "type": "string"
            },
            {
              "id": "model",
              "name": "model",
              "value": "nano-banana-2-lite",
              "type": "string"
            },
            {
              "id": "aspect",
              "name": "aspect_ratio",
              "value": "1:1",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "name": "Image request",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://bananabanana.pro/api/mcp",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json, text/event-stream"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ jsonrpc: \"2.0\", id: 1, method: \"tools/call\", params: { name: \"generate_image\", arguments: { prompt: $json.prompt, model: $json.model, aspect_ratio: $json.aspect_ratio, idempotency_key: \"n8n-\" + $execution.id } } }) }}"
      },
      "name": "Generate image",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "started?",
              "leftValue": "={{ $json.result.structuredContent.status }}",
              "rightValue": "processing",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "name": "Started?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        660,
        0
      ]
    },
    {
      "parameters": {
        "errorMessage": "={{ $json.result.structuredContent.error_code || $json.result.structuredContent.status }}: {{ $json.result.structuredContent.message }} {{ $json.result.structuredContent.next_step }}"
      },
      "name": "Not started",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        880,
        200
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://bananabanana.pro/api/mcp",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json, text/event-stream"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ jsonrpc: \"2.0\", id: 1, method: \"tools/call\", params: { name: \"get_result\", arguments: { job_id: $('Generate image').item.json.result.structuredContent.job_id, wait_seconds: 30 } } }) }}"
      },
      "name": "Get result",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "still-processing?",
              "leftValue": "={{ $json.result.structuredContent.status }}",
              "rightValue": "processing",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "name": "Still processing?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1100,
        0
      ]
    },
    {
      "parameters": {
        "amount": 5
      },
      "name": "Wait 5 s",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        1320,
        -160
      ],
      "webhookId": "bb-wait-5s"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "completed?",
              "leftValue": "={{ $json.result.structuredContent.status }}",
              "rightValue": "completed",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "name": "Completed?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1320,
        100
      ]
    },
    {
      "parameters": {
        "errorMessage": "={{ $json.result.structuredContent.error_code }}: {{ $json.result.structuredContent.message }} {{ $json.result.structuredContent.next_step }}"
      },
      "name": "Failed",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        1540,
        260
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{ $json.result.structuredContent.files[0].url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "name": "Download file",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1540,
        80
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Image request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Image request": {
      "main": [
        [
          {
            "node": "Generate image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate image": {
      "main": [
        [
          {
            "node": "Started?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Started?": {
      "main": [
        [
          {
            "node": "Get result",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Not started",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get result": {
      "main": [
        [
          {
            "node": "Still processing?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Still processing?": {
      "main": [
        [
          {
            "node": "Wait 5 s",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Completed?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 5 s": {
      "main": [
        [
          {
            "node": "Get result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Completed?": {
      "main": [
        [
          {
            "node": "Download file",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Failed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
