zenmem LLM SDK (Python)
A minimal SDK for building AI features with memory. Start a session, call an LLM, and let it remember things — at whatever scope makes sense: this conversation, this project, or the whole company.
pip install zenmem
pip install "zenmem[all]" # + openai, anthropic, google-generativeai
from zenmem import ZenmemClient, ZenmemConfig
client = ZenmemClient(ZenmemConfig(
endpoint="http://203.0.113.10:6636", # your zenmem deployment — IP:port
accessToken="<your token>",
companyCode="WPCORP4812",
))
sessionId = client.startSession()
result = client.callLLM(
rawPrompt="What should I learn next?",
provider="OPENAI", model="gpt-4o-mini",
scope="session", sessionId=sessionId,
passMemory=True, saveInMemory=True,
)
print(result.output)
client.endSession(sessionId)
That callLLM pulled relevant memory into context, called the model, and
wrote a summary of the exchange back — one call.
Requires Python 3.11+. Provider keys come from ZenmemConfig fields or the
matching environment variable: OPENAI_API_KEY, ANTHROPIC_API_KEY,
GOOGLE_API_KEY, DEEPSEEK_API_KEY.
endpoint is required — one host:port for everything the SDK talks to.
There is no default; every client must say explicitly which deployment it's
pointed at.
The basics
Everything in this SDK is one of four things:
client.startSession() / client.endSession(id) |
begin/end a conversation |
client.callLLM(...) |
call a model, optionally with memory in and out |
client.addMemory(text, scope=...) |
remember something |
client.fetchMemory(query, scope=...) |
recall something |
Scope
Every memory-touching call takes a scope:
| scope | meaning |
|---|---|
"session" |
this conversation only — requires sessionId |
"project" |
shared across everything running under your configured project |
"company" |
shared company-wide, no project partition |
client.addMemory("the user prefers Python", scope="session", sessionId=sessionId)
client.addMemory("our support hours are 9-5 ET", scope="company")
memory = client.fetchMemory("what does the user prefer?", scope="session", sessionId=sessionId)
memory.memoryText # plain-text block, ready for an LLM prompt
memory.dataNodes # [DataNode(id, text, score, metadata), ...]
scope="project" reads/writes are partitioned by ZenmemConfig.companyProjectCode,
so several projects can share one account without seeing each other's memory.
Pass projectId="OTHER_PROJECT" to target a different project for one call.
callLLM
result = client.callLLM(
rawPrompt="...", # or promptId="PROMPT-XXXX"
provider="OPENAI", model="gpt-4o-mini", # not needed with promptId
inputParams={"question": "..."},
scope="session", sessionId=sessionId,
passMemory=True, # inject memory from `scope` as context
saveInMemory=True, # write a summary of this exchange back
)
result.output, result.summary, result.inputTokens, result.outputTokens
Memory retrieval and summarization are non-fatal — if they fail, the model call still goes through without that context.
Sessions
sessionId = client.startSession() # or startSession("my-own-id")
client.addMemory("...", scope="session", sessionId=sessionId)
client.callLLM(rawPrompt="...", provider="OPENAI", model="gpt-4o-mini",
scope="session", sessionId=sessionId, passMemory=True)
client.endSession(sessionId) # promotes its memory to longterm
A closed session id cannot be reused — always start a fresh one for a new conversation.
Module-level API
For scripts that only need one client:
import zenmem
zenmem.init(config)
sessionId = zenmem.startSession()
zenmem.addMemory("...", scope="session", sessionId=sessionId)
zenmem.callLLM(rawPrompt="...", provider="OPENAI", model="gpt-4o-mini")
Errors
All SDK errors derive from ZenmemError, so one except catches everything:
| Exception | Raised when |
|---|---|
ZenmemConfigError |
Missing token, key, or an invalid scope. |
ZenmemApiError |
A backend call failed (carries statusCode, responseBody). |
ProviderError |
The LLM provider call failed. |
Renamed from VMI
This library was previously vmi-llm-sdk. Nothing breaks on upgrade — the
old names are still exported as aliases to the same objects.
| Old | New |
|---|---|
pip install vmi-llm-sdk |
pip install zenmem |
import llm_sdk |
import zenmem (both work) |
VmiClient / VmiConfig / VmiTransaction |
ZenmemClient / ZenmemConfig / ZenmemTransaction |
VmiError / VmiConfigError / VmiApiError |
ZenmemError / ZenmemConfigError / ZenmemApiError |
VMI_* env vars |
ZENMEM_* (old names read as a fallback) |
Full documentation
The complete reference installs with the package:
import zenmem
print(zenmem.docs_path())
| Page | Contents |
|---|---|
docs/configuration.md |
Every ZenmemConfig field |
docs/memory.md |
addMemory / fetchMemory reference |
docs/llm-calls.md |
callLLM parameters and pipeline |
docs/scoping.md |
session / project / company memory |
docs/sessions.md |
Session lifecycle |
docs/transactions.md |
Grouping several writes into one commit/rollback |
docs/models.md |
Typed results and exception hierarchy |
License
MIT. The full text ships in the package as LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zenmem-0.4.4.tar.gz.
File metadata
- Download URL: zenmem-0.4.4.tar.gz
- Upload date:
- Size: 80.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
684cff6c192acb5dea7c8aab2b15149c14734f3fec694a7ec3fb7e18f90b257c
|
|
| MD5 |
f7b085e2718957a5a29253ae7a448c00
|
|
| BLAKE2b-256 |
c6eb1fba64a0aec7df8708ff2038e0c3c490e8f6a44cb91a94ad8bbe58dbbf42
|
File details
Details for the file zenmem-0.4.4-py3-none-any.whl.
File metadata
- Download URL: zenmem-0.4.4-py3-none-any.whl
- Upload date:
- Size: 68.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
166a14f727930357d302cbb40e7fb0be489c58c0f19e50f36f6ee4947463f318
|
|
| MD5 |
a19e52aadb5f0f58587e13241b7c037a
|
|
| BLAKE2b-256 |
b7d554d2d33af9fee0976e52cb437390ef0b24cbd8972b752aaee91ca48a317d
|