N8n AI Agent + Gemini OpenAI-compatible API: 400 Bad Request when executing Gmail tools

n8n AI Agent returns 400 Bad Request when using Gmail tools with Gemini through OpenAI-compatible API

I’m using n8n 2.47.5 (self-hosted) with an AI Agent connected to an OpenAI Chat Model node configured to use Google’s Gemini OpenAI-compatible API.

My configuration:

  • Base URL: https://generativelanguage.googleapis.com/v1beta/openai/

  • Model: gemini-3.5-flash-lite

  • Use Responses API: OFF

  • Gemini API key configured in n8n.

The issue:

The model works correctly for normal text conversations through my webhook. I also tested the Gemini API directly using PowerShell, and gemini-3.5-flash-lite returned a successful response.

However, when I connect Gmail tools to the AI Agent, it fails with 400 Bad Request (no body). This happens when I ask the agent to retrieve my latest email, even without requesting any email to be sent or drafted.

I also configured a Gmail Human-in-the-Loop approval tool connected to a Gmail Send tool. Interestingly, when I ask the agent to prepare an email, I receive the approval notification, and after clicking Approve, the email is successfully sent. However, immediately afterward, the AI Agent fails with the same 400 error instead of returning a final response.

The execution shows both the OpenAI Chat Model and AI Agent nodes in red. The model output before the failure sometimes shows:

finish_reason: "tool_calls"

The error details include:

400 status code (no body)

The stack trace points to:

@n8n/n8n-nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/executeBatch.ts

My questions:

  1. Is Gemini’s OpenAI-compatible API fully compatible with n8n’s AI Agent tool-calling implementation?

  2. Is there a known issue with Gemini function/tool calling, especially when the agent makes a second model request after executing a tool?

  3. Is there a recommended configuration or workaround that allows Gemini to work reliably with Gmail tools and Human-in-the-Loop approval?

I would prefer to continue using Gemini rather than switch to a paid OpenAI API.

Any help or suggestions would be appreciated.

The 400 error you see right after the tool call is most likely because of a thought signature.

Gemini 3 and newer models return a thought signature on the first function call of each step.
According to the Gemini docs, when you use tools you have to return this thought signature as part of history in your next request, otherwise the request fails with a 400 error.

This is why plain chat with gemini works fine and then fails exactly on the second request after a tool call (with finish_reason: tool_calls), because it doesn’t send the thought signature in the next request.

If you are using an OpenAI-compatible endpoint, the signature is sent as part of tool_calls[].extra_content.google.thought_signature.

The n8n OpenAI Chat Model node uses LangChain’s ChatOpenAI implementation. I could not find any implementation of handling extra_content in the relevant parts of the langchainjs code, so this information is dropped when the agent sends history to the model.

You can use the n8n Google Gemini Chat Model node instead. The agent implementation in n8n for Gemini models does include logic to carry signatures from the model’s response back into history. A Gemini API key from AI Studio should work in its credential, so you don’t need an OpenAI key.