API Reference
REST API for storing memories, retrieving context, and debugging agent decisions. All endpoints accept API key auth via X-API-Key header.
Base URL
Authentication
API Key (mg_*) via header or SDK. Dashboard uses JWT tokens.
Store Memory
Two ways to store: beliefs (immediate, searchable) or events (async pipeline processing).
| Method | Path | Description | Auth |
|---|---|---|---|
| POST | /v1/beliefs | Create a belief — immediately searchable with vector embedding | API Key |
| POST | /v1/beliefs/batch | Batch create up to 100 beliefs at once | API Key |
| POST | /v1/events | Log an event — processed async via Events → Episodes → Beliefs pipeline | API Key |
| POST | /v1/ingest | Ingest text or file (PDF, TXT) — auto-extracts beliefs | API Key |
| POST | /v1/documents | Store a document with embedding for knowledge base | API Key |
| POST | /v1/documents/upload | Upload a file (PDF, TXT, Markdown) | API Key |
| POST | /v1/documents/link | Scrape and ingest a URL | API Key |
# Store a belief (immediate)
curl -X POST https://api.memgraph.ai/v1/beliefs \
-H "X-API-Key: mg_your_key" \
-H "Content-Type: application/json" \
-d '{
"subject_id": "alice",
"key": "deployment_preference",
"value": "Prefers Kubernetes over Docker Compose",
"confidence": 0.95,
"belief_type": "preference",
"domain": "infrastructure"
}'Retrieve Context
Get relevant memories for your agent's prompt. v2/context is the recommended endpoint — it includes entities, decisions, and graph data alongside beliefs.
| Method | Path | Description | Auth |
|---|---|---|---|
| POST | /v2/context | Full context retrieval — beliefs + entities + decisions + graph (recommended) | API Key |
| POST | /v1/context | Basic context retrieval — beliefs + episodes only | API Key |
# Retrieve context (recommended — v2)
curl -X POST https://api.memgraph.ai/v2/context \
-H "X-API-Key: mg_your_key" \
-H "Content-Type: application/json" \
-d '{
"query": "What deployment strategy does Alice prefer?",
"user_id": "alice",
"agent_id": "support-bot",
"include_decisions": true,
"include_graph": true
}'
# Response includes:
# - results[] — scored beliefs and memories
# - entities[] — related entities
# - decisions[] — relevant past decisions
# - graph — entity relationship dataManage Beliefs
| Method | Path | Description | Auth |
|---|---|---|---|
| GET | /v1/beliefs | List beliefs with pagination (?subject_id, ?domain, ?limit, ?cursor) | API Key |
| GET | /v1/beliefs/{subject_id} | Get all beliefs for a user/subject | API Key |
| PUT | /v1/beliefs/{belief_id} | Update a belief (value, confidence, type, domain) | API Key |
| DELETE | /v1/beliefs/{belief_id} | Delete a specific belief | API Key |
| DELETE | /v1/beliefs | Bulk delete by subject + domain (soft or hard) | API Key |
| GET | /v1/beliefs/history/{subject_id}/{key} | Version history for a specific belief key | API Key |
| GET | /v1/beliefs/timeline/{subject_id} | Chronological timeline of all belief changes | API Key |
Cognitive Sidecar
Auto-recall context before LLM calls and auto-learn from exchanges. See the Sidecar guide for SDK usage.
| Method | Path | Description | Auth |
|---|---|---|---|
| POST | /v1/sidecar/pre-flight | Get memory context to inject before your LLM call | API Key |
| POST | /v1/sidecar/post-flight | Extract and store learnings from a message exchange | API Key |
| POST | /v1/sidecar/process | Combined pre-flight + post-flight in one call | API Key |
# Pre-flight: inject memory into your prompt
curl -X POST https://api.memgraph.ai/v1/sidecar/pre-flight \
-H "X-API-Key: mg_your_key" \
-H "Content-Type: application/json" \
-d '{
"user_id": "alice",
"agent_id": "support-bot",
"message": "How should I deploy to production?",
"token_budget": 4000
}'
# Post-flight: learn from the exchange
curl -X POST https://api.memgraph.ai/v1/sidecar/post-flight \
-H "X-API-Key: mg_your_key" \
-H "Content-Type: application/json" \
-d '{
"user_id": "alice",
"agent_id": "support-bot",
"messages": [
{"role": "user", "content": "I prefer Kubernetes"},
{"role": "assistant", "content": "Noted, will recommend K8s"}
]
}'Decisions
Record, inspect, and debug agent reasoning traces. See the Decisions guide for patterns.
| Method | Path | Description | Auth |
|---|---|---|---|
| POST | /v2/decisions | Record a decision with goal, reasoning steps, tools, and outcome | API Key |
| POST | /v2/decisions/synthesize | Auto-extract a decision from a message exchange | API Key |
| GET | /v2/decisions/{id} | Get a decision by ID | API Key |
| GET | /v2/decisions/{id}/explain | Full debug view — beliefs, context snapshot, entity graph | API Key |
| GET | /v2/decisions | List decisions (?agent_id, ?user_id, ?outcome, ?limit) | API Key |
| PATCH | /v2/decisions/{id}/outcome | Record outcome — auto-adjusts belief confidence (LTP/LTD) | API Key |
| POST | /v2/outcomes/record | Platform-friendly outcome recording | API Key |
Entities & Graph
Knowledge graph with named entities and temporal relationships.
| Method | Path | Description | Auth |
|---|---|---|---|
| POST | /v2/entities | Create entity (person, org, product, place, concept, system, project) | API Key |
| GET | /v2/entities | List entities (?entity_type, ?limit) | API Key |
| POST | /v2/entities/search | Fuzzy + semantic entity search | API Key |
| DELETE | /v2/entities/{id} | Delete entity and its relationships | API Key |
| POST | /v2/relationships | Create relationship between entities (with temporal validity) | API Key |
| GET | /v2/relationships | List relationships (?entity_id, ?relation_type) | API Key |
| POST | /v2/graph/traverse | Traverse entity graph from seed nodes (max_depth, temporal_filter) | API Key |
Memory Quality
Monitor memory health, detect contradictions, and track agent reliability.
| Method | Path | Description | Auth |
|---|---|---|---|
| GET | /v1/intelligence/health | Memory health — confidence stats, staleness, contradiction rate | API Key |
| GET | /v1/intelligence/contradictions | Contradiction report with resolution history | API Key |
| GET | /v1/intelligence/mcis | Memgraph Cognitive Integrity Score (0-100 composite) | API Key |
| POST | /v1/intelligence/evaluate | Score a retrieval query — detailed breakdown of all 5 signals | API Key |
| GET | /v2/contradictions | List contradictions (?status=active) | API Key |
| PATCH | /v2/contradictions/{id} | Resolve or dismiss a contradiction | API Key |
| GET | /v2/trust-score/{agent_id} | Agent trust score — accuracy and track record | API Key |
| GET | /v2/analytics | Decision analytics — success rate, outcome distribution | API Key |
Account & Keys
| Method | Path | Description | Auth |
|---|---|---|---|
| POST | /v1/auth/onboard | Create account + tenant + API key in one call | Public |
| POST | /v1/auth/login | Login and get JWT token | Public |
| GET | /v1/auth/me | Get current user profile | JWT |
| GET | /v1/auth/whoami | Resolve identity from API key or JWT | Key/JWT |
| POST | /v1/api-keys | Create new API key | JWT |
| GET | /v1/api-keys | List API keys (prefix only) | JWT |
| DELETE | /v1/api-keys/{key_id} | Revoke an API key | JWT |
| GET | /health | Health check (DB + cache status) | Public |
Self-Hosting Endpoints
Additional endpoints useful when running your own instance.
| Method | Path | Description | Auth |
|---|---|---|---|
| POST | /v1/dreaming/trigger | Manually trigger belief consolidation for pending episodes | API Key |
| GET | /v1/dreaming/health | Check if the background dreaming worker is running | API Key |
| GET | /v1/admin/export | Export all tenant data as JSON (GDPR-compliant) | Admin |
| POST | /v1/admin/import | Import beliefs and events from JSON backup | Admin |
| GET | /metrics | Prometheus metrics endpoint | Public |
Full Example: Store + Retrieve + Decide
# 1. Store a memory
curl -X POST https://api.memgraph.ai/v1/beliefs \
-H "X-API-Key: mg_your_key" \
-H "Content-Type: application/json" \
-d '{
"subject_id": "alice",
"key": "deployment_preference",
"value": "Prefers Kubernetes for production workloads",
"confidence": 0.95,
"belief_type": "preference"
}'
# 2. Retrieve context for your agent
curl -X POST https://api.memgraph.ai/v2/context \
-H "X-API-Key: mg_your_key" \
-H "Content-Type: application/json" \
-d '{
"query": "What deployment method does Alice prefer?",
"user_id": "alice",
"include_decisions": true
}'
# 3. Record a decision
curl -X POST https://api.memgraph.ai/v2/decisions \
-H "X-API-Key: mg_your_key" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "support-bot",
"user_id": "alice",
"goal": "Recommend deployment strategy",
"confidence": 0.85,
"outcome": "SUCCESS"
}'Error Codes
| Code | Meaning | What to do |
|---|---|---|
| 400 | Bad request | Check required fields and data types |
| 401 | Unauthorized | Check your API key or JWT token |
| 404 | Not found | Resource doesn't exist or wrong tenant |
| 429 | Rate limited | Wait and retry (120 req/min per tenant) |
| 500 | Server error | Retry with backoff, check /health |
All errors return { "detail": "error message" }. The SDK auto-retries on 429 and 5xx with exponential backoff.
Interactive docs: FastAPI auto-generates OpenAPI docs at /docs on your server (e.g., http://localhost:8001/docs) — useful for exploring all endpoints including internal ones.
