How to set runtimeContext with chatRoutes
In my current setup, i add some runtime context in the api/route.ts which is then passed to the agent.stream options. How do I implement the same when using chatRoute?
4 Replies
š Created GitHub issue: https://github.com/mastra-ai/mastra/issues/10385
š 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!
Option 1: Middleware
Option 2: Send in Request Body
chatRoute automatically picks up requestContext from either source and passes it to agent.stream().Hey! @Grayson Thanks for replying.
can you point me to some documentation for the second option ?
hey @Grayson ! can you help me in figuring out how to use the second option you suggested ? I have a bunch of api routes which stream different agents. I add runtime context at the Next.js api route level. This context comes from the frontend client as request body.
Hey sorry, was out of office. Can you post a minimal repro of what you are trying to do?
(I think I may have mixed up requestContext and runtimeContext in your question)