How To Connect ChatGPTs New Image Model to n8n [N8N Tutorial]

In this blog post, I’ll walk you through the process of integrating ChatGPT’s Image GPT-1 model with N8N to generate and edit AI images via API—without writing any code manually. You’ll learn how to set up the workflow, generate images, merge multiple images, and optimize costs.


What You’ll Learn

✅ How to set up N8N for ChatGPT Image Generation
✅ Generating AI images using Image GPT-1 API
✅ Reducing costs with custom parameters (size, quality)
✅ Merging two images into one with API & N8N
✅ Converting base64 JSON into viewable images


Step 1: Set Up N8N & OpenAI API Key

  1. Open N8N and create a new workflow.
  2. Get your OpenAI API key from platform.openai.com.
  • Go to API KeysCreate new secret key.
  1. Ensure your OpenAI organization is verified (required for Image GPT-1).

Step 2: Generate an AI Image with HTTP Request

  1. Add an HTTP Request node in N8N.
  2. Import the cURL command from OpenAI’s Image Generation API documentation.
    (Code will be inserted here—check the description for the exact cURL command.)
  3. Replace the API key in the node.
  4. Enter your image prompt in the body parameters.
  5. Test the node—you’ll get a base64 JSON response.

Step 3: Convert Base64 to an Image File

  1. Add a “Convert JSON to Binary Data” node (for base64 decoding).
  2. Link the HTTP Request node’s output to this node.
  3. Test the step—you’ll now see the generated AI image!

Step 4: Reduce Image Generation Costs

Image GPT-1 is more expensive than DALL·E, but you can optimize costs by:

  • Adjusting image size (smaller = cheaper).
  • Setting quality to “low” or “medium” instead of “high”.
  • (Code for parameters will be inserted here.)

Step 5: Merge Two Images into One

  1. Upload two images to Google Drive (or another storage service).
  2. Use Google Drive nodes in N8N to fetch both images.
  3. Add a Merge Node to combine the two images.
  4. Use another HTTP Request node with the Image Edit API cURL command.
    (Code for merging will be inserted here.)
  5. Convert the output from base64 to view the merged image.

Final Workflow & Tips

  • Download the full N8N workflow below.
  • Avoid errors by ensuring OpenAI organization verification.
  • Experiment with different prompts & parameters for better results.

Curl Command

curl --silent --location --request POST "https://api.openai.com/v1/images/edits" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -F model="gpt-image-1" \
  -F 'image[]=@body-lotion.png' \
  -F 'image[]=@bath-bomb.png' \
  -F 'image[]=@incense-kit.png' \
  -F 'image[]=@soap.png' \
  -F 'prompt=Generate a photorealistic image of a gift basket on a white background labeled "Relax & Unwind" with a ribbon and handwriting‑style font, containing all the items in the reference pictures' \
  -F response_format="url"          # or b64_json if you prefer Base64

Code Node

const binaryPropertyName = 'data';
const newBinaryPropertyName = 'data_1';

const binaryData = items[0].binary[binaryPropertyName];

if (!binaryData) {
throw new Error('no data found');
}

// Return the binary data with the new name
return [{ binary: { [newBinaryPropertyName]: binaryData } }];

N8N Complete Workflow

{
  "name": "ChatGPT Image Generation",
  "nodes": [
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -80,
        800
      ],
      "id": "300c8662-6d64-4a70-b654-774d0eb013fb",
      "name": "When clicking ‘Test workflow’"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/images/generations",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer API Key"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "model",
              "value": "gpt-image-1"
            },
            {
              "name": "prompt",
              "value": "A childrens book drawing of a veterinarian using a stethoscope to listen to the heartbeat of a baby otter."
            },
            {
              "name": "size",
              "value": "1024x1024"
            },
            {
              "name": "quality",
              "value": "auto"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        420,
        380
      ],
      "id": "93ad405e-ee8c-43fa-994b-30208832cb63",
      "name": "HTTP Request"
    },
    {
      "parameters": {
        "operation": "toBinary",
        "sourceProperty": "data[0].b64_json",
        "options": {}
      },
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        720,
        380
      ],
      "id": "9cb86578-f08f-47bd-a1e8-5ea1138fa236",
      "name": "Convert to File"
    },
    {
      "parameters": {
        "operation": "download",
        "fileId": {
          "__rl": true,
          "value": "1jKLXDgs918ECcYIfw7hA52w1HaFm2xar",
          "mode": "list",
          "cachedResultName": "gucci-flora-1.webp",
          "cachedResultUrl": "https://drive.google.com/file/d/1jKLXDgs918ECcYIfw7hA52w1HaFm2xar/view?usp=drivesdk"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        280,
        740
      ],
      "id": "990aa7d2-f024-41ec-82bc-7dbbd0abd29a",
      "name": "Google Drive",
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "21UFu9AjTKl1aVlG",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "operation": "download",
        "fileId": {
          "__rl": true,
          "value": "1Hm-0ASFFf-NmjSo-mbUmfIUFFYYP84xW",
          "mode": "list",
          "cachedResultName": "gucci-flora-2.webp",
          "cachedResultUrl": "https://drive.google.com/file/d/1Hm-0ASFFf-NmjSo-mbUmfIUFFYYP84xW/view?usp=drivesdk"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        280,
        940
      ],
      "id": "eb5d987d-5ee4-4944-9a30-5175395f13bb",
      "name": "Google Drive1",
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "21UFu9AjTKl1aVlG",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineByPosition",
        "options": {}
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.1,
      "position": [
        740,
        860
      ],
      "id": "e125fd20-2240-45cb-bb23-9ccbb311204f",
      "name": "Merge"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/images/edits",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer ADD YOUR API KEY"
            }
          ]
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "name": "model",
              "value": "gpt-image-1"
            },
            {
              "name": "prompt",
              "value": "Generate a photorealistic image of a gift basket on a white background labeled \"Relax & Unwind\" with a ribbon and handwriting‑style font, containing all the items in the reference pictures"
            },
            {
              "parameterType": "formBinaryData",
              "name": "image[]",
              "inputDataFieldName": "data"
            },
            {
              "parameterType": "formBinaryData",
              "name": "image[]",
              "inputDataFieldName": "data_1"
            }
          ]
        },
        "options": {
          "redirect": {
            "redirect": {}
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1040,
        860
      ],
      "id": "532e9933-1489-40ec-b1c7-a2e6a35340af",
      "name": "HTTP Request1"
    },
    {
      "parameters": {
        "jsCode": "const binaryPropertyName = 'data';\nconst newBinaryPropertyName = 'data_1'; \n\nconst binaryData = items[0].binary[binaryPropertyName];\n\nif (!binaryData) {\nthrow new Error('no data found');\n}\n\n// Return the binary data with the new name\nreturn [{ binary: { [newBinaryPropertyName]: binaryData } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        500,
        960
      ],
      "id": "53ef87ae-a9a8-4df5-8b53-a1222b2ee7b6",
      "name": "Code"
    },
    {
      "parameters": {
        "operation": "toBinary",
        "sourceProperty": "data[0].b64_json",
        "options": {}
      },
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        1260,
        860
      ],
      "id": "b9f58ece-91af-44bb-9f6e-5438b1881f24",
      "name": "Convert to File1"
    },
    {
      "parameters": {
        "content": "## Generate Images Using GPT-IMAGE-1\n",
        "height": 420,
        "width": 1000
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        220
      ],
      "typeVersion": 1,
      "id": "e2129941-3cf2-4fd7-a763-9d070899597a",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "## Generate Image Using Reference Images with GPT-IMAGE-1\n",
        "height": 480,
        "width": 1800
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -220,
        680
      ],
      "typeVersion": 1,
      "id": "b0231dfb-2a2c-4d9d-84aa-5fbad679ffbf",
      "name": "Sticky Note1"
    }
  ],
  "pinData": {},
  "connections": {
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Google Drive",
            "type": "main",
            "index": 0
          },
          {
            "node": "Google Drive1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Convert to File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive1": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "Convert to File1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "f176413f-89b7-460e-9a31-2cfaf878a805",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "7d6a5bcda733904ebcb54fc0e889f6735550f40f670703e17874c0872e05a9cb"
  },
  "id": "WkDu7vbB2WYiEAvA",
  "tags": []
}

Conclusion

Now you can generate, edit, and merge AI images using ChatGPT Image GPT-1 and N8N—all without writing complex code!

5/5 - (5 votes)

About

Leave a Comment

Your email address will not be published. Required fields are marked *