# OpenAI image generation in 5 minutes

**URL:** <https://discourse.nodered.org/t/openai-image-generation-in-5-minutes/70112>\
**Category:** Share Your Projects\
**Created:** [5 November 2022 05:07 UTC](https://discourse.nodered.org/t/openai-image-generation-in-5-minutes/70112 "2022-11-05T05:07:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![VinistoisR](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vinistoisr/32/5778_2.png) [@VinistoisR](https://discourse.nodered.org/u/VinistoisR)\
**Post date:** [5 November 2022 05:07 UTC](https://discourse.nodered.org/t/openai-image-generation-in-5-minutes/70112/1 "2022-11-05T05:07:05Z")

</div>

saw a video about OpenAI image generation and I had to try it out. Naturally node-red made this a 5 minute job.

```auto
[
    {
        "id": "c2883a331c36842f",
        "type": "tab",
        "label": "OpenAI",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "1de2dab24e4aea36",
        "type": "function",
        "z": "c2883a331c36842f",
        "name": "function 1",
        "func": "msg.url = \"https://api.openai.com/v1/images/generations\";\nmsg.method = \"POST\";\nvar prompt = msg.payload;\nvar n = 2;\nvar size = \"512x512\";\n\nmsg.payload = {\n \"prompt\": prompt,\n \"n\": n,\n \"size\": size,\n};\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 740,
        "y": 200,
        "wires": [
            [
                "b5c4b9a30cd04582"
            ]
        ]
    },
    {
        "id": "b5c4b9a30cd04582",
        "type": "http request",
        "z": "c2883a331c36842f",
        "name": "",
        "method": "use",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "bearer",
        "senderr": false,
        "headers": [],
        "x": 950,
        "y": 200,
        "wires": [
            [
                "0a851b5ea2c3db75"
            ]
        ]
    },
    {
        "id": "af927ae24f9e9018",
        "type": "ui_text_input",
        "z": "c2883a331c36842f",
        "name": "Prompt",
        "label": "Enter a Prompt, like \"Paddleboarding with a scarecrow at sunset\"",
        "tooltip": "Enter a prompt!",
        "group": "dcc461615ad026bf",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": true,
        "mode": "text",
        "delay": 300,
        "topic": "",
        "x": 440,
        "y": 120,
        "wires": [
            [
                "b717e2dd116b0935"
            ]
        ]
    },
    {
        "id": "7d109687b80b952a",
        "type": "ui_button",
        "z": "c2883a331c36842f",
        "name": "",
        "group": "dcc461615ad026bf",
        "order": 2,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "submit",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "icon": "",
        "payload": "prompt",
        "payloadType": "flow",
        "topic": "",
        "x": 470,
        "y": 200,
        "wires": [
            [
                "1de2dab24e4aea36"
            ]
        ]
    },
    {
        "id": "b717e2dd116b0935",
        "type": "change",
        "z": "c2883a331c36842f",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "prompt",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 760,
        "y": 120,
        "wires": [
            []
        ]
    },
    {
        "id": "0a851b5ea2c3db75",
        "type": "ui_template",
        "z": "c2883a331c36842f",
        "group": "dcc461615ad026bf",
        "name": "",
        "order": 3,
        "width": 0,
        "height": 0,
        "format": "<div layout=\"row\" layout-align=\"space-between\">\n \n <img src=\"{{msg.payload.data[0].url}}\">\n <img src=\"{{msg.payload.data[1].url}}\">\n\n \n</div>\n\n",
        "storeOutMessages": true,
        "fwdInMessages": true,
        "resendOnRefresh": true,
        "templateScope": "local",
        "x": 1160,
        "y": 200,
        "wires": [
            []
        ]
    },
    {
        "id": "dcc461615ad026bf",
        "type": "ui_group",
        "name": "OpenAI demo",
        "tab": "308f09ba75c30f2f",
        "disp": true,
        "width": "20",
        "collapse": false
    },
    {
        "id": "308f09ba75c30f2f",
        "type": "ui_tab",
        "name": "OpenAI",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/9/f928fd73236b3f0f2b2f1eda68aca36c20ede097.jpeg)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/7/777a02a2480c414a23ba34902eb359d766d1b970.png)

---

<div class="post-metadata">

**Author:** ![yaseralie](https://avatars.discourse-cdn.com/v4/letter/y/0ea827/32.png) [@yaseralie](https://discourse.nodered.org/u/yaseralie)\
**Post date:** [5 January 2023 22:20 UTC](https://discourse.nodered.org/t/openai-image-generation-in-5-minutes/70112/2 "2023-01-05T22:20:12Z")

</div>

Hi,  
Inspired by your json,  
I made video how to run OpenAI in node-red  
Thank you

I tested, it fast to generate the images  
Video:

[![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/c/bcbea5823c8a22a663b8eb8c9545d1b0f10afa75.jpeg "Run OpenAI in Node-RED, text completion and image generation") ](https://www.youtube.com/watch?v=MAeZWsVB5C0)
