Integrations
Five ways to wire Brain into a stack — Next.js, FastAPI, LangChain, the OpenAI Responses API, or the first-party MCP server — and the one question that decides which.
Start here
Next.jsin-depth guideThe App Router, end to end — the runtime constraint that decides where
your code can run, identity from the session, recall in a Server
Component, writes in Server Actions and after().
Read it.
FastAPIin-depth guideA Python service, end to end — choosing between the sync HTTP tier and the async wire tier, why the wrong choice blocks your event loop, and the pooled-key multi-tenancy only this tier can do. Read it.
These two are the full treatments, and they are complementary: the Next.js guide ends at the point where a serverless runtime cannot hold a connection, and the FastAPI guide picks up exactly there.
What ships, and what you write
@brain-db/mcpfirst-party packageA published MCP server exposing 49 tools over stdio or remote Streamable HTTP. Install it; you do not write it. See Brain over MCP.
LangChainglue you writeNo first-party package. Brain is the long-term half of LangChain's memory model — a store, a retriever or agent tools, never the checkpointer. Three wirings and the trade-offs.
OpenAIglue you writeNo first-party package. Two function tools on the Responses API and a dispatch loop. The Assistants API it used to describe was sunset in August 2026 — the current pattern is here.
Choosing
The real question is who decides when memory is touched — the model, or your code.
The last row is the one worth sitting with. With MCP, a memory that never gets written looks identical to a conversation where there was nothing to write. If what you are storing matters, an explicit call site you can test is the safer shape — and nothing stops you doing both.
They are not exclusive
A common production shape is MCP for the agent's reads and explicit SDK calls for its writes: the model can ask what is known whenever it likes, and your code decides what is worth remembering. That keeps the useful autonomy and removes the failure mode above.
The tier question, once
Every guide here runs into the same fork, so it is worth stating plainly in one place. Brain has two client tiers, and which one you can use is usually decided for you by where your code runs.
That last row causes more confusion than it should: a verdict comparison written for one tier silently never matches on the other. It is called out again in both guides, at the point where it bites.
Was this page helpful?
Manual rate-limit backoff
Catch a 429 / 503, honor Retry-After, and retry — taking over from the SDK's built-in auto-retry when you need to.
Next.js
Brain in a Next.js App Router app — where the client lives, why the Edge runtime cannot load it, identity from the session, recall in a Server Component, writes in Server Actions and after(), and streaming the change feed.