Build five real AI features with the Vercel AI SDK and LangChain.js: a streaming chat with useChat, typed structured output, tool calling with per-user security, RAG with LangChain retrievers, and a LangChain agent streamed into useChat. Plus safe output parsing, how pipe() works, and shipping responsibly.
When you build an AI feature in a JavaScript app, two libraries come up again and again. They overlap a little, but they're built for different jobs.
Vercel AI SDK (ai) | LangChain.js (langchain) | |
|---|---|---|
| Best at | AI features inside a web product: streaming chat, structured output, tool calls, and the React hooks that render them | Building blocks for LLM pipelines: document loaders, text splitters, vector store integrations, retrievers, chains, and agents |
| Feels like | A small, typed API: streamText, generateText, useChat | A big toolbox of composable pieces |
| Frontend story | First-class: useChat in @ai-sdk/react handles messages, streaming, stop, retry, and tool calls | Server-side; connects to AI SDK UI through the official @ai-sdk/langchain adapter |
| Providers | One interface for Anthropic, OpenAI, Google, and many more | Also provider-agnostic (@langchain/anthropic, @langchain/openai, …) |
| Workflows | Tool loops with stop conditions; agents with ToolLoopAgent | Agents with createAgent, and LangGraph for multi-step, stateful, resumable workflows |
A practical rule: start with the AI SDK for anything a user interacts with. Reach for LangChain when you need its integrations (a specific loader or vector store), or when the workflow is complex enough to want LangGraph. They combine well: LangChain on the server, AI SDK on the frontend.
What you'll build (each project is a common production feature):
useChatVersions: this tutorial was written and checked against AI SDK 7 (ai 7, @ai-sdk/react 4) and LangChain.js 1.6 (langchain 1, @langchain/core 1). Both libraries rename APIs between major versions, and many tutorials online still show older ones. If your versions differ, check each library's migration guide.