Describe the problem/error/question
Every time an Agent makes a LLM query that last more than 4 minutes (exactly) it crashes with this error message:
Problem in node ‘AI Agent1‘
Gateway timed out - perhaps try again later?
I know a similar problem was supposed to be solved. But I am running version 2.5.0 and still have the problem.
What is the error message (if any)?
Here is the error log:
{
“errorMessage”: “Gateway timed out - perhaps try again later?”,
“errorDescription”: “504 stream timeout”,
“errorDetails”: {
“rawErrorMessage”: [
“504 stream timeout”
]
},
“n8nDetails”: {
“nodeName”: “AI Agent1”,
“nodeType”: “@n8n/n8n-nodes-langchain.agent”,
“nodeVersion”: 3.1,
“time”: “1/26/2026, 2:32:50 PM”,
“n8nVersion”: “2.5.0 (Self Hosted)”,
“binaryDataMode”: “filesystem”,
“stackTrace”: [
“NodeOperationError: Gateway timed out - perhaps try again later?”,
" at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+n8n-nodes-langchain@file+packages+@n8n+nodes-langchain_5e964642f84eebe7ab5946b9e3444692/node_modules/@n8n/n8n-nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/executeBatch.ts:95:11",
" at Array.forEach ()“,
" at executeBatch (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+n8n-nodes-langchain@file+packages+@n8n+nodes-langchain_5e964642f84eebe7ab5946b9e3444692/node_modules/@n8n/n8n-nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/executeBatch.ts:84:15)”,
" at processTicksAndRejections (node:internal/process/task_queues:105:5)“,
" at ExecuteContext.toolsAgentExecute (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+n8n-nodes-langchain@file+packages+@n8n+nodes-langchain_5e964642f84eebe7ab5946b9e3444692/node_modules/@n8n/n8n-nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/V3/execute.ts:46:66)”,
" at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+n8n-nodes-langchain@file+packages+@n8n+nodes-langchain_5e964642f84eebe7ab5946b9e3444692/node_modules/@n8n/n8n-nodes-langchain/nodes/agents/Agent/V3/AgentV3.node.ts:139:10)“,
" at WorkflowExecute.executeNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@[email protected]_@[email protected]_ec37920eb95917b28efaa783206b20f3/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1046:8)”,
" at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@[email protected]_@[email protected]_ec37920eb95917b28efaa783206b20f3/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1227:11)“,
" at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@[email protected]_@[email protected]_ec37920eb95917b28efaa783206b20f3/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1659:27”,
" at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@[email protected]_@[email protected]_ec37920eb95917b28efaa783206b20f3/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:2301:11"
]
}
}
Please share your workflow
Any AI Agent that call my LLM with a prompt and an output big enough to last more than 4 minutes leads to the problem. The endpoint I call is LiteLLM. However when walling it from my machine with basic python code I do not have any timeout issue.
Information on your n8n setup
- n8n version: 2.5.0
- Database (default: SQLite):
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- Running n8n via (Docker, npm, n8n cloud, desktop app): local docker
- Operating system: WSL/Windows
1 Like
Hi @Julien_Carme ,
Welcome to the community,
This is actually a known issue, can you try increasing your n8n’s execution timeout settings and see if the issue persist?
Add these environment variables to your n8n configuration:
EXECUTIONS_TIMEOUT=900
EXECUTIONS_TIMEOUT_MAX=900
N8N_GRACEFUL_SHUTDOWN_TIMEOUT=900
This extends the timeout to 15 minutes (900 seconds)
depending on your setup:
Docker Compose:
environment:
- EXECUTIONS_TIMEOUT=900
- EXECUTIONS_TIMEOUT_MAX=900
- N8N_GRACEFUL_SHUTDOWN_TIMEOUT=900
Docker Run:
docker run -e EXECUTIONS_TIMEOUT=900 -e EXECUTIONS_TIMEOUT_MAX=900 ...
npm/direct installation:
Add to your .env file or export before starting n8n.
Let me know if the issues still persist!
Hey @Julien_Carme Welcome to the n8n community!
This is not a LiteLLM issue.
What you are hitting is a hard timeout in n8n’s AI Agent execution, and it happens at 4 minutes because of a stream / proxy timeout in the LangChain agent path (504 stream timeout).
Key points:
-
AI Agent nodes in n8n still run as blocking executions
-
If the LLM call does not stream tokens and takes too long, n8n kills it
-
Version 2.5.0 improved stability, but long-running agent calls are still not supported
-
Python works because it bypasses n8n’s execution + proxy timeouts
What helps in practice:
-
Enable streaming responses in LiteLLM (best fix)
-
Split the prompt into smaller steps instead of one long call
-
Increase reverse-proxy / Docker timeouts (Nginx, Traefik, etc.), if you have one
-
For very long jobs, run the agent outside n8n and call it via HTTP
So this is a known limitation rather than a bug in your setup.
Add these environment variables to your n8n configuration:
EXECUTIONS_TIMEOUT=900
EXECUTIONS_TIMEOUT_MAX=900
N8N_GRACEFUL_SHUTDOWN_TIMEOUT=900
Thanks for your answer, but no it makes no change at all. Still timeout after exactly 4 minutes.
Enable streaming responses in LiteLLM (best fix)
Thanks for your answer
I tried and it did not work. However I am not entirely sure whether I correctly setup streaming in LiteLLM or not, I will continue to investigate.
1 Like
Indeed let me know if you have specific question about that. I would say most of the LLMs dont take more than 1 minute to reply for text inputs and it can differ but, if you are looking to extend that 4 min time frame i want to ask what data are you going to process with it. So that if you can share your workflow maybe we can solve this out with different approach. Hope this helps
I would say most of the LLMs dont take more than 1 minute to reply for text inputs
Claude Sonnet has an output window of 64000 tokens, if you ask it to generate a document that big it takes way more than 4 minutes. At least with the instance I use which is on GCP.
As I integrate this generation in a larger workflow, with several such calls, I never know if and when the timeout will be reached and the workflow will fail.
I am sorry I can’t share the workflow but it would not help anyway. To reproduce the problem you can simply create a prompt that generates enough tokens and that’s it.
@Julien_Carme
You are running into a hard 4-minute stream timeout in n8n’s AI Agent execution path. This is not controlled by EXECUTIONS_TIMEOUT and is why changing those env vars has no effect.
Even with streaming enabled, very large generations (tens of thousands of tokens) can exceed the proxy or LangChain agent stream timeout, especially when running inside n8n. This is a known limitation of the AI Agent node today.
What actually works:
-
Chunk the generation: split the document into sections and generate them across multiple shorter LLM calls.
-
Move long generations outside n8n: run the LLM job as a separate service (Python, Cloud Run, etc.) and call it via HTTP from n8n.
-
Avoid single huge outputs inside AI Agent nodes. They are not designed for long blocking executions.
So yes, your reproduction is valid, but currently n8n cannot reliably handle very long single-call LLM generations, regardless of model or infra. The workaround is architectural, not configuration-based. I guess we are now facing an exception of langchain.
OK thank you for your support.
Glad it helped, if you can mark it as a solution to let others know what is true. Thanks