Objective: Real-time Chatbot with Logging
I’m building a real-time chatbot flow on n8n Cloud (v1.94.0) that uses the OpenAI gpt-4.1-mini model to handle incoming user messages and provide context-aware answers — particularly by referencing a Pinecone vector store when answering knowledge-based questions.
The main goals of the flow are:
- Respond to the user instantly via webhook (using either RespondToWebhook or HTTP Request) with the AI’s output.
- Silently log the same AI response to Airtable —along with some user/session metadata (e.g., timestamp, session ID, chat inputs, Agent outputs, etc.)—for internal debugging and to monitor flow behavior over time .
- Ensure the user only sees the AI’s message, without delays or exposure to the logging step.
Issue Summary
- Using gpt-4.1-mini, the AI Agent response takes ~20 seconds on average.
- This exceeds our acceptable performance threshold for live user interaction.
- Downgrading to gpt-4.1-nano reduces latency but fails at intent recognition on less explicit messages.
I’ve built two versions of the flow:
-
Chatbot_v2: uses child workflows, which introduces additional latency due to context switching. However, it successfully logs silently and returns the correct AI output to the user.
-
Chatbot_v3: consolidates everything in a single canvas to reduce communication overhead — yet latency persists.Additionally, this version triggers the following error when using HTTP Request to return the AI response:
The data in “Body Parameters” is no valid JSON. Set Body Content Type to “RAW/Custom” for XML or other types of payloads.
My Request
Could you please:
-
Help diagnose the primary causes of this delay when using gpt-4.1-mini on n8n Cloud?
-
Recommend optimization strategies or configuration tips for improving the performance of OpenAI-based flows in real-time chat scenarios?
-
Clarify how to correctly return the AI Agent’s output to the user—either via HTTP Request or RespondToWebhook—while logging to Airtable silently in the background:
- The HTTP Request node throws a JSON formatting error (see above).
- The RespondToWebhook node returns the Airtable response instead of the AI output.