MemoryLake
Engineering & Developercross-session context for ChatGPT API

Add Cross-Session Context to Every ChatGPT API Call

The ChatGPT API is stateless. Every call starts blank unless you stuff context into the system prompt — which inflates tokens, bloats latency, and still loses fidelity. MemoryLake adds a cross-session memory layer to the ChatGPT API, so each call retrieves only the context that matters.

Day 1“MemoryLake adds a cross-session memory layer to the ChatGPT”“API, so each call retrieves only the context that matters.”✓ Got it, I will remember.Day 7 — new session“Same task again — can you keep the context?”× Sure — what was the context again?(forgot every detail you taught it)+ MEMORYLAKE LAYERMemory auto-loadedPer-user persistent memoryCompact retrieval beats stuffed promptsSix memory types instead of one bufferSESSION OUTPUT✓ Same prompt, on-brand answerNo re-briefing required.

Add Cross-Session Context to Every ChatGPT API Call

Get Started Free

Free forever · No credit card required

The problem: the ChatGPT API forgets between every request

Without a memory layer, every API call ships either zero context or a massive system prompt that re-explains the user from scratch. Teams burn tokens, latency, and money trying to fake persistence. The real answer is a memory store the API can query — not a longer prompt.

How MemoryLake solves cross-session context for the ChatGPT API

Per-user persistent memory

Per-user persistent memory

Each user has their own memory namespace. The API retrieves only their relevant prior facts, events, and conversations.

MEMORYCompact retrieval beats s…

Compact retrieval beats stuffed prompts

Pull a 500-token memory block instead of 50,000-token chat history. Same recall, 100x cheaper.

MEMORYSix memory types instead of one buffer

Six memory types instead of one buffer

Conversation, facts, events, reflections, skills, and background memory each retrieve with their own logic.

Cross-model portability

Cross-model portability

When you switch from GPT-4o to a future model — or to Claude or Gemini — user memory follows them. Zero migration cost.

Get Started Free

Free forever · No credit card required

How it works for the ChatGPT API

  1. Connect — Pipe each user turn and assistant response into MemoryLake via SDK or REST.
  2. Structure — MemoryLake classifies, dedupes, and stores each turn with user metadata.
  3. Reuse — Before every API call, retrieve a ranked, token-budgeted memory block. Prepend it as system context.

Before vs. after: ChatGPT API context handling

Without MemoryLakeWith MemoryLake
Returning user requestEmpty system promptPersonalized memory injected
Token usage for context30k+ per call<2k per call
Latency from huge promptsSlow first tokenCompact context, fast response
Switching to GPT-5 or ClaudeMigrate everythingMemory follows the user

Who this is for

Product teams building on the OpenAI API — copilots, assistants, vertical SaaS — who want users to feel remembered without paying the token tax for stuffed system prompts.

Runnable demoabout 3 minutes

Try this use case on your own account

The chat API starts blank on every call, so an app built on it either sends no context or pastes the user's history into every prompt. Here a tutor app keeps its call and adds one flag: each learner's boundary, a saved scope over their own project and actor. MemoryRouter attaches the memories that matter for the message, and the demo measures the reply, the prompt tokens and what leaks.

What you will see

  • Two learners (Japanese and German), three past sessions each, stored as conversations; one project, one actor and one boundary per learner (boundary create --projects … --human-actor …)
  • The same message through memorylake router chat three ways: no boundary mentions 0 of 30 learner details over 5 runs; each learner's boundary brings their own (keigo, Osaka, dative, football) and never the other's (0 of 15 leaks)
  • The token bill: Mina's three pasted sessions cost 767 prompt tokens, her boundary 286 to 399. Off-topic messages still got some memory attached in 3 of 5 runs; the demo prints that too
  • The same boundary through router messages --model claude-haiku-4-5, and tonight's session piped in like every other one: the next call moves from N4 to N3 (5/5), while "drop the romaji" lost to an older pinned preference once (4/5). Plus ask and a local web UI

You need: a MemoryLake API key · the memorylake CLI · Python 3.9+

Run it

git clone https://github.com/memorylake-ai/memorylake-usecases.git
cd memorylake-usecases/chatgpt-api-memory
export MEMORYLAKE_API_KEY=sk-…
python3 demo.py          # or: python3 web/server.py

Watch it run · real, unedited recordings

Related use cases

Frequently asked questions

How is this different from OpenAI's built-in memory feature?

OpenAI's memory is product-specific to ChatGPT, opaque, and not portable. MemoryLake is developer-controlled, structured, exportable, and works with any model.

Does it support streaming responses?

Yes. Retrieval happens before the streaming call. The memory block is just part of your system prompt.

What's the latency impact?

Single-digit millisecond retrieval. Negligible next to model latency.