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.
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 ContextaraClientmem = ContextaraClient(api_key="YOUR_API_KEY", namespace="user-123")# After each conversation turnmem.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 promptsystem_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 ContextaraClientfrom openai import OpenAImem = ContextaraClient(api_key="YOUR_API_KEY", namespace="user-123")openai = OpenAI()def chat(user_message: str) -> str:# Build memory-enhanced system promptsystem = 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 memorymem.ingest(user_text=user_message, assistant_text=assistant_reply)return assistant_reply
SDK Reference
Creates a namespace-scoped memory client.
api_keynamespaceuser_nameStore a conversation turn. Call this after every exchange.
mem.ingest(user_text="I just moved to London.",assistant_text="How are you finding it?")
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
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)
Search stored memories by meaning. Returns ranked results.
results = mem.search("food preferences", top_k=5)# [{"id": "...", "content": "...", "kind": "preference", "score": 0.87}, ...]
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
/v1/ingest/v1/store/v1/context/v1/search/v1/memories/v1/statsExample: 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"