Installation
Usage: Creating a Context-Aware API Route
A common use case is to create an API endpoint that your frontend can call. This endpoint will securely fetch context from Jean Memory and then stream a response from your chosen LLM. The example below shows how to create a Next.js API route that is compatible with edge runtimes and the Vercel AI SDK.- Extract Data: It pulls the latest user message and, most importantly, the
userToken
from the incoming request. This token, acquired by your frontend via OAuth, authorizes access to the user’s memory. - Fetch Context: It calls
jean.getContext()
, passing theuserToken
and the user’s message to the Jean Memory engine. The engine returns a block of relevant, engineered context. - Construct Prompt: It assembles a final prompt, injecting the context from Jean Memory before the user’s actual question. This enriches the LLM’s understanding.
- Stream Response: It calls the LLM (in this case, OpenAI) with the context-rich prompt and streams the response back to the frontend using the Vercel AI SDK’s
StreamingTextResponse
. This provides a responsive, real-time chat experience.
Authentication Flow
As with the Python SDK, theuserToken
is obtained by your frontend application through a secure OAuth 2.1 flow using our @jeanmemory/react
SDK. Your frontend makes an authenticated request to this API route, including the userToken
in the request body. See the Authentication guide for more details.
Test User Support: The Node.js SDK v2.0.7+ automatically creates test users for development:
Speed Modes
Jean Memory provides four distinct speed modes to balance response time with context depth:- fast: Ideal for real-time applications requiring sub-second responses
- balanced: Recommended for most conversational AI use cases with natural language synthesis
- autonomous: Best for complex tasks requiring intelligent decision-making
- comprehensive: Use for research and detailed analysis tasks
Additional Configuration
For advanced use cases, you can configure additional options:Advanced: Direct Tool Access
For advanced use cases, theJeanClient
also provides a tools
namespace for direct, deterministic access to the core memory functions.
Performance Expectations
Different operations have different timing characteristics:tools.search_memory()
: 1-2 seconds - Fast semantic search, returns JSONgetContext()
(orchestration): 3-10 seconds - Full AI conversation with contexttools.deep_memory_query()
: 5-15 seconds - Comprehensive cross-memory analysistools.store_document()
: Immediate response + background processing (30-60 seconds total)