Skip to content

Commit 99500f0

Browse files
Docs: Add image and file upload handling guide for n8n workflows
- Document how clients send images (base64-encoded in messages) - Explain token management with detail parameter (low/high/auto) - Provide 3 common approaches for processing images in n8n - Add practical code example for setting detail parameter - Clarify that bridge passes through, n8n handles processing Related to: #46
1 parent 31933c9 commit 99500f0

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

docs/N8N_SETUP.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,89 @@ Webhook → Extract Chat Body → AI Agent → (Response)
150150

151151
The Webhook node receives the entire HTTP request in `$json`, with the actual chat data nested in `$json.body`. The "Extract Chat Body" node (a Set node) extracts this nested data and flattens it, making fields like `chatInput` and `sessionId` directly accessible to the AI Agent.
152152

153+
## Handling Images and File Uploads
154+
155+
The bridge passes file uploads and images through to n8n as-is. Your workflow must handle image extraction and processing.
156+
157+
### How Clients Send Images
158+
159+
Clients like LibreChat and Open-webUI send images embedded in the message content as base64-encoded data:
160+
161+
```json
162+
{
163+
"messages": [
164+
{
165+
"role": "user",
166+
"content": [
167+
{"type": "text", "text": "What's in this image?"},
168+
{
169+
"type": "image_url",
170+
"image_url": {
171+
"url": "data:image/jpeg;base64,/9j/4AAQSkZJRg...",
172+
"detail": "low"
173+
}
174+
}
175+
]
176+
}
177+
]
178+
}
179+
```
180+
181+
### Token Management for Images
182+
183+
The `detail` parameter controls how many tokens the image uses:
184+
185+
- `"low"` - 65 tokens per image (recommended)
186+
- `"high"` - 65-765 tokens depending on image size
187+
- `"auto"` - LLM provider decides (default, usually "high")
188+
189+
**Important:** If clients don't set `detail`, images may consume 500+ tokens and cause "too many tokens" errors. You can add the `detail` parameter in your n8n workflow before passing to the LLM.
190+
191+
### Processing Images in n8n
192+
193+
Your workflow needs to extract and handle images from the `messages` array. Common approaches:
194+
195+
**Option 1: Pass through to LLM (if supported)**
196+
- Extract entire `messages` array
197+
- Forward to LLM that supports vision (GPT-4V, Claude 3, etc.)
198+
- Ensure `detail: "low"` is set to avoid token issues
199+
200+
**Option 2: Upload to storage**
201+
- Extract base64 image data
202+
- Upload to S3, Cloudinary, or similar
203+
- Replace base64 with public URL
204+
- Forward modified messages to LLM
205+
206+
**Option 3: Process locally**
207+
- Extract image for analysis
208+
- Use separate vision API/service
209+
- Combine results with chat response
210+
211+
### Example: Setting detail Parameter in n8n
212+
213+
Use a Code node to ensure all images use `detail: "low"`:
214+
215+
```javascript
216+
const messages = $json.messages || [];
217+
218+
const processedMessages = messages.map(msg => {
219+
if (Array.isArray(msg.content)) {
220+
msg.content = msg.content.map(item => {
221+
if (item.type === 'image_url' && item.image_url) {
222+
// Set detail to low if not specified
223+
if (!item.image_url.detail) {
224+
item.image_url.detail = 'low';
225+
}
226+
}
227+
return item;
228+
});
229+
}
230+
return msg;
231+
});
232+
233+
return { messages: processedMessages };
234+
```
235+
153236
## Testing Your Workflow
154237

155238
1. Save and activate the workflow in n8n

0 commit comments

Comments
 (0)