Skip to content

Use the API

Every call goes to https://api.metaphorlabs.io/v1, sends JSON, and carries your API key as a bearer token. The API reference lists every route and field, and Errors, limits and retries covers what goes wrong.

The examples read your key from METAPHOR_API_KEY. Make one in the console under API keys, as in the Quickstart.

Each call names a space in its path. Use personal, your own space: it’s the one served today. A key you make in the console acts for you, so it needs nothing else.

Another space ID answers 404 not-found.

POST /v1/spaces/personal/memories needs the Write access (memories:write).

Terminal window
curl https://api.metaphorlabs.io/v1/spaces/personal/memories \
-H "Authorization: Bearer $METAPHOR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"content": "The billing service retries failed charges three times.",
"source": { "name": "api", "id": "decision-118" }
}'
{ "id": "4f1c9a7e2b8d06c3a5e9f17b20d4c8e6", "status": "accepted" }
  • content: up to 32,000 characters. It is never written to a log.
  • source.name: where it came from, such as api or slack. Lowercase letters, digits and hyphens, up to 32.
  • source.id: the item’s ID there, 1 to 256 visible ASCII characters. Use the source’s own ID, never a title, a sentence or a name: a hash of it stays after the memory is erased.

The answer comes once the memory is kept, before it’s ready for recall. To wait for it, read it by its id (GET /v1/spaces/personal/memories/{id}) until the answer is 200:

  • 404 not-ready: it’s kept and not yet ready. Read again in a second or two.
  • 404 not-saved: it could not be saved, and is not kept. Send it again.

A space keeps up to 1,000 memories, or 8 MiB, that are not yet ready. Past that a write is 429 inbox-full, and nothing is kept: send it again after the seconds in Retry-After. The memory’s id is made from its source, so the same source and content sent again changes nothing. The same source with other content is 409 conflict: replacing a memory isn’t served yet. So is a source whose memory was forgotten past undoing.

Leave out occurred_at, agent and source.url, or send them as null. They aren’t kept yet, so a value is refused with 400 invalid-request. Leave out audience too: a memory in your space is seen by you alone.

GET /v1/spaces/personal/memories lists your memories, newest first. It needs Read (memories:read).

Terminal window
curl "https://api.metaphorlabs.io/v1/spaces/personal/memories?limit=20" \
-H "Authorization: Bearer $METAPHOR_API_KEY"

It answers { "data": [...], "next": ... }. Send next back as after for the next page. It’s null on the last.

GET /v1/spaces/personal/memories/{memory_id} reads one. Its status is stored today. It doesn’t yet say whether the memory is ready for recall.

POST /v1/spaces/personal/recall needs Read (memories:read).

Terminal window
curl https://api.metaphorlabs.io/v1/spaces/personal/recall \
-H "Authorization: Bearer $METAPHOR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "question": "How many times does billing retry a charge?", "budget": 1000 }'
{
"items": [
{
"text": "The billing service retries failed charges three times.",
"heading": null,
"occurred_at": null,
"memory_ids": ["4f1c9a7e2b8d06c3a5e9f17b20d4c8e6"]
}
]
}
  • question: up to 4,000 characters, in the user’s words. It is never written to a log.
  • budget: the most tokens the lines may take together, 100 to 10,000. 2,000 when left out.

The lines come in the order they’re best read. items is empty when nothing in the space answers.

POST /v1/spaces/personal/forget needs Forget (memories:forget). Name the memories by ID, or one item by its source:

Terminal window
curl https://api.metaphorlabs.io/v1/spaces/personal/forget \
-H "Authorization: Bearer $METAPHOR_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: forget-order-notes-1" \
-d '{ "memory_ids": ["4f1c9a7e2b8d06c3a5e9f17b20d4c8e6"] }'

Or, by source: -d '{ "source": { "name": "api", "id": "decision-118" } }'.

{
"id": "b7e04c2a9d3f18e6c5a0f29d4b81e7c3",
"state": "open",
"undo_until": "2027-01-31T09:30:00Z",
"erased_at": null
}
  • What it names leaves recall at once, with everything made from it. The same fact in another memory stays until that one is forgotten too.
  • It answers the same whether or not anything matched.
  • Idempotency-Key is optional: 1 to 255 visible ASCII characters, such as a UUID. Send the same key to retry a forget whose answer was lost, and you get the first forget back. Without one, a retry makes a second forget, and only the first can undo what was taken.
  • memory_ids takes 1 to 100 IDs.
  • A space holds at most 5,000 forgets open at once. Past that, a forget changes nothing and answers 429 open-forgets with frees_at. Undoing a forget frees a place.
  • A space makes at most 200 forgets an hour. Past that, a forget changes nothing and answers 429 rate-limited, with Retry-After set to the seconds left in the hour. Undoing a forget doesn’t give its place in the hour back.

Forgetting in words (what) and by author aren’t served yet. They answer 400 invalid-request.

GET /v1/spaces/personal/forgets/{forget_id} answers where a forget stands. state is one of:

  • open: gone from recall. It can be undone until undo_until.
  • undone: brought back.
  • closed: the undo window has closed and nothing of it can be read.
  • erased: every key that could open a copy of it is destroyed too.

POST /v1/spaces/personal/forgets/{forget_id}/undo brings back what that forget took, while its window is open. Only the user who asked for the forget can undo it.

Terminal window
curl -X POST https://api.metaphorlabs.io/v1/spaces/personal/forgets/b7e04c2a9d3f18e6c5a0f29d4b81e7c3/undo \
-H "Authorization: Bearer $METAPHOR_API_KEY"

It answers with the forget, now undone. After the window closes it changes nothing and answers where the forget stands.