Monitor Gemini Chat Interactions with Langfuse Tracing - n8n Workflow

Use this powerful n8n workflow to monitor and trace all Gemini 2.5 chat interactions using Langfuse observability. Essential for debugging custom n8n templates and analyzing AI performance.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

AI Developers needing robust observability tools for their production LLM applications.
Data Scientists and MLOps Engineers who require detailed tracing of conversational flow and token usage.
Users building complex conversational systems using n8n templates and the Langchain integration.
Anyone leveraging the Google Gemini API within an n8n workflow who needs performance monitoring.

Overview

Developing reliable AI applications requires more than just calling an API; it demands deep visibility into how the models process inputs and generate outputs. This specialized n8n workflow template addresses the critical need for observability by integrating Langfuse tracing directly into the conversational pipeline powered by Google Gemini 2.
5.

This robust solution allows you to capture every detail of the chat session, including context, token usage, and latency, which is essential for debugging, cost optimization, and improving model performance. By utilizing a custom n8n node to inject the Langfuse callback handler, this n8n workflow ensures that your Langchain-based AI Agent is fully instrumented from the moment the conversation begins. This provides the necessary tools for professional monitoring, making this one of the most valuable n8n templates for serious AI development.

How it Works

The entire process starts with the primary n8n trigger, the When chat message received n8n node, which initiates the conversation when a new message arrives via a webhook. This message is passed directly to the AI Agent n8n node, which handles the orchestration of the LLM and memory components.

The core intelligence is the gemini-2.5 n8n node, which defines the underlying language model (Gemini 2.5 Flash). Instead of connecting directly to the Agent, this model is piped into the Langfuse LLM custom code n8n node.

Inside the Langfuse LLM n8n node, a custom script takes the Gemini model object and dynamically wraps it with the Langfuse CallbackHandler, using the sessionId provided by the initial n8n trigger data. This creates an instrumented LLM.

This newly instrumented model is then provided to the AI Agent n8n node. Concurrently, the mem (Buffer Window Memory) n8n node is connected to the Agent, providing conversational context. The AI Agent utilizes the traced Gemini model and the conversation history to generate a response, ensuring every step of the processing is automatically logged and sent to your Langfuse dashboard for detailed analysis.

Installation Guide


  1. Import the n8n workflow: Copy the provided JSON data and paste it into your n8n instance using the 'New' menu and selecting 'Import from JSON'.

  2. Set up Gemini Credentials: Locate the gemini-2.5 n8n node. You will need to set up or select credentials for the Google Gemini API (formerly Google Palm). Ensure you have access to the Gemini 2.5 models.

  3. Configure Langfuse Environment Variables: Langfuse integration typically requires environment variables (like LANGFUSEPUBLICKEY, LANGFUSESECRETKEY, and LANGFUSE_HOST) to be configured on your n8n host environment, allowing the custom code n8n node to successfully send traces.

  4. Activate the Trigger: The When chat message received n8n trigger is a webhook-based n8n node. Once activated, copy the webhook URL and configure your chat front-end application to send messages to this endpoint. This completes the setup of this powerful n8n workflow.

Node Details

When chat message received (n8n trigger):
Function: Serves as the starting n8n trigger, initiating the automation when an external chat message is received via a unique webhook.
Key Configuration: Provides necessary input data, including the sessionId used later by the Langfuse code for tracing context.
gemini-2.5 (LLM Chat Google Gemini n8n node):
Function: Defines the core Large Language Model used for generating responses.
Key Configuration: Uses models/gemini-2.5-flash-preview-05-20 and sets the generation temperature to 0.4.
Langfuse LLM (Langchain Code n8n node):
Function: This is the critical custom n8n node responsible for instrumenting the LLM. It imports the Langfuse callback handler, initializes it using the input sessionId, and wraps the incoming Gemini model, ensuring all subsequent calls are traced by Langfuse.
Key Configuration: Custom JavaScript code handles the model wrapping and callback injection.
mem (Memory Buffer Window n8n node):
Function: Maintains conversational history for the AI Agent.
Key Configuration: Configured with a context window length of 100 tokens/messages.
AI Agent (Langchain Agent n8n node):
Function: The central orchestration unit. It receives the chat message, utilizes the instrumented LLM (from the Langfuse LLM node), and leverages the provided memory to formulate the final, context-aware response. This powerful n8n node completes the conversational loop.

Related n8n Workflows

Free

Nodes: 5 Nodes
Updated: December 26 2025
View all
Created by
Eduardo Hales
Eduardo Hales

Full Stack Developer with 8+ years building web applications, now focused on AI engineering and cybersecurity. I integrate LLMs into production systems, conduct security audits, and help teams build safer, smarter software. Particularly interested in making AI applications both powerful and secure.

Featured*