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

Good day @logidy

I think the issue is that you are probably sending the Telegram file_id, not the real image content. OpenRouter cannot read the image from that value, the image_url.url field must contain either a public image URL or a real base64 data URL.

As a workaround, I would do one of these two options.

Option 1, use a public image URL if you can make the image accessible somewhere.

Option 2, use the binary data downloaded by the Telegram Get File node and send that as base64.

In n8n, after Telegram Get File, check the Binary tab. If the binary property is called data, you can usually reference the real base64 content with something like:

{{ $binary.data.data }}

Then your JSON should be closer to this:

{
“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,{{ $binary.data.data }}”
}
}
]
}
]
}

I would also remove any replaceAll() logic from the Telegram file_id, because cleaning the file_id will not convert it into an image. The important part is to use the downloaded binary file content, not the Telegram identifier.

If it still returns Bad Request, I would first test with a small JPG image and set the image MIME type correctly, for example data:image/jpeg;base64, for JPG or data:image/png;base64, for PNG.