Skip to content

API

The xmemory REST API is what the Python and TypeScript SDKs call under the hood. You can also call it directly with curl, fetch, or any HTTP client.

For MCP-based access (no HTTP calls needed), see the MCP guide.

All endpoints live under https://api.xmemory.ai, accept JSON, and return JSON. Every request except /healthz requires a Bearer token in the Authorization header.

Please register your interest at https://xmemory.ai and we will reach out to give access. When you receive your API key, copy and securely store the key. Never share your API key publicly.


Write something, then read it back — two curl calls:

Terminal window
# Write
curl -X POST https://api.xmemory.ai/write \
-H "Authorization: Bearer $XMEM_AUTH_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"instance_id": "your-instance-id",
"text": "Alice Johnson works at Acme Corp. Her email is alice@acme.com.",
"extraction_logic": "deep"
}'
# Read
curl -X POST https://api.xmemory.ai/read \
-H "Authorization: Bearer $XMEM_AUTH_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"instance_id": "your-instance-id",
"query": "What is Alice's email?"
}'
# → {"status": "ok", "reader_result": {"answer": "alice@acme.com"}, ...}

The rest of this page covers every endpoint in detail.


Before you can write or read, you need an instance — a memory store with a typed schema.

Generate an xmemory schema from a plain-language description:

{
"schema_description": "Track contacts with name, email, company, and notes."
}

Returns { "status": "ok", "generated_schema": { ... } }.

To refine an existing schema, pass current_yml_schema — existing objects and fields are preserved and only the described changes are applied.

Create an instance from a generated schema. Pass either yml_schema or json_schema:

{ "yml_schema": "..." }

Returns { "status": "ok", "instance_id": "inst_abc123" }.

Save the instance_id — you’ll pass it with every subsequent call.

Update the schema of an existing instance:

{
"instance_id": "inst_abc123",
"yml_schema": "..."
}

Returns { "status": "ok" }.


Extract structured objects from text and persist them. Blocks until committed.

{
"instance_id": "inst_abc123",
"text": "Bob Lee is a designer at Globex. He joined last Monday.",
"extraction_logic": "deep"
}
FieldRequiredDescription
instance_idyesInstance to write to
textyesFree-form text to extract from
extraction_logicno"deep" (default), "regular", or "fast"

Returns:

{
"status": "ok",
"extract_write_id": "ew_...",
"cleaned_objects": { ... },
"diff_plan": { ... }
}

cleaned_objects contains the stored objects. diff_plan shows what was inserted, updated, or deleted.

Same extraction pipeline, but returns immediately instead of blocking:

{
"instance_id": "inst_abc123",
"text": "Carol is a senior engineer at Initech.",
"extraction_logic": "deep"
}

Returns { "status": "ok", "write_id": "wq_..." }.

Important: do not read immediately after an async write — the data may not be committed yet. Poll with /write_status first.

Check whether an async write has finished:

{ "write_id": "wq_..." }

Returns:

{
"status": "ok",
"write_id": "wq_...",
"write_status": "completed",
"error_detail": null,
"completed_at": "2025-03-16T12:34:56Z"
}

write_status is one of: queued, processing, completed, failed, not_found.


Query the instance in natural language:

{
"instance_id": "inst_abc123",
"query": "Who joined the team recently?",
"mode": "single-answer"
}
FieldRequiredDescription
instance_idyesInstance to query
queryyesNatural-language question
modeno"single-answer" (default), "xresponse", or "raw-tables"

The response shape depends on the mode:

Modereader_resultBest for
single-answer{"answer": "Bob Lee joined last Monday."}Natural-language answers
xresponse{"objects": [...], "relations": [...]}Structured data
raw-tables{"tables": [...]}Raw SQL results

Extract structured objects from text without storing them — useful for previewing what a write would produce:

{
"instance_id": "inst_abc123",
"text": "Dave manages the London office.",
"extraction_logic": "deep"
}

Returns { "status": "ok", "objects_extracted": { ... } }.

Same parameters as /write.


Returns 200 if the API is reachable. No authentication required.

Terminal window
curl https://api.xmemory.ai/healthz

All endpoints return { "status": "error", "error_message": "..." } on failure with the appropriate HTTP status code (400, 401, 404, 500).


EndpointMethodAuthDescription
/healthzGETHealth check
/instance/generate_schemaPOSTYesGenerate a schema from a description
/instance/createPOSTYesCreate a new instance
/instance/updatePOSTYesUpdate an instance’s schema
/writePOSTYesWrite (synchronous)
/write_asyncPOSTYesWrite (async, returns write_id)
/write_statusPOSTYesPoll async write status
/readPOSTYesQuery the instance
/extractPOSTYesExtract without writing