Skip to content

Function: threadsRoute()

threadsRoute(options): ApiRoute[]

Register the <path> Mastra custom API route. Handles three methods on the same mount:

  • GET: a page of the resource’s conversation threads (listThreads).
  • DELETE: remove the thread named by the thread-selection header / ?threadId= query (deleteThread). The id is read from RequestContext (the auth middleware resolves it the same way it does for streaming and history), so the client deletes any of its threads by stamping the target id - no separate path param.
  • PATCH: rename the thread named by the thread-selection header / ?threadId= query to the { title } in the JSON body (renameThread). Targets a thread the same way DELETE does; 404s when the thread isn’t owned by the caller.

Follows the @mastra/ai-sdk agent-binding convention: pass agent for a fixed-agent mount, or include :agentId in the path for dynamic routing. The plugin registers both /route/threads (default agent) and /route/threads/:agentId.

ThreadsRouteOptions

ApiRoute[]