Setup connection to Google Imagen 4

Quick test:

curl “https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent
-H ‘Content-Type: application/json’
-H ‘X-goog-api-key: GEMINI_API_KEY’
-X POST
-d ‘{
“contents”: [
{
“parts”: [
{
“text”: “Explain how AI works in a few words”
}
]
}
]
}’

Hey @chrismol hope all is good.

Copy this request, go to the http request node and in the top right corner hit the import curl button. Then paste the curl and click Import.

You should end up with something like this:

@jabbson That is great, thank you for the fast help! Super easy once I get how the UI works!

Now, how would I break up the raw JSON in the Body into separate fields so I could use a long prompt for creating images? It has double/single quotes, commas, periods, etc.

you don’t need to break it down, really, you can just work with this JSON. If you need a longer propmt which is defined before the Http Request node, you can inject it with an expression - that {{ $json.bla bla bal}} thing.

@jabbson Ok but I’m getting an error with the prompt formatting. Can I put the prompt into it’s own field for easier formatting?

You can add a set node in front of the HTTP Request node and set the prompt there, then reference it in the JSON structure as {{ $json.prompt }} or whatever you will call it in the set node.

And looking at your JSON - of course it’s not valid - it has new lines. Which brings us to the next thing - even if you prepend the HTTP with SET, you will still have new lines in the JSON, so what you probably want to do is when you reference in the JSON, do it like this:
{{ $json.prompt.toJsonString() }}

so that it is pre-formatted to be a valid json string.

@jabbson Can I share the flow with you? Would you stub it out for me?

If you have questions or something isn’t working, sure thing - do share.

Ok another dumb question… how do I share with you? Should your username be searchable? Some other name or id I need to know?

You can share it here like this. Or you can save it in pastebin or google doc and share the link with me privately.

just add your key to the header

Thanks but it’ still messy with the long prompt. Is there any way to isolate the “text” parameter into a form field in the n8n workflow steps? Then i can simply paste or import a long prompt that has formatting in it and the code will handle it without errors.

I am sorry, I don’t understand the question