Should you use the AI SDK or LangChain in TypeScript?

  • Isaac
    Isaac
    AI Systems Engineer

The AI SDK is Vercel's open-source TypeScript toolkit for calling models through one interface across providers, covering text, structured output, embeddings and reranking. We removed LangChain from monogram.io, and the site's retrieval, our own agents and most model calls in our internal tools app run on the AI SDK. Choose LangChain when you need its integration catalog or graph orchestration; choose the AI SDK when you want thin calls you can read end to end.

What is the AI SDK, and do you need Vercel to use it?

The AI SDK is a provider-agnostic TypeScript library. It runs anywhere Node runs, and you can reach a model through a provider package such as the OpenAI or Anthropic one, or through the gateway provider that routes to Vercel AI Gateway. Hosting on Vercel is not required, and the SDK itself is free; you pay the model provider.

Our code routes through the Gateway. On monogram.io, choosing a model is a Gateway string like openai/text-embedding-3-small or cohere/rerank-v4-fast, and the same string format names the chat model in the agent config. The embedding and rerank models are one-line constants in a shared package, and changing the embedding model also needs a full re-index.

AI SDK vs LangChain: which should you use?

LangChain is a framework with prebuilt loaders, chains and a large integration catalog. The AI SDK is a smaller set of functions you compose yourself. Neither is wrong; they sit at different levels of abstraction.

monogram.io used to ingest content with LangChain's OpenAIEmbeddings. The assistant rebuild dropped every LangChain package from the site and replaced them with a gateway-routed embedding helper on each side, for ingestion and for retrieval, built on the AI SDK's embed and embedMany. The reason was routing: every embedding now goes through the Gateway with the same model and dimensions. Query vectors and stored vectors are produced by two mirrored helpers that read the same model and dimensions from one shared package, so they cannot drift.

We would still reach for LangChain on a project that needs many of its document loaders or vendor integrations out of the box. For a retrieval pipeline we own end to end, the AI SDK's smaller surface is easier to reason about.

Can the AI SDK do RAG, embeddings and reranking?

Yes. embed, embedMany and rerank are core functions, and the SDK pairs them with whatever vector store you already run. It does not store vectors itself.

The monogram.io assistant is the working example. Both ingestion and retrieval import the embedding model and its 512 dimensions from one shared package, and the helper throws when a query vector has the wrong dimensions rather than letting it query the Pinecone index. Dense search runs beside a lexical match over Sanity content, and a rerank call to cohere/rerank-v4-fast reorders the candidates against the raw question. If the reranker is unavailable, retrieval falls back to the unreranked order. Recall improved because we rebuilt ingestion as a whole, including full-content serialization, header-aware chunks and contextual prefixes. Validated on a staging index before cutover, that rebuild took source recall on our 25-question golden set from 68% to 88%.

How do you get structured output from the AI SDK?

Call generateText with output: Output.object({ schema }) and a Zod schema, and the SDK returns a typed object that matches it. The AI SDK 6 migration guide deprecated generateObject and streamObject, says they will be removed in a future version, and points to generateText and streamText with an output setting instead.

Plenty of examples online still use generateObject, so check the migration guides before you copy one.

Should you call the OpenAI SDK directly instead?

If you use a single provider and want its newest features the day they ship, the provider's own SDK is the thinner choice. The AI SDK pays off once you call more than one provider or want the same behavior on every call.

Our internal tools app runs both, on purpose. An OpenAI SDK client pointed at AI Gateway's endpoint serves the image tools and several chat tools, and the AI SDK's createGateway provider serves the rest, both built on the same key. The difference shows when we add a rule to every call. Every chat model there is told today's date so no tool drafts a document dated last year. On the AI SDK side that is one wrapLanguageModel middleware that edits the prompt. On the OpenAI client it means wrapping completions.create by hand.

How hard is the upgrade from AI SDK 6 to 7?

The 7.0 migration guide lists 2 requirements up front. v7 requires Node.js 22 or later, and its packages are ESM only. Codemods exist for many renames; expect some by hand.

The ESM change is the one that cost us time. In our internal tools app, moving to ai@7 broke 4 Knowledge Base test suites that never call a model, because Jest transforms nothing under node_modules and a static import of an ESM-only package made the module unparseable. We now import ai dynamically inside the shared function that builds the Gateway provider for model calls, so a suite pays for it only if it reaches that line. On monogram.io, a shared package of pure constants and types with no runtime dependencies lets the site and the agent import the same model slugs while each upgrades on its own schedule.

How does the AI SDK relate to eve and AI Gateway?

The AI SDK is the call layer. AI Gateway is the routing and billing layer underneath it, and eve is an agent runtime above it. Our assistant uses all 3. eve runs the conversation, and the retrieval code beside it calls the AI SDK, which sends each request through the Gateway. You can use the AI SDK with neither.

When not to use the AI SDK

  • You want batteries included. If you need dozens of document loaders and vector store adapters on day one, LangChain ships more of them.
  • You need durable agents. The SDK's tool loop runs in memory. Sessions that survive a deploy, approvals that can wait days for a person and schedules come from a runtime above it; we use eve for that.
  • You cannot absorb major versions. The SDK ships majors regularly, and an upgrade can touch test tooling as well as call sites.
  • You need a provider feature before the SDK supports it. Calling the provider's SDK directly gets you there first.

FAQ

Is the AI SDK free?

Yes. It is open source, and you pay only for the model calls.

Does the AI SDK work with Claude, GPT and Gemini?

Yes. Through one Gateway provider our assistant runs Claude Haiku 4.5 with GPT-5 mini and Gemini 2.5 Flash configured as fallbacks, plus OpenAI embeddings and Cohere reranking.

Do I need AI Gateway to use the AI SDK?

No. Install a provider package and pass its model instead. We use the Gateway for fallbacks and spend reporting.

Can I use the AI SDK and LangChain together?

Yes, and a bridge package exists for it. We chose to remove LangChain so every embedding went through the Gateway with the same model and dimensions.

Can Monogram help us build on the AI SDK?

Yes. See our agentic AI services, the M8 case study, our LangChain and Vercel pages, or contact us.

Further reading: AI SDK docs, AI SDK 7.0 migration guide, rerank reference, language model middleware.