Setting AI Automation Timeouts Correctly for Long-Running LLM Calls
By Abhishek Patoliya · 2026-08-16
A timeout value copied from a typical REST API integration — a few seconds, maybe ten — is often simply wrong for an LLM call, where a legitimate response involving extended reasoning or a long completion can genuinely take much longer than a typical CRUD API call ever would. Setting automation timeouts correctly for LLM calls means neither cutting off valid, slow-but-working requests nor leaving a workflow hanging indefinitely on a request that's genuinely stuck — and those two failure modes need different fixes, not one timeout value trying to serve both.
Getting Automation Timeouts Right Requires Two Different Numbers
Treating "the timeout" as a single value to tune misses that a well-behaved LLM integration usually needs two distinct numbers working together: one bounding total time so nothing runs forever, and a separate one detecting a stall specifically, since a slow-but-active call and a genuinely stuck one look identical to a single blunt duration limit but need very different handling.
Why Generic API Timeout Defaults Don't Transfer
A typical REST endpoint returning a database record responds in tens to hundreds of milliseconds; a five-second timeout is generous. An LLM call generating a long, reasoning-heavy response can legitimately take tens of seconds, and a call using extended tool use or multiple reasoning steps can take longer still. Applying a REST-API-appropriate timeout to an LLM call doesn't protect against a stuck request — it just guarantees premature failures on responses that were working correctly and would have completed given a realistic amount of time.
Measuring Real Latency Before Guessing at a Number
Rather than picking a timeout value intuitively, pull actual latency data for the specific task from recent runs — the same observability data covered elsewhere on this blog makes this a direct query rather than a guess. Look at the p95 or p99 latency (not just the average, which a handful of fast trivial cases can pull down misleadingly) and set the timeout with real headroom above that — commonly two to three times the p99 — rather than something tight enough that a normal slow-but-valid response gets cut off.
-- Find real p95/p99 latency for a specific automation task
-- to set a timeout with actual headroom, not a guess
select
percentile_cont(0.95) within group (order by latency_ms) as p95,
percentile_cont(0.99) within group (order by latency_ms) as p99
from automation_logs
where workflow_name = 'invoice-extraction'
and created_at > now() - interval '30 days';
Total Duration Timeout vs Stall Timeout
For streaming responses specifically, a single total-duration timeout is a blunt instrument — a stream that's actively producing tokens, even at a slow but steady pace, is behaving completely differently from one that's gone silent partway through and stopped producing anything at all. A stall timeout — how long since the last token or chunk arrived, reset on every new token — catches a genuinely stuck stream much faster than waiting for an overall duration limit, while still allowing a slow-but-actively-working stream to run to completion without being cut off prematurely.
// Conceptual pattern for a streaming call — both limits active simultaneously
const STALL_TIMEOUT_MS = 15_000; // no new token in 15s -> abort
const TOTAL_TIMEOUT_MS = 120_000; // hard cap regardless of activity
let lastTokenAt = Date.now();
// on each received token/chunk: lastTokenAt = Date.now();
// separately check: Date.now() - lastTokenAt > STALL_TIMEOUT_MS -> abort
// and: Date.now() - startedAt > TOTAL_TIMEOUT_MS -> abort
What Happens After a Timeout Fires
A timeout without a defined next step just converts one problem (a slow call) into another (an unhandled error). Decide explicitly what happens when a timeout fires: retry once with backoff if the failure looks transient, fall back to a different provider using the pattern covered elsewhere on this blog if the timeout suggests a genuine outage rather than one slow call, or surface the failure clearly for human follow-up if neither applies. Treat a timeout as a specific, expected failure mode with its own handling — not a generic error the workflow happens to throw and stop on without a plan.
Timeouts in Queue-Mode or Concurrency-Limited Setups
In an n8n instance running queue mode or with limited execution concurrency, a stuck call holding a worker slot for an unnecessarily long timeout has a cost beyond just that one workflow — it reduces capacity available for everything else waiting to execute. This is a concrete reason to keep timeouts tight relative to actual measured latency rather than generously long "just in case": a timeout that's too loose doesn't just delay detecting one problem, it can compound into a broader capacity problem across the whole instance when several long-running executions stack up simultaneously.
Revisiting Timeout Values as the Task or Model Changes
A timeout tuned correctly for one model version or one task shape can become wrong after a model upgrade changes typical response latency, or after the task itself grows more complex (longer documents, more reasoning steps). Re-measure and adjust timeouts as part of the same periodic review used for other automation health checks, rather than setting them once at launch and assuming they stay correct indefinitely as the underlying task and model both continue to change.
Timeouts and User-Facing Latency Expectations
For an automation with a human waiting on the other end — even indirectly, like a support agent expecting an AI-drafted reply within a few seconds — the timeout needs to account for what the person on the receiving end can reasonably tolerate, not just what the LLM call itself can technically handle before genuinely failing. A technically valid but slow response that arrives after the person has already given up and moved on isn't actually useful, even though it didn't hit the timeout. Where user-facing latency matters this much, it's worth setting a shorter, UX-driven timeout that falls back to a faster (even if lower-quality) response rather than only bounding for correctness.
Logging Timeout Events Distinctly From Other Failures
Tag timeout failures distinctly in the observability data covered elsewhere on this blog, separate from other error types like malformed responses or authentication failures. A rising timeout rate specifically, tracked as its own metric, is a strong early signal of either a provider-side slowdown or a task that's grown more complex than the current timeout accounts for — a signal that gets lost if timeouts are logged generically alongside every other kind of failure instead of as their own distinct, trackable category.
Coordinating Timeouts With Retry and Fallback Logic
A timeout value doesn't exist in isolation — it interacts directly with whatever retry or fallback logic sits behind it, covered in more depth elsewhere on this blog. A timeout set too aggressively combined with an equally aggressive retry policy can multiply load on a struggling provider exactly when it's least able to handle it, turning one slow period into a self-inflicted pile-up of retried requests. Tune timeout, retry count, and backoff delay together as one coordinated system, not as three independently-chosen values that happen to interact once deployed.
Setting Different Timeouts for Different Task Types on the Same Automation
A single automation often makes more than one kind of LLM call — a quick classification step and a longer content-generation step, for instance — and applying one blanket timeout across both means it's wrong for at least one of them. Set timeouts per call type based on that specific call's actual measured latency, rather than picking one number for the whole automation and accepting that it will be too tight for the slow calls or too loose for the fast ones.
Written by Abhishek Patoliya, Senior n8n Developer & Automation Architect, Surat, India. Verified n8n Creator.