M
Mastra•5d ago
TepidToast

Deploying Mastra with NextJS

Hi there! Loving Mastra so far, but getting to deployment now and I'm a little confused. So I'm deploying this with my next.js app, and I was wondering how workflow streaming would work. In the docs, it says to include workflow streaming with ai sdk as WorkflowRoute in mastra index.ts - does this mean that its a seperate server? If I want to integrate it into my nextjs app with workflow streaming, does that needs to be a route hosted in my nextjs app or does including the mastra package in the external dependencies and the WorkflowRoute in the index.ts cover that? Please let me know!
4 Replies
kprocks
kprocks•5d ago
WorkflowRoute in mastra index.ts is uses mastra api that is separate server other then nextjs i would not choose this.
export const mastra = new Mastra({
server: {
apiRoutes: [
workflowRoute({
path: "/workflow",
workflow: "weatherWorkflow",
includeTextStreamParts: true,
}),
],
},
});
export const mastra = new Mastra({
server: {
apiRoutes: [
workflowRoute({
path: "/workflow",
workflow: "weatherWorkflow",
includeTextStreamParts: true,
}),
],
},
});
this will then be uses as http://localhost:4111/workflow The ideal way to work with nextjs is to install the mastra package in nextjs which is described here : https://mastra.ai/guides/v1/getting-started/next-js after this you need to create a separate route in nextjs and implement your logic using workflow.streamVNext(...) same as agent.stream(...) in example
Abhi Aiyer
Abhi Aiyer•5d ago
Yeah in NextJS you should use Mastra through NextJS
Mastra Triager
Mastra Triager•4d ago
šŸ“ Created GitHub issue: https://github.com/mastra-ai/mastra/issues/10818 šŸ” If you're experiencing an error, please provide a minimal reproducible example whenever possible to help us resolve it quickly. šŸ™ Thank you for helping us improve Mastra!
TepidToast
TepidToastOP•3d ago
perfect! thanks for the info

Did you find this page helpful?