Contexara API

Add persistent memory to any AI agent with a single API call. Contexara handles storage, retrieval, and context assembly. You just ingest and retrieve.

Simple integration
One endpoint to store context, one to retrieve it. Works with any LLM.
Namespace isolation
Every user gets a fully isolated memory partition. No cross-contamination.
LLM agnostic
Works with OpenAI, Anthropic, Gemini, or any local model. No vendor lock-in.
Always up to date
Memory updates automatically as conversations evolve. No manual management.

Quickstart

Get memory running in your agent in under 5 minutes.

1. Get your API key

Sign up at contexara.com and copy your API key from the dashboard.

2. Install the SDK

pip install contexara

3. Add memory to your agent

from contexara import ContextaraClient
mem = ContextaraClient(api_key="YOUR_API_KEY", namespace="user-123")
# After each conversation turn
mem.ingest(
user_text="I prefer dark mode and I use VSCode.",
assistant_text="Got it, I'll keep that in mind."
)
# Before each LLM call, get a memory-enhanced system prompt
system_prompt = mem.build_system_prompt(
agent_instructions="You are a helpful assistant.",
query="what editor does the user prefer?"
)
# Pass system_prompt to your LLM as usual

Full example with OpenAI

from contexara import ContextaraClient
from openai import OpenAI
mem = ContextaraClient(api_key="YOUR_API_KEY", namespace="user-123")
openai = OpenAI()
def chat(user_message: str) -> str:
# Build memory-enhanced system prompt
system = mem.build_system_prompt(
agent_instructions="You are a personal assistant.",
query=user_message
)
response = openai.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": system},
{"role": "user", "content": user_message},
]
)
assistant_reply = response.choices[0].message.content
# Ingest the turn into memory
mem.ingest(user_text=user_message, assistant_text=assistant_reply)
return assistant_reply

SDK Reference

ContextaraClient(api_key, namespace, user_name?)

Creates a namespace-scoped memory client.

Parameter
Type
Description
api_key
str
Your Contexara API key.
namespace
str
Unique ID per user or agent. Memory is fully isolated per namespace.
user_name
str
Optional. Used for personalized responses.
POST.ingest(user_text, assistant_text)

Store a conversation turn. Call this after every exchange.

mem.ingest(
user_text="I just moved to London.",
assistant_text="How are you finding it?"
)
GET.build_system_prompt(agent_instructions, query)

Retrieve relevant memory and compile it into a ready-to-use system prompt. Pass the result directly to your LLM.

system = mem.build_system_prompt(
agent_instructions="You are a helpful assistant.",
query="what city does the user live in?"
)
# Returns a string. Use as your LLM system message
POST.store(content, kind?, importance?)

Explicitly store a memory fact. Useful for seeding memory from structured data without going through a conversation.

mem.store(
content="User is allergic to peanuts.",
kind="constraint",
importance=5
)
GET.search(query, top_k?)

Search stored memories by meaning. Returns ranked results.

results = mem.search("food preferences", top_k=5)
# [{"id": "...", "content": "...", "kind": "preference", "score": 0.87}, ...]
GET.stats()

Returns memory statistics and a quality score for the namespace.

stats = mem.stats()
# {
# "memories": 42,
# "topics": 8,
# "tokens_total": 18400,
# "quality_score": 78.4
# }

REST API

All SDK methods map to REST endpoints. Authenticate with your API key.

Authorization: Bearer YOUR_API_KEY
Method
Endpoint
Description
POST
/v1/ingest
Store a conversation turn
POST
/v1/store
Explicitly store a memory fact
GET
/v1/context
Get a memory-enhanced system prompt
GET
/v1/search
Search memories by meaning
GET
/v1/memories
List stored memories
GET
/v1/stats
Namespace memory statistics

Example: Store a turn

curl -X POST https://api.contexara.com/v1/ingest \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"namespace": "user-123",
"user_text": "I prefer working late nights.",
"assistant_text": "Noted, night owl schedule."
}'

Example: Get context

curl "https://api.contexara.com/v1/context?namespace=user-123&query=work+schedule" \
-H "Authorization: Bearer YOUR_API_KEY"
Questions or need help? Reach out at howdy@contexara.com