Issue with AI Agent + Google Vertex Chat Model

Describe the problem/error/question

My current workflow keeps on getting Errors when inferencing to Google Vertex Chat Model node due to a Bad Request. As far as I can see, the prompt is validly written so it should be working. The model I am trying to use is ‘gemini-3.1-flash-lite’.

What is the error message (if any)?

"Bad request - please check your parameters

Google request failed with status code 400"

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

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

Thanks for letting us know about this, We have created CV-11 as the internal dev ticket to look into it.

Hi @Irrazional Welcome!
On Vertex, gemini-3.1-flash-lite is only served on the global region endpoint, so a credential pinned to a specific location (any us- or europe- region) returns this 400. The 2.5 models still run on regional endpoints, but the 3.x models moved to global-only. Open your Google Service Account credential, set Region to global, and if global isn’t in the dropdown, toggle Expression (fx) on that field and type global manually, then re-run.
See this:

n8n 2.29.0 shipped node-side handling for this too, so updating from 2.27.3 helps alongside the region change.
Separately, this is a text chat model, so it returns text, not images. To generate the images your prompt describes, use an image model like Gemini 3.1 Flash Image (Nano Banana) through the HTTP Request node, not the AI Agent.

Ah thanks a lot, the error is resolved! But what you mentioned is true, I can’t generate images yet with this workflow. Do you perhaps know a step-by-step guide that can help me set up that part of the flow?

Thanks a lot!

Hi @Irrazional
The built-in Google Gemini node has a “Generate an Image” operation for exactly this, no HTTP wiring needed. Steps:

  1. Add a Google Gemini node.
  2. Create a “Google Gemini (PaLM) API” credential with an API key from Google AI Studio (aistudio.google.com), then select it in the node.
  3. Set Resource to “Image” and Operation to “Generate an Image”.
  4. Put your prompt text in the “Prompt” field (the same text you had on the AI Agent).
  5. It returns the image as binary, so connect it straight into your existing Google Drive upload node.
    This replaces the AI Agent and Vertex Chat Model pair for the image step.
    See this:

Oh sorry, I forgot to clarify on my part. I am trying to resolve this through Vertex AI due to Gemini not supporting the use of the free 300$ GCP credit any more. The billing support at Google helped me configure it through Vertex AI instead of AI studio, as they said that it is possible to use those credits. Is there a way for me to configure the connection to the 3.1 flash image lite model through Vertex?

We have taken a look at this issue and are unable to confirm that this is a bug, For now we have closed the internal ticket but if it starts to look like it is a bug our moderation team will flag this again.

Hi @Irrazional
The Vertex Chat Model node can’t do this, it’s a text-only LangChain sub-node, and n8n has no built-in Vertex image node, so on Vertex the image model has to be called with the HTTP Request node using your existing Service Account credential. That keeps everything on GCP billing, so your $300 credit still applies. One correction on the model: the image model is gemini-3.1-flash-image-preview (Nano Banana), there’s no flash-image-lite, the -lite tiers are text only. Confirm the exact ID in Model Garden for your project.
Setup:

  1. Open your Google Service Account credential, turn on “Set up for use in HTTP Request node”, add the scope https://www.googleapis.com/auth/cloud-platform, and save.
  2. Add an HTTP Request node, method POST, Authentication set to Predefined Credential Type > Google Service Account API, and select that same credential.
  3. URL (global endpoint, since the 3.x models are global-only, same reason as your earlier region fix):
https://aiplatform.googleapis.com/v1/projects/gen-lang-client-0799028555/locations/global/publishers/google/models/gemini-3.1-flash-image-preview:generateContent
  1. Turn Send Body on, Body Content Type JSON. Put the whole body in expression mode (start the field with =) so the label interpolates, and request an image back with responseModalities:
={
  "contents": [
    { "role": "user", "parts": [ { "text": "A professional, high-resolution photo of {{ $json.Labels.split(',')[0] }}" } ] }
  ],
  "generationConfig": { "responseModalities": ["TEXT", "IMAGE"] }
}
  1. The image comes back as base64 at candidates[0].content.parts[0].inlineData.data. Add a Convert to File node (base64 string to file) to turn it into binary, then feed that into your existing Drive upload node.
    Google Service Account | Nodes | n8n Docs

Hey there!

A 400 Bad Request from the Google Vertex Chat Model usually means the API received your request, but the payload or configuration was malformed. It’s not a network timeout or an authentication block (which would typically throw a 401 or 403).

Looking at the details you provided, here are the most likely culprits and how to fix them:

1. Incorrect Google Cloud Project ID (Most Critical)
Your node is currently using something like gen-lang-client-... as the projectId. This looks like an internal client ID, not a standard Google Cloud Project ID.

  • Go to your Google Cloud Console.
  • Click the project selector dropdown at the top.
  • Copy your actual Project ID (it’s usually a lowercase string with hyphens, like my-gemini-project-12345).
  • Replace the current value in both of your Google Vertex nodes with this correct ID.

2. Missing or Unlinked Credentials
If your workflow JSON shows credentials: {}, the node isn’t explicitly linked to a Google Cloud credential. Relying on default host credentials can sometimes fail.

  • In n8n, go to Credentials and create a new “Google Cloud API” credential.
  • In Google Cloud (IAM & Admin > Service Accounts), create a Service Account with “Vertex AI User” permissions.
  • Generate a JSON key for this account, download it, and paste its contents into your n8n credential.
  • Go back to your workflow and explicitly select this new credential in both Vertex nodes.

3. Enable Vertex AI API
As a quick sanity check, ensure the “Vertex AI API” is actually enabled for your specific project in the Google Cloud Console (APIs & Services > Library).

Once the Project ID is fixed and the Service Account is properly linked, the 400 error should disappear. Let me know if that works for you!

I was experiencing same issues tnx