Changing background of product picture to create an ad

Describe the problem/error/question

Use case: I have product pictures (png) in google drive. I set a nod to convert these into base64 before passing them to an AI model to change the background (eg I have picture of sofa and I want to add it to a living room)
Pb: I tried to call with HTTP node the brand new Gemini API, I am based in the US (no geo restrictution) but can’t make it work (end point: https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp-image-generation:generateContent?key=APIKEY).

I keep on getting this message: "“models/gemini-2.0-flash-exp-image-generation is not found for API version v1beta, or is not supported for generateContent” while Google API doc says this model exists: Gemini models  |  Gemini API  |  Google AI for Developers

I tried Open AI but only manage to make image from scratch, not leveraging my product picture

I am surely missing something but can’t find how to make it work via API calls (on both Open AI UI and Gemini UI I managed to get what I want but not via n8n)

Thanks a lot for any pointer, I spent 3 days on this and exhausted all I could think of

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hello @Anthony_Roger

Assuming there is no geo-restriction as explained here:

The endpoint you’re mentioning looks good to me and is working on my side.

So, I suggest you double-check the JSON body that you included in the request…

Thanks this really helps knowing that this endpoint actually works. I will triple check my JSON script today and revert. Thanks again for the reco

So I tried several JSON script (including some generated by Gemini) but no luck at calling this API and generating an image. My set up> Google Drive, download a file then a convert to base64 node, then a HTTP node. The first 2 nodes work, the HTTP one doesn’t. If the endpoint works, it seems my JSON doesn’t. Is there any resource of a JSON call for this API I can refer to? I checked the template but this model isn’t there yet

Hi @Anthony_Roger

This is a very basic example of how to call Gemini to generate an image via the HTTPS node:


You can find more details here:

Feel free to edit it as needed, and let me know if you need any assistance.

Are you hard set on using Gemini? Ive done something similar for a side project where I replaced the background of a car using Stability AI. My process was:

  1. Take input image and strip background (Maybe your products already have no background)
  2. Use the structure API to generate a new image using the same structure of the car with a different background
  3. Use n8n Edit Image node to stick the Masked car onto the new image generated.
  4. Push the new image to a cdn for use in my app

Heres the results:



NB: Slightly different images, as I cant find my old execution, but to give an idea of the process

1 Like

Nice car!! Thanks a million for the examples, will test this out now. I wanted to use Gemini as I had some API credit but will switch allegiances if I can’t make it work

I will go the Stability AI or even Chatgpt road. I tried the exact worlfow with Gemini (copy pasted it) and still got the same error message so not sure what is wrong with my Gemini API account. Anyway thanks a mill for the solutions.

Sometimes it’s worth using the right tool for the job. There are off course many options out there. I have yet to properly play with the new GPT image gen.

1 Like

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