n8n

How to Automate OpenAI Chat Data Answers?

Give your team a simple chat tool that can answer data questions using AI and a custom data pull. It is great for quick research, content checks, or fast Q and A without opening extra tabs.

A chat message starts the flow. An AI Agent uses the OpenAI Chat Model to understand the question. The agent has a custom tool that calls a subworkflow. That subworkflow runs on demand using When Executed by Another Workflow, pulls the top 50 posts from a public source, reshapes fields with a Set step, and returns a JSON string from a Code step. The agent reads this data and replies in plain language, like naming the fifth most popular post.

Setup is simple. You only need an OpenAI API key. The data source here is a public Hacker News feed, which needs no credentials. You can replace that node with your own API or database and keep the same shape of the response. Expect faster research, fewer clicks, and consistent answers. Good fits include trend checks, content scouting, and product research. Test by asking the sample question in chat.

What are the key features?

  • Chat trigger captures user questions and starts the flow
  • AI Agent uses the OpenAI Chat Model to interpret intent
  • Custom tool exposes a subworkflow the agent can call on demand
  • Execute Workflow Trigger runs the data fetch function safely
  • Hacker News node retrieves the top 50 posts for analysis
  • Set step cleans and reshapes fields into a simple JSON structure
  • Code step returns one response field with a JSON string
  • Agent composes a clear answer using the tool output

What are the benefits?

  • Reduce manual searching from 20 minutes to under 1 minute
  • Answer repeat data questions without switching tools
  • Improve consistency by using one structured data pull
  • Support many chat users with the same reliable tool call
  • Connect AI reasoning directly to a live data source

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 and Hacker News. See the Tools Required section above for links to create accounts with these services.
  3. In the n8n credentials manager, create an OpenAI credential. Choose API Key, paste your key from your OpenAI account, and give the credential a clear name like OpenAI Prod.
  4. Open the OpenAI Chat Model node and select your OpenAI credential. Choose a suitable model such as gpt 4o mini.
  5. Open the AI Agent node and confirm the language model is linked. Ensure the custom tool named hn tool is enabled for the agent.
  6. Open the Custom tool node and verify the workflow reference points to this workflow. Leave inputs empty unless you plan to pass arguments.
  7. In the subworkflow path, open the Hacker News node. Confirm the limit is set to 50 and the resource is set to all. No credential is required for this public feed.
  8. Open the Set node labeled Clean up data. Check that key fields like title are mapped to simple names you want the agent to use.
  9. Open the Code node named Stringify. Confirm it returns a response field that contains JSON.stringify of the items.
  10. Click Chat in the editor and ask What is the 5th most popular post ever on Hacker News. You should receive a direct answer based on the fetched list.
  11. If no data returns, run the subworkflow starting at When Executed by Another Workflow and inspect the Hacker News output. If the agent replies without details, confirm the tool is connected to the AI Agent and that your OpenAI credential is valid and within quota.

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.

Hacker News

Sign up

Free: $0 / mo, public read-only API (no auth, no stated rate limit)

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.