Error in batch image generation api using gemini-2.5-flash

I am trying to do a batch image generation using the Gemini 2.5 flash image (nano banana), and I keep getting errors for the request:

{'error': {'code': 3, 'message': 'Request contains an invalid argument.'}, 'key': *"Modified by Moderator"*

The batch api accepts the data that I send, it shows me that the generation has succeeded, but it then throws this error given above.

The format that I’m using to send the image references in the prompt is:

{
  "key": ".....",
  "request": {
    "contents": [
      {
        "parts": [
          {
            "text": "Generate an image of this pet sitting still in front of the camera. With the head and shoulders of the pet within the frame. The pet should look happy with a party hat on its head. Keep the background colour a uniform colour with colour code #00B140. Only keep the head and the shoulder of the pet in the image. Make sure that the pet fills in the frame as much as possible"
          },
          {
            "file_data": {
              "file_uri": "files/t85xlkojz2x4",
              "mime_type": "image/png"
            }
          }
        ]
      }
    ]
  }
}

I cannot find the official documentation on Google for passing images in the prompt for batch endpoints.

I’m using Python 3.10 on Linux.

Hey! Just flagged this to our Batch API team, hang tight!

Hi ahar,

Thanks for reporting this issue. The format you are using to send images is not correct. Please try to use a fully qualified URI instead of the file ID.

For example, replace:

files/t85xlkojz2x4

for

https://generativelanguage.googleapis.com/files/t85xlkojz2x4

in the request you shared.

We are improving the error message to make this issue easier to debug.

1 Like