Analysis image from openrouter google/gemini-2.5-flash

I am having an issue. When I upload an image file via telegram and want to send it to Openrouter’s google/gemini-2.5-flash model for analysis. It seems the “Telegram get file” node functions correctly, as I use “Edit field” to remove extra hidden ‘/n’. Also “Edit node” works fine.

However, when I use this value (which is from Edit node) as an input to “Http node”, it directly connects to “Openrouter”. I have also set the Send body as a JSON. The model constantly gives me an error (Bad request).

Here is the JSON data I used.

{
“model”: “google/gemini-2.5-flash”,
“messages”: [
{
“role”: “user”,
“content”: [
{
“type”: “text”,
“text”: “Please analyze this JPG image in detail, pointing out the construction progress and potential safety hazards.”
},
{
“type”: “image_url”,
“image_url”: {
“url”: “data:image/jpeg;base64,{{ $json.base64String }}”
}
}
]
}
]
}

Information on your n8n setup

  • n8n version: n8n Version 2.2.6

  • Operating system: On 3rd party cloud

Hey @logidy Looking at the OpenRouter Image Inputs docs, your payload should look like:

{
  "model": "google/gemini-2.5-flash",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "what's in this image"
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "data:{{ $('Get a file').item.binary.data.mimeType }};base64,{{$json.data}}"
          }
        }
      ]
    }
  ]
}

For your information $binary.data.data will not work,
Also, code nodes are unnecessarily complex for this,

The solution is actually simpler: just use the Extract from File node to get the base64 string and include it in the request body,

here is fully working example: