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:
-
Is Gemini’s OpenAI-compatible API fully compatible with n8n’s AI Agent tool-calling implementation?
-
Is there a known issue with Gemini function/tool calling, especially when the agent makes a second model request after executing a tool?
-
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.