# Build a Headless AI Chat API with Memory and History: n8n workflow

> Started by another system calling it, and works across n8n data table. It hands the judgement calls to Groq.

Source: https://millionrounds.com/workflow/build-a-headless-ai-chat-api-with-memory-and-history (Millionrounds; every figure on the page links to its filing or article)

[Automation library](https://millionrounds.com/workflows) · [AI assistants](https://millionrounds.com/workflows?category=AI+assistants#library)

# Build a Headless AI Chat API with Memory and History

Started by another system calling it, and works across n8n data table. It hands the judgement calls to Groq. 26 steps, 1 branch: large, and worth reading before you trust it with anything live.

Large Calls a model: Groq

[Download free](https://millionrounds.com/login?next=%2Fapp%2Fworkflow%2Fbuild-a-headless-ai-chat-api-with-memory-and-history)

**26 steps** Large: read it before trusting it with anything live

**1** Branch: places the flow splits

**0** Loops or waits

**1** Service it connects to

## The flow

Starts it 6 Model 4 Logic 6 Service 10

The steps in the order they run, from what starts it.

- 1 **Receive Chat** Webhook *Starts it*
- 2 **Joke Tool** Http Request Tool *Service*
- 3 **Get Convos Webhook** Webhook *Starts it*
- 4 **Get History Webhook** Webhook *Starts it*
- 5 **used to create the conversations table, RAN ONLY ONCE!** Data Table *Service*
- 6 **LLM** Lm Chat Groq *Model*
- 7 **LLM1** Lm Chat Groq *Model*
- 8 **CRITICAL: CLEAN DB** Data Table *Service*
- 9 **Parse Input** Code *Logic*
- 10 **Generate Reply** Agent *Model*
- 11 **Fetch User Convos** Data Table *Service*
- 12 **Fetch Full History** Data Table *Service*
- 13 **Summarize conversation** Chain Llm *Model*
- 14 **Check Exists** Data Table *Service*
- 15 **Save AI Msg** Data Table *Service*
- 16 **Format Convo List** Code *Logic*
- 17 **Format Output** Code *Logic*
- 18 **Is Existing?** If *Logic*
- 19 **Send Response** Respond To Webhook *Starts it*
- 20 **Send Convos Response** Respond To Webhook *Starts it*
- 21 **Send History Response** Respond To Webhook *Starts it*
- 22 **Save User Msg** Data Table *Service*
- 23 **Gen Conv ID** Code *Logic*
- 24 **Fetch History** Data Table *Service*
- 25 **Save New Msg** Data Table *Service*
- 26 **Format History** Code *Logic*

## How it's built

- **Starts on:** Another system calling it
- **Steps:** 26, with 1 branch
- **Size:** Large: read it before trusting it with anything live
- **Connects to:** n8n data table
- **Model:** Groq

## Questions

What does it need to run?

An n8n account, and a key for Groq. You connect your own accounts after importing it; none are included.

What starts it?

It starts on another system calling it.

Does it use AI?

Yes. It calls Groq. Model calls are billed by the provider, not by n8n.

How long does it take to set up?

Take your time. At 26 steps it is large: read it before trusting it with anything live.

How do I import it?

Copy the workflow, open a new workflow in n8n and paste. The steps appear on the canvas, ready for your own accounts.

**Before you run it**

Nothing here has been tested by us. It is somebody's working automation, read and described from its own steps. Treat the connections it wants as a list of accounts it will touch, and read the 26 steps before you point it at anything that matters.

## Run it in n8n

- **Create your n8n account** Free to start. n8n is where the workflow runs. [Create an n8n account ↗](https://millionrounds.com/n8n)
- **Download the workflow** Free with a Millionrounds account. [Download free](https://millionrounds.com/login?next=%2Fapp%2Fworkflow%2Fbuild-a-headless-ai-chat-api-with-memory-and-history)
- **Paste it into n8n** Open a new workflow in n8n and paste. Then connect your own accounts.

Stored with the author's traces removed: canvas notes, instance identifiers, saved credential names and any live document they had left behind.

## Connects to

Each opens the other workflows that use it.

[n8n data table](https://millionrounds.com/workflows?service=n8n+data+table#library)

## Workflows like it

Also ai assistants, with the same services where possible, closest in size first.

- [**Email-to-task automation with Outlook and Microsoft To Do** 26 steps · calls a model · Gmail, Google Tasks](https://millionrounds.com/workflow/email-to-task-automation-with-outlook-and-microsoft-to-do)
- [**Smart message batching AI-powered Facebook Messenger chatbot use** 25 steps · calls a model · n8n data table](https://millionrounds.com/workflow/smart-message-batching-ai-powered-facebook-messenger-chatbot)
- [**Analyze and modernize university curricula with OpenAI** 24 steps · calls a model · in-memory vectors, n8n data table](https://millionrounds.com/workflow/analyze-and-modernize-university-curricula-with-openai)
- [**Segment players and predict churn with OpenAI** 23 steps · calls a model · in-memory vectors, n8n data table](https://millionrounds.com/workflow/segment-players-and-predict-churn-with-openai)
- [**Draft dental denial appeal packets from Gmail EOBs with OpenAI** 22 steps · calls a model · Gmail, Google Drive](https://millionrounds.com/workflow/draft-dental-denial-appeal-packets-from-gmail-eobs-with-open)
- [**Route revenue transactions and assess AI outputs with Claude** 30 steps · calls a model · n8n data table](https://millionrounds.com/workflow/route-revenue-transactions-and-assess-ai-outputs-with-claude)
