
Vercel AI SDK vs LangChain.js: Size, Speed and a Verdict
Vercel AI SDK vs LangChain.js tested on one agent: install size, bundle, cold start, state, approvals and MCP, with a clear verdict for Node.js teams.
- What: Vercel AI SDK vs LangChain.js, compared on the same one-tool agent: install size, bundle, cold start and agent features.
- Why it matters: The choice fixes your streaming UI, agent runtime and serverless footprint for years.
- What to do: Default to the AI SDK; add LangGraph when you need checkpointed, resumable agent state.
- Key stat: In our run, LangChain.js imported in 0.33 s versus 0.08 s for AI SDK 7.0.184.
Vercel AI SDK vs LangChain.js comes down to state. The AI SDK is a lean, provider-agnostic toolkit with first-class React streaming, and in our test it installed about a quarter of the disk footprint. LangChain.js runs agents on LangGraph, so you get checkpoints, resume and human-in-the-loop built in, at the cost of a heavier dependency tree.
The Vercel AI SDK (npm package ai) is an open-source TypeScript toolkit that gives one API for text generation, structured output, tool calls and agents across model providers, plus UI hooks such as useChat. LangChain.js is an open-source agent framework whose createAgent runs on LangGraph, a stateful graph runtime with built-in persistence.
Vercel AI SDK vs LangChain.js is the first architecture call most Node.js teams make when they add an LLM feature, and the online comparisons are hard to trust. Many still benchmark AI SDK 3 against LangChain 0.3, versions that no longer exist in the same shape. Since then, LangChain shipped v1 with createAgent and middleware, and the AI SDK reached major version 7, published on 25 June 2026. Both now have an agent class, MCP support and tool approval, so the old “AI SDK for chat, LangChain for agents” rule needs re-checking.
To settle Vercel AI SDK vs LangChain.js with data, we built the same one-tool agent in both, on current releases, and measured what each costs to install, bundle and import. All commands and raw output are below. The post then compares the features that actually differ: state, persistence, approvals and UI streaming. It ends with a verdict, plus a pattern that lets you use both.
What is the core difference in Vercel AI SDK vs LangChain.js?
The core difference is where agent state lives. The AI SDK treats an agent as a loop over messages that your app stores. LangChain.js treats an agent as a graph whose state a checkpointer saves for you.
The AI SDK docs describe its ToolLoopAgent as handling “the loop, context management, and stopping conditions.” Persistence is your job: the message persistence guide saves UIMessage arrays in an onEnd callback to a store you choose.
LangChain’s v1 release notes say createAgent is built on LangGraph, so persistence, streaming, human-in-the-loop and “time travel” work out of the box. The LangGraph persistence docs split this into checkpointers for thread state and stores for cross-thread memory.
Here is the same agent in both. Each file constructed its agent without errors on Node.js v22.23.5 in our sandbox (we did not call a live model).
// agent-aisdk.mjs (ai@7.0.184, @ai-sdk/openai@4.0.125, zod@4.6.7)
import { ToolLoopAgent, tool, stepCountIs } from 'ai';
import { openai } from '@ai-sdk/openai';
import { z } from 'zod';
const getOrder = tool({
description: 'Look up an order',
inputSchema: z.object({ id: z.string() }),
execute: async ({ id }) => ({ id, status: 'shipped' }),
});
export const agent = new ToolLoopAgent({
model: openai('gpt-5-mini'),
tools: { getOrder },
stopWhen: stepCountIs(5),
});
// const { text, steps } = await agent.generate({ prompt: 'Where is order 42?' });
// agent-langchain.mjs (langchain@1.6.8, @langchain/core@1.5.1, @langchain/openai@1.8.5)
import { createAgent, tool } from 'langchain';
import { ChatOpenAI } from '@langchain/openai';
import { z } from 'zod';
const getOrder = tool(
async ({ id }) => JSON.stringify({ id, status: 'shipped' }),
{ name: 'getOrder', description: 'Look up an order', schema: z.object({ id: z.string() }) },
);
export const agent = createAgent({
model: new ChatOpenAI({ model: 'gpt-5-mini' }),
tools: [getOrder],
});
// const result = await agent.invoke({ messages: [{ role: 'user', content: 'Where is order 42?' }] });
The shapes are close. The AI SDK passes tools as an object keyed by name and stops on a condition you set. LangChain passes an array and keeps calling tools until the model stops asking for them.
How much heavier is LangChain.js than the Vercel AI SDK?
In our test, LangChain.js was about four times larger on disk and twice as large bundled. That matters for serverless cold starts, CI install time and your supply-chain surface.
How we measured
- Create two empty npm projects and install pinned versions of each stack.
- Bundle the agent file above with esbuild 0.25.12 using
--bundle --minify --platform=node. - Time a cold
import()of the agent file seven times and take the median.
npm i ai@7.0.184 @ai-sdk/openai@4.0.125 zod # project A
npm i langchain@1.6.8 @langchain/core@1.5.1 @langchain/openai@1.8.5 zod # project B
npx esbuild agent.mjs --bundle --minify --platform=node --format=esm --outfile=out.mjs
gzip -c out.mjs | wc -c
/usr/bin/time -f "%e s %M KB" node -e "import('./agent.mjs')" # 7 runs, median
Raw results, Node.js v22.23.5, 4-core Linux sandbox, 29 November 2026:
AI SDK 7 LangChain.js 1.6
packages installed 11 25
node_modules (no esbuild) 28.5 MiB 110.0 MiB
bundle, minified 1,113,029 B 2,021,830 B
bundle, gzipped 253,438 B 505,199 B
cold import (median) 0.08 s 0.33 s
peak RSS on import 69,968 KB 132,644 KB
bare `node -e ""` 0.01 s / 41,216 KB (baseline)
The import gap comes mostly from the framework itself. Importing langchain alone took a median 0.27 s in our run, against 0.07 s for ai. LangChain’s tree also pulls in langsmith, @langchain/langgraph and the official openai SDK, which explains the extra 14 packages.
The edge-runtime gotcha
We also bundled both with --platform=neutral --conditions=browser, a rough stand-in for edge targets. The AI SDK bundle built. The LangChain bundle failed with Could not resolve "node:fs" from langsmith/lib/utils/fs.mjs. Real edge runtimes with Node compatibility flags may behave differently, so test your target. But if you deploy to an edge function, check this before you commit.
One more practical constraint: ai@7 declares Node.js 22 or later in its engines field, while langchain 1.6.8 declares Node.js 20 or later. Teams still on Node 20 Lambda runtimes will feel that.
Which handles agent state and persistence better?
LangChain.js handles state better, because LangGraph saves it for you. The AI SDK gives you clean hooks, but you write the store.
With LangGraph you compile a graph with a checkpointer and pass a thread_id. The persistence docs list two traps worth knowing. MemorySaver keeps checkpoints in RAM, so a restart loses everything. And with PostgresSaver, the docs advise keeping thread_id values under 255 characters; use a UUID or hash.
The AI SDK route is more manual but more transparent. The persistence guide stores messages in the useChat format and validates them with validateUIMessages on load. It also documents consumeStream(), which keeps generation running and saving even after the client disconnects. We covered the opposite case, cancelling on disconnect, in our guide to cancelling an LLM stream on client disconnect in Node.js.
Neither gives you full durable execution. A LangGraph checkpoint is saved at step boundaries, so side effects inside a node can run twice. Our durable execution for AI agents guide explains why idempotency keys still matter.
How do tool approval and MCP compare in Vercel AI SDK vs LangChain.js?
Both now support human approval and MCP, with different ergonomics. Approval is where the state difference shows up most.
In the AI SDK, you set toolApproval on generateText, streamText or ToolLoopAgent. Each tool can be 'not-applicable', 'approved', 'denied' or 'user-approval', or decided by a function. The older per-tool needsApproval property is now deprecated. Your UI receives an approval request part, and your app resumes the call.
LangChain ships humanInTheLoopMiddleware, which interrupts the graph and lets a reviewer approve, edit or reject a call. Because the paused state sits in the checkpointer, the reviewer can answer hours later from another process. That is the practical win.
For MCP, the AI SDK has a built-in MCP client that recommends HTTP transport for production and limits stdio to local servers. LangChain uses the separate @langchain/mcp-adapters 2.0 package, whose MCPAdapter can mix stdio and HTTP servers in one adapter.
Middleware is LangChain’s other differentiator. The v1 docs list six hooks, from beforeAgent to afterAgent, plus prebuilt summarization and PII-redaction middleware. The AI SDK covers similar ground with prepareStep and stopWhen, but you compose it yourself.
Which is better for React and Next.js streaming UIs?
The AI SDK is better for UI streaming, and it is not close. useChat, typed message parts and a documented stream protocol are the reason most teams adopt it.
Its introduction lists React, Next.js, Vue, Svelte and Node.js as targets, with AI SDK UI as “framework-agnostic hooks.” LangChain does not ship an equivalent chat hook for these frameworks in the langchain package.
Adoption reflects this. The ai package logged 43,201,794 npm downloads in the week of 21–27 November 2026. The langchain package logged 4,199,737 for 15–21 November 2026, the latest window the npm API returned for it. Downloads include CI and transitive installs, so treat them as a rough signal.
Schema choice matters here too. Both accept Zod; our Zod vs Valibot comparison shows how the import style alone can triple a client bundle.
Can you use LangChain.js and the Vercel AI SDK together?
Yes, and for many teams it is the best answer. The official @ai-sdk/langchain adapter converts AI SDK UI messages into LangChain messages and streams LangGraph output back into useChat.
// app/api/agent/route.ts — LangGraph agent, AI SDK UI (per the @ai-sdk/langchain docs)
import { createUIMessageStreamResponse, UIMessage } from 'ai';
import { toBaseMessages, toUIMessageStream } from '@ai-sdk/langchain';
import { agent } from '@/lib/langchain-agent'; // createAgent(...) from the example above
export async function POST(req: Request) {
const { messages }: { messages: UIMessage[] } = await req.json();
const stream = await agent.stream(
{ messages: await toBaseMessages(messages) },
{ streamMode: ['values', 'messages', 'tools'] },
);
return createUIMessageStreamResponse({ stream: toUIMessageStream(stream) });
}
The adapter’s toUIMessageStream detects direct model streams, LangGraph streams and streamEvents() output automatically. Tool progress streams as preliminary output when you include the tools stream mode. We confirmed the package exists at version 3.0.184, with @langchain/core as a required peer.
My recommendation: keep provider calls that need failover in one layer. Whichever SDK you choose, wrap model calls the way our LLM fallback circuit breaker guide describes, so an outage at one provider doesn’t take down the agent.
| Factor | Vercel AI SDK | LangChain.js |
|---|---|---|
| Packages installed (our run) | 11 | 25 |
| node_modules size (our run) | 28.5 MiB | 110.0 MiB |
| Gzipped agent bundle (our run) | 253 KB | 505 KB |
| Cold import, median (our run) | 0.08 s | 0.33 s |
| Node.js engines | >=22 | >=20 |
| Agent class | ToolLoopAgent | createAgent on LangGraph |
| Built-in persistence | No; app stores messages | Checkpointers and stores |
| Tool approval | toolApproval | humanInTheLoopMiddleware |
| MCP | Built-in client | @langchain/mcp-adapters |
| React chat hooks | useChat (AI SDK UI) | Via @ai-sdk/langchain |
The NexGismo verdict: for most Node.js and Next.js products, start with the Vercel AI SDK. It is lighter, imports four times faster in our test and owns the UI layer. Reach for LangChain.js, specifically LangGraph, when an agent must pause for approval, survive restarts or run for many steps. When you need both, bridge them with @ai-sdk/langchain instead of choosing one.
- In a sandbox test of the same one-tool agent, LangChain.js 1.6.8 installed 25 packages and 110 MiB, versus 11 packages and 28.5 MiB for AI SDK 7.
- LangChain.js took a median 0.33 seconds to import on Node.js 22, compared with 0.08 seconds for the AI SDK.
- LangChain’s createAgent runs on LangGraph, which adds checkpointed thread state, resume and human-in-the-loop interrupts.
- The AI SDK leaves persistence to the application, storing UIMessage arrays in an onEnd callback.
- LangGraph’s MemorySaver loses all checkpoints on restart, so production agents need PostgresSaver or another durable checkpointer.
- The @ai-sdk/langchain adapter streams LangGraph agent output into the AI SDK’s useChat hook.
Frequently Asked Questions
Is Vercel AI SDK better than LangChain?
Neither is better for every project. The Vercel AI SDK is lighter and has the best React and Next.js streaming hooks; in our test it imported in 0.08 seconds versus 0.33 seconds for LangChain.js. LangChain.js is better when agents need built-in checkpoints, resume after restarts or human approval that can wait hours.
Can I use LangChain with the Vercel AI SDK?
Yes. The official @ai-sdk/langchain adapter converts AI SDK UI messages to LangChain messages with toBaseMessages and streams LangChain or LangGraph output back to the useChat hook with toUIMessageStream. That lets you run a LangGraph agent on the server and keep the AI SDK chat UI on the client.
Does the Vercel AI SDK only work on Vercel?
No. The AI SDK is an open-source TypeScript package that runs in any Node.js environment, and its docs list React, Next.js, Vue, Svelte and Node.js as targets. Vercel hosting is optional. Version 7 of the ai package declares Node.js 22 or later in its engines field, so check your runtime version.
Does LangChain.js work in edge runtimes?
Test it on your exact target first. In our esbuild test with a neutral platform and browser conditions, the LangChain.js agent bundle failed to resolve node:fs from the langsmith dependency, while the AI SDK bundle built. Edge runtimes with Node.js compatibility flags may behave differently, so deploy a minimal agent before committing.
Does the Vercel AI SDK support AI agents?
Yes. The AI SDK provides a ToolLoopAgent class that runs a model and tools in a loop, with stopping conditions such as stepCountIs and per-step control through prepareStep. It also supports tool approval through toolApproval and MCP tools through a built-in client. It does not persist agent state for you; your application stores the messages.
Which should you pick?
The Vercel AI SDK vs LangChain.js decision should follow your hardest requirement, not the demo. If your feature is a chat or tool-calling endpoint that finishes inside one request, the AI SDK gives you less code, a smaller bundle and the best React streaming. If your agent must wait for a human, resume after a deploy or remember a thread across sessions, LangGraph’s checkpointer saves you from building that storage layer yourself.
Before you settle Vercel AI SDK vs LangChain.js for your team, rerun our three commands on your real agent and target runtime. The numbers move with your tools and providers. If you try it, tell us what you measured, and we’ll add a follow-up covering Python LangGraph with an AI SDK front end.
Sources
- AI SDK Docs — Introduction
- AI SDK Docs — Agents overview (ToolLoopAgent)
- AI SDK Docs — Tools and tool calling (toolApproval)
- AI SDK Docs — Model Context Protocol tools
- AI SDK Docs — Chatbot message persistence
- AI SDK Docs — LangChain adapter (@ai-sdk/langchain)
- LangChain Docs — What’s new in LangChain v1 (JavaScript)
- LangChain Docs — LangGraph persistence (JavaScript)
- LangChain Docs — Model Context Protocol with MCPAdapter
- npm registry — ai package metadata and release dates
- npm registry — langchain latest package metadata
- npm downloads API — ai, last week
- npm downloads API — langchain, last week