1
Install required dependencies
Install the necessary packages for your backend API:
npm
2
Create the message store
First, create a simple in-memory message store to manage conversation history.
This in-memory store just stores the list of messages for a given
threadId
including messages that are not sent to the client like the tool call messages.app/api/chat/messageStore.ts
3
Create the chat endpoint
Create the main API endpoint that handles incoming chat requests with streaming:
app/api/chat/route.ts
4
Set your API key
Make sure to set your Thesys API key as an environment variable:
Next.js (.env.local)