Model or dataset
langchain-ai/langchain-nextjs-template avatar
langchain-ai/langchain-nextjs-template

langchain-nextjs-template: a LangChain.js + Next.js starter with five worked examples

LangChain + Next.js starter template

2,532 stars563 forksTypeScriptMIT

At a glance

What is it?
The template ships five separate API routes covering chat, structured output, agents, and two RAG variants, all streaming through Vercel's AI SDK. It is a reference implementation to fork, not a package to install.
Who is it for?
Fork it if you want a working Next.js App Router project where chat, structured output, a LangGraph agent and two retrieval variants already stream tokens to the client, and you plan to replace the demo pages with your own. Do not adopt it if you need a published npm package, a stable API surface, or a non-Next.js frontend: this is a repository to clone, and its version is 0.0.0 with private set to true.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 11 days ago.
What is it written in?
Mainly TypeScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 20, 2026, and from our analysis. They are not legal advice.

Editorial analysis

What the template actually gives you, and who it is for

This repository is a scaffold, not a library. Its package.json declares "private": true and a version of 0.0.0, which tells you the intended workflow: clone or use the Deploy with Vercel button, then edit in place. Nothing is published for you to depend on.

The README lists five use cases, each with its own route file: simple chat, structured output, agents, retrieval with a chain, and retrieval with an agent. That is the real value. Instead of reading separate documentation pages and guessing how the pieces fit, you get five working endpoints in one Next.js App Router project, sharing a UI and a streaming layer.

The audience is narrow but well served: a developer who already knows Next.js and wants to see LangChain.js wired into route handlers with token streaming, without assembling the plumbing first. If you have never written a Next.js route handler, the template will not teach you that, and the README assumes it.

How the routes, the AI SDK and LangGraph fit together

The architecture is flat and readable. Backend logic lives under app/api/chat/, with one route per example. The README points at app/api/chat/route.ts as the place to change the prompt and model, and at app/page.tsx as the page you edit first.

The README states that most examples use Vercel's AI SDK to stream tokens to the client and render incoming messages. The agents are different: they use LangGraph.js, described in the README as LangChain's framework for building agentic workflows, with preconfigured helper functions to cut boilerplate. The README also says you can replace those helpers with custom graphs.

The structured output route takes a third approach. According to the README, it builds a schema with Zod, formats it the way OpenAI expects, passes it as a function, and sets a function_call parameter to force arguments into that shape. That is a concrete mechanism, and it is the one route where the model is constrained rather than merely prompted.

Retrieval sits behind a small local adapter, utils/supabase-vector-store.ts, built on @supabase/supabase-js and @langchain/core. The README says it reuses an existing documents table and a match_documents function, so no database migration is needed. Swapping vector stores means editing three files: app/api/retrieval/ingest/route.ts and the two chat retrieval routes.

Installing and getting a first streamed answer

There is no install command for the template itself. You clone the repository, and the README says to copy .env.example to .env.local, then add an OpenAI API key for the basic examples. The .env.example file also carries LANGCHAIN_CALLBACKS_BACKGROUND=false as an active line, which the README ties to serverless Edge functions and LangSmith tracing.

bash
cp .env.example .env.local
yarn dev

After yarn dev, open http://localhost:3000 in a browser. The README says you can ask the bot something and watch a streamed response arrive. The page reloads as you edit app/page.tsx.

The agent example needs one more key. Set TAVILY_API_KEY in .env.local for web search, and note the README's detail that the calculator tool accepts two numbers and an arithmetic operation rather than evaluating arbitrary expressions, so it will not run a free-form expression you paste in.

The retrieval examples need Supabase. The README refers to the LangChain.js Supabase vector store instructions for database setup, then asks you to put the database URL and private key into .env.local as SUPABASE_URL and SUPABASE_PRIVATE_KEY. The ingest route is where documents are split, embedded and uploaded. One warning from the README is worth repeating: pressing Upload a second time re-ingests the docs and creates duplicates, and you clear the store by running DELETE FROM documents; in the Supabase console.

There are also regression tests that need no keys or live database, run with Node.js 22.6 or later:

bash
node --experimental-strip-types --test utils/integrations.test.mjs

Where the template stops being the right tool

The retrieval routes are bound to Supabase. The README frames the adapter as swappable, but swapping means editing three route files and reimplementing the vector store interface yourself. If your organization runs pgvector directly, or Pinecone, or anything else, you are doing integration work the template does not do for you.

The demo content is also demo content. The README says the default document text is pulled from the LangChain.js retrieval use case docs. That text is there to make the example work, not to model a real corpus, and the ingest route gives no guidance on chunking strategy for documents of different shapes.

The structured output route depends on OpenAI function calling. The README describes the mechanism in those terms, so pointing it at a different provider is not a configuration change.

Finally, the project has no releases. The releases list is empty, and package.json still reads 0.0.0. Treat it as a snapshot of a pattern rather than a dependency with a changelog. The last push to the repository was on 2026-09-18, which is recent, but recency of commits is not the same thing as a versioning policy.

The real alternative: assembling the same stack yourself

The honest alternative is not another template. It is starting from create-next-app and adding @langchain/core, @langchain/openai, the AI SDK and LangGraph.js on your own terms, writing only the routes you need.

That path costs more upfront and buys control. You pick the vector store from the beginning instead of editing three files later. You decide whether structured output goes through OpenAI function calling or something provider-neutral. You avoid inheriting a UI built from Radix primitives, Tailwind and a component set you may not want, since the template's dependency list includes @radix-ui packages, tailwindcss and components.json.

The template's counter-argument is time. Five route files that already stream correctly, plus an ingest route and a Supabase adapter, is a lot of plumbing to reproduce from documentation alone. If your goal is to evaluate LangChain.js patterns rather than ship a bespoke architecture, forking is faster. If your goal is a production system with a chosen vector store and a chosen model provider, you will end up rewriting more of the template than you keep.

Licence, maintenance signals and what an upgrade costs

The repository is MIT licensed, which permits commercial use, modification and redistribution provided the copyright notice and permission notice are retained. That is the standard permissive arrangement, and it imposes no copyleft obligation on your own code. This is a description of the licence text, not legal advice; if you are redistributing the template inside a product, have your own counsel read the LICENSE file.

On maintenance, the facts are limited. The repository is not archived, and the last push was on 2026-09-18. There is no version history to diff against and no upgrade path documented in the README. Upgrading means reading the dependency diff in package.json and testing your own routes.

That diff will not be trivial. The dependency list pins major versions across several fast-moving packages: @langchain/core at ^1.2.8, @langchain/langgraph at ^1.4.10, ai at ^7.0.66, next at ^16.3.4, react at ^19.3.0 and zod at ^3.25.76. The engines field requires Node.js 22 or later, and the package manager is pinned to [email protected]. Any one of those majors moving can change an API you rely on, and the template gives you no migration notes. Budget for reading upstream changelogs yourself.

The README does address one cost directly. It states that for the RAG use case LangChain occupies 37.32 KB of code space after compression and chunk splitting, as of @langchain/core 0.1.15, which it puts at under 4 percent of the 1 MB Vercel free tier edge function allotment. Note the version: that measurement is from an older core release than the one package.json pins. You can check your own numbers, because @next/bundle-analyzer is configured, and the README gives the command:

bash
ANALYZE=true yarn build

Editorial conclusion

Fork it if you want a working Next.js App Router project where chat, structured output, a LangGraph agent and two retrieval variants already stream tokens to the client, and you plan to replace the demo pages with your own. Do not adopt it if you need a published npm package, a stable API surface, or a non-Next.js frontend: this is a repository to clone, and its version is 0.0.0 with private set to true. Before you commit, verify three things in the repository: that app/api/chat/route.ts holds the prompt and model you intend to keep, that your vector store is reachable, because the retrieval routes are hardwired to Supabase through utils/supabase-vector-store.ts, and that LANGCHAIN_CALLBACKS_BACKGROUND is set to false in .env.local, since the README ties that setting to serverless Edge functions and LangSmith tracing.

Frequently asked questions

Do I install langchain-nextjs-template as a package?

No. The repository is a template to clone or deploy, and package.json marks it private with version 0.0.0. You fork it and edit the files in place.

Which API keys does langchain-nextjs-template need?

The basic examples need an OpenAI API key. The agent example additionally needs TAVILY_API_KEY, and the retrieval examples need SUPABASE_URL and SUPABASE_PRIVATE_KEY. LangSmith tracing keys are optional.

Why does langchain-nextjs-template set LANGCHAIN_CALLBACKS_BACKGROUND to false?

The README explains that the app is made to run in serverless Edge functions, and that setting the variable to false ensures tracing finishes when LangSmith tracing is in use. It appears as an active line in .env.example.

Can I use a vector store other than Supabase with langchain-nextjs-template?

The README says you can swap in another supported vector store by changing the code under app/api/retrieval/ingest/route.ts and the two retrieval chat routes. The bundled adapter in utils/supabase-vector-store.ts is Supabase-specific.

Official sources

  1. Issues
  2. langchain-ai/langchain-nextjs-template on GitHub
  3. License: MIT
  4. Project website
  5. README
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/langchain-ai-langchain-nextjs-template.svg)](https://hysenlabs.com/projects/langchain-ai-langchain-nextjs-template)