TypeScript: AI SDK & Mastra
Recommended libraries and frameworks for integrating AI into TypeScript applications.
The TypeScript ecosystem has two main options depending on the complexity of the use case:
| AI SDK (Vercel) | Mastra | |
|---|---|---|
| Best for | Streaming, structured output, tool use in web/API apps | Complex agents, workflows, persistent memory |
| API surface | Small, very focused | Broader, opinionated |
| React integration | Native hooks (useChat, useCompletion) | No (backend-first) |
| Multi-provider | Yes (OpenAI, Anthropic, Google, Mistral…) | Yes (via AI SDK internally) |
| Workflows | No (basic primitives) | Yes (typed step graph) |
| Memory | Manual | Built-in |
For most Aircury TypeScript projects: start with AI SDK, migrate to Mastra when you need multi-step workflows or persistent memory across sessions.
AI SDK (Vercel)
The reference SDK for AI in TypeScript. Covers the most common use cases with a minimal, consistent API: text, streaming, structured output, and tool use with unified multi-provider support.
Covers the following cases well:
- Basic and streaming calls to any provider
- Typed structured output with Zod schemas
- Tool use with automatic tool call loop
- React hooks for conversational interfaces (
useChat,useCompletion) - MCP server integration
Official docs: sdk.vercel.ai/docs
Mastra
Opinionated TypeScript framework for building AI agents and workflows. Where AI SDK is a low-level library, Mastra is a full platform with agents, persistent memory, graph-based workflows, and built-in observability.
Covers the following cases well:
- Agents with typed instructions and tools
- Short-term and long-term memory across sessions
- Multi-step workflows with explicit branches and dependencies
- MCP server integration
- Telemetry and tracing via OpenTelemetry
Official docs: mastra.ai/docs
When to use each
Use AI SDK if you have a React/Next.js app, need streaming to the client, or your use case is relatively simple. Use Mastra if you’re building agents with memory across sessions, have multi-step workflows, or are managing multiple specialized agents.
On This Page