{"record":{"id":"07d836926733d769","repo":"n8n-io/n8n","slug":"the-file-filename-is-sizeinmb-mb-which-ex","errorCode":null,"errorMessage":"The file \"${fileName}\" is ${sizeInMb} MB, which exceeds the ${limitInMb} MB limit for passing binary data to the model","messagePattern":"The file \"(.+?)\" is (.+?) MB, which exceeds the (.+?) MB limit for passing binary data to the model","errorType":"exception","errorClass":"NodeOperationError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/common.ts","lineNumber":164,"sourceCode":"\t\tbase64Data = Buffer.from(binaryBuffer).toString(BINARY_ENCODING);\n\t} else {\n\t\tbase64Data = data.data.includes('base64,') ? data.data.split('base64,')[1] : data.data;\n\t}\n\n\t// Guard against oversized attachments. Providers that accept inline (base64)\n\t// documents cap the request payload, so we reject early with a clear message\n\t// instead of surfacing an opaque provider-side error. The limit is\n\t// configurable via N8N_AI_AGENT_MAX_PASSTHROUGH_BINARY_SIZE_BYTES.\n\tconst maxSizeInBytes =\n\t\tContainer.get(AiConfig)?.maxAgentPassthroughBinarySizeBytes ??\n\t\tDEFAULT_MAX_PASSTHROUGH_BINARY_SIZE_BYTES;\n\t// Decode the base64 length exactly (Buffer.byteLength accounts for padding).\n\tconst sizeInBytes = Buffer.byteLength(base64Data, 'base64');\n\tif (sizeInBytes > maxSizeInBytes) {\n\t\tconst fileName = data.fileName ?? 'binary file';\n\t\tconst sizeInMb = (sizeInBytes / (1024 * 1024)).toFixed(1);\n\t\tconst limitInMb = (maxSizeInBytes / (1024 * 1024)).toFixed(1);\n\t\tthrow new NodeOperationError(\n\t\t\tctx.getNode(),\n\t\t\t`The file \"${fileName}\" is ${sizeInMb} MB, which exceeds the ${limitInMb} MB limit for passing binary data to the model`,\n\t\t\t{\n\t\t\t\tdescription:\n\t\t\t\t\t'Reduce the file size, or disable the binary passthrough option for this input.',\n\t\t\t},\n\t\t);\n\t}\n\n\t// PDFs (and other documents) are passed as a file content block. OpenAI's\n\t// Responses API needs its native `input_file` part; every other supported\n\t// provider consumes the LangChain standard data content block.\n\tif (type === 'file') {\n\t\tif (contentFormat === 'openai-responses') {\n\t\t\treturn {\n\t\t\t\ttype: 'input_file',\n\t\t\t\tfile_data: `data:${data.mimeType};base64,${base64Data}`,\n\t\t\t\tfilename: data.fileName ?? 'attachment.pdf',","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/common.ts#L146-L182","documentation":"Thrown by addPassthroughBinary (Tools Agent common.ts) when a binary item being passed through to the model exceeds the configured size cap. The limit defaults to DEFAULT_MAX_PASSTHROUGH_BINARY_SIZE_BYTES and is overridable via the AiConfig.maxAgentPassthroughBinarySizeBytes field, which in turn reads N8N_AI_AGENT_MAX_PASSTHROUGH_BINARY_SIZE_BYTES. The check uses Buffer.byteLength on the decoded base64 to measure true size, and the error message reports both the file size and the limit in MB.","triggerScenarios":"passthroughBinaryImages or passthroughBinaryPdfs is enabled on the Agent, and an incoming item carries a binary file (image/PDF) whose decoded size exceeds the configured limit. The model would otherwise receive an oversized payload and the provider would reject it opaquely.","commonSituations":"Large PDF or high-res image attached to the trigger; default limit too low for the use case; user enabled binary passthrough without sizing the inputs.","solutions":["Reduce the input file size before it reaches the agent (compress the image, split the PDF, or downscale).","Disable the 'passthroughBinaryImages' / 'passthroughBinaryPdfs' option if binary passthrough is not required.","Raise the limit by setting N8N_AI_AGENT_MAX_PASSTHROUGH_BINARY_SIZE_BYTES in the environment (self-hosted only), mindful of provider payload limits."],"exampleFix":"// before — oversized binary reaches the agent and trips the guard\n\n// after — gate passthrough by size upstream\nconst MAX = 20 * 1024 * 1024;\nconst items = [];\nfor (const item of $input.all()) {\n  const b = item.binary?.data;\n  if (b && Buffer.from(b.data, 'base64').length > MAX) {\n    // drop binary, keep text only\n    const { data, ...rest } = item;\n    items.push({ json: item.json, binary: undefined });\n  } else {\n    items.push(item);\n  }\n}\nreturn items;","handlingStrategy":"validation","validationCode":"const limit = Container.get(AiConfig)?.maxAgentPassthroughBinarySizeBytes ?? DEFAULT_MAX_PASSTHROUGH_BINARY_SIZE_BYTES;\nfor (const item of items) {\n  for (const key of Object.keys(item.binary ?? {})) {\n    const b = item.binary[key];\n    const buf = b.id ? await ctx.helpers.binaryToBuffer(await ctx.helpers.getBinaryStream(b.id)) : Buffer.from(b.data, 'base64');\n    if (buf.length > limit) {\n      throw new NodeOperationError(ctx.getNode(), `Binary '${key}' (${(buf.length/1048576).toFixed(1)} MB) exceeds the ${(limit/1048576).toFixed(1)} MB passthrough limit.`);\n    }\n  }\n}","typeGuard":"function isWithinBinaryLimit(buf: Buffer, limit: number): boolean {\n  return buf.length <= limit;\n}","tryCatchPattern":null,"preventionTips":["Compress or split large files before they reach the agent.","Disable passthroughBinaryImages / passthroughBinaryPdfs when not needed.","Tune N8N_AI_AGENT_MAX_PASSTHROUGH_BINARY_SIZE_BYTES only with awareness of provider payload limits."],"tags":["langchain","agent","tools-agent","binary","size-limit","configuration","env"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}