Error with gpt image edit api call

I am trying to use an HTTP request to call on the OpenAI image edit api to generate some images.
I always get the error below after i execute the request:

The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined

n8n version

1.111.0 (Self Hosted)

Stack trace

TypeError: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined at Function.from (node:buffer:325:9) at parametersToKeyValue (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected]_asn1.js@5_afd197edb2c1f848eae21a96a97fab23/node_modules/n8n-nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts:399:28) at prepareRequestBody (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected]_asn1.js@5_afd197edb2c1f848eae21a96a97fab23/node_modules/n8n-nodes-base/nodes/HttpRequest/GenericFunctions.ts:264:25) at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected]_asn1.js@5_afd197edb2c1f848eae21a96a97fab23/node_modules/n8n-nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts:418:53) at WorkflowExecute.executeNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@[email protected]_@[email protected]_08b575bec2313d5d8a4cc75358971443/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1254:31) at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@[email protected]_@[email protected]_08b575bec2313d5d8a4cc75358971443/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1428:22) at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@[email protected]_@[email protected]_08b575bec2313d5d8a4cc75358971443/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1760:38 at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@[email protected]_@[email protected]_08b575bec2313d5d8a4cc75358971443/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:2337:11

Please, can someone assist with a possible solution? I have attached a screenshot of what it looks like

Hey @thejediMunk hope all is well.

From what I see you have an expected binary in the form data, but I do not see any input binaries.

Also, could you share your workflow so we could take a closer look?

It appears that the image field you’re sending is undefined — the error is literally telling you that it tried to use Buffer.from(undefined). You need to pass the actual uploaded file binary into the HTTP Request node.

i removed my API key but here is the workflow i am using

I had a look at your workflow. The main issue is with how the HTTP Request node is picking up the file.

Easiest fix: you don’t really need that Code node at all. Just connect the HTTP Request node directly to your Product Data form node. In the body parameters, set the file field to use the binary key Upload_product_image (that’s the name coming straight from the form). This way the API will get the file as-is and it should work fine.

If you do want to keep the Code node in between, then the code needs a small tweak so it copies/renames the binary properly. Right now it’s dropping the file, which is why the HTTP node sees undefined. Basically, the Code node has to take Upload_product_image and expose it again as image (or whatever field name you want), then the HTTP node can use that key.

So short version:

  • Option A: Skip the Code node, map Upload_product_image directly in the HTTP node.

  • Option B: Fix the Code node so it re-outputs the binary under the right key (image), then use that in the HTTP node.

Try Option A first — it’s simpler and should just work.

Hey @thejediMunk a few things you want to fix in the workflow.

  1. in the form, you have put a period where you had to put a comma

    [fixed below :white_check_mark:]

  2. Trying to reference a binary from a remote node is not something you can currently do, so merging is one way to do it. For that you can use a Merge node and bring that binary to where you need to use it [fixed below :white_check_mark:]

  3. You don’t want to be putting that API key into the field in clear text to begin with. Create a credential with openai and use that in the HTTP Request node.

Go:

  • Authentication: Predefined Credentials
  • Credential Type: OpenAI
  • OpenAI: Create New

and create the credential to use. This way your credential is not going to be exposed and will be stored securely in the database.

Let me know if that worked.

1 Like

Thank you so much. The Merge node solved the issue. I also implemented the API credential idea.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.