n8n

How to Connect OpenAI Database Insights?

Turn chat questions into clear answers from a local database. Team members ask in plain English and get results without writing SQL. Ideal for operations and analyst roles that need quick numbers and simple reports.

A one time setup downloads a sample SQLite file, unzips it, and saves it on the server. For every new chat message, the flow loads the local database, combines it with the chat JSON, and sends both to an AI SQL agent. The agent uses OpenAI gpt 4 turbo with a steady temperature and can run several SQL queries before it answers. A memory buffer keeps the last 10 messages so follow up questions make sense. This creates fast self service insights without building dashboards.

You only need an OpenAI API key and access to the n8n chat endpoint. Keep the sample file or point the load step to your own SQLite database path. Expect faster replies to ad hoc data questions, fewer requests to data specialists, and more time saved across the team. Use it for sales revenue checks, catalog lookups, or quick ops metrics when speed matters.

What are the key features?

  • Chat Trigger starts a new turn for each user message.
  • Local SQLite file is loaded on demand and attached to the request.
  • AI SQL agent can run multiple queries before giving a final answer.
  • OpenAI gpt 4 turbo model with low temperature for steady results.
  • Memory window stores the last 10 turns for follow up questions.
  • One time setup downloads, extracts, and saves a sample database.
  • Binary handling combines chat JSON and the database in a single payload.

What are the benefits?

  • Reduce ad hoc SQL requests from 1 hour to 5 minutes
  • Automate up to 80 percent of simple data questions
  • Improve accuracy by querying the source database directly
  • Keep context across 10 chat messages to cut rework
  • Support many chat requests without manual effort

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with OpenAI. See the Tools Required section above for links to create accounts with these services.
  3. In n8n, open the Credentials tab and create a new OpenAI credential. Visit the OpenAI website, create an API key from your account API page, and paste it into the credential. Name the credential clearly, for example OpenAI Prod.
  4. Open the OpenAI Chat Model node and select your OpenAI credential. Confirm the model is set to gpt 4 turbo and temperature is 0.3.
  5. If you want the sample data, run the manual trigger section once. Click Test workflow to download, extract, and save the SQLite file locally.
  6. If you prefer your own database, remove the download and extract nodes, upload or place your SQLite file on the server, and update the Load local SQLite node path to your file.
  7. Open the Load local SQLite node and verify the file path resolves. Click Execute node to confirm the file loads without errors.
  8. Check the Combine chat input with the binary node. Make sure Include Binary is enabled and the JSON output references the Chat Trigger item JSON.
  9. Start the workflow and open the chat interface from the Chat Trigger panel. Send a test message like Please describe the database and watch the AI Agent node steps.
  10. If you see file not found, check the database path and permissions. If answers look off, lower temperature or increase the memory window length in the Memory node.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

OpenAI

Sign up

Pay-as-you-go: GPT-5 at $1.25 per 1M input tokens and $10 per 1M output tokens

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.