This guide assumes you have basic knowledge of Mastra and NextJS.
You’ll also need a Thesys API key from the C1 Console.
1
Create a new NextJS project
package.json
2
Create a new Mastra agent
You can follow the Mastra Quickstart to create a new Mastra agent
or just follow along this guide. We’ll set up the example weather agent from the Quickstart but change
the LLM provider to Thesys.
- Setting up the Mastra server
- Building the agent
- Building the tool
src/server/index.ts
3
Change the render function to use C1Chat
src/app/page.tsx
4
Implement the chat endpoint
We will modify the chat endpoint from the template app
to use our newly created Mastra agent and return the response as a SSE stream.
- Modifying the chat endpoint
- Modifying the message store
src/app/api/chat/route.ts
5
Run the app
We need to modify the Now simply start the app:
.env.local
file to include the Thesys API key and then add
the Mastra server to the next.config.ts
file and start the app.next.config.ts
View the code
Find more examples and complete code on our GitHub repository.