MemorySyncMemorySync
Getting Started

Your First Memory

This page walks through the real /memory/add contract: the required headers, accepted body fields, the route's server-side mutations, and the response shapes you can actually receive.

The request

BASH
curl -X POST https://api.memorysync.io/memory/add \
  -H "X-API-Key: $MEMORYSYNC_API_KEY" \
  -H "X-Project-ID: $MEMORYSYNC_PROJECT_ID" \
  -H "X-End-User-ID: demo-user-001" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "User prefers dark mode and concise responses.",
    "source": "chat",
    "metadata": {"conversation_id": "conv-123"},
    "deduplicate": true
  }'

Header contract

HeaderRequiredVerified behaviour
X-API-Keyyes for service authResolved before the memory handler runs.
Authorization: Bearer ...alternativeJWT-authenticated callers act as the end user directly.
X-Project-IDusually yesGlobally enforced for project-scoped routes unless the API key already supplies project_id.
X-End-User-IDyes for service-auth memory callsResolves to the corresponding user. Ignored for dashboard JWT callers.

Body fields the schema accepts

FieldMeaningVerified note
textCanonical memory bodyRequired unless you send content. After trimming, text must be at least 10 characters.
contentAlias for textNormalized into text by the schema.
sourceOrigin labelOptional field on the request body.
event_typeTrigger labelOptional field on the request body.
tagsSemantic tagsOptional field on the request body.
ttl_minutesRetention hintOptional integer >= 1.
importanceManual importance hintOptional float from 0.0 to 1.0.
metadataArbitrary JSONOptional and preserved in the response.
deduplicateDuplicate handling flagDefaults to true.
user_id and project_idDeprecated body fieldsIgnored or overwritten by server-side auth and request state.

What the route handler does

  1. Runs authentication, scope checks, and add-quota enforcement before processing the payload.
  2. If the org is over its add quota, silently returns {"status":"ok"} without storing anything.
  3. Resolves the effective end user. Service-auth callers must supply X-End-User-ID or end_user_id in the body.
  4. Overwrites client-supplied user_id, environment, and project_id with trusted request context.
  5. Runs the memory through the extraction pipeline before storing it.
  6. If a record was stored, emits the memory-created webhook and returns the first stored MemoryResponse.

Response cases

CaseHTTPBody shape
Stored successfully201MemoryResponse.
Silent quota skip200{"status":"ok"}.
Extraction skip200{"status":"skipped","reason":...,"candidates_extracted":...}.
Missing project400{"code":"PROJECT_ID_REQUIRED",...}.
Missing end user400{"error":{"code":"MISSING_END_USER_ID",...}}.
Bad input422Structured validation error payload.

Query the same user back

BASH
curl -X POST https://api.memorysync.io/memory/query \
  -H "X-API-Key: $MEMORYSYNC_API_KEY" \
  -H "X-Project-ID: $MEMORYSYNC_PROJECT_ID" \
  -H "X-End-User-ID: demo-user-001" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "What response style does this user prefer?",
    "k": 5
  }'

Common first-time snags

  • Sending project_id in the JSON body and expecting it to win. The handler overwrites it from request state.
  • Using an API key without X-End-User-ID. Shared-key memory requests are rejected without an end-user identifier.
  • Sending fewer than 10 non-whitespace characters. The schema rejects it before the deeper service logic runs.
  • Assuming add always returns 201. Silent quota mode and extraction skips both return 200 with different body shapes.