> For the complete documentation index, see [llms.txt](https://docs.gitloom.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gitloom.cloud/api-reference/memories.md). Agents can also search and read this documentation through its [MCP server](https://docs.gitloom.cloud/~gitbook/mcp).

# Memories

Write memories, retrieve them, read one by path, delete them, and navigate the tree.

#### POST /v1/memories

Send a **conversation** (`messages`) and a model extracts the atomic facts worth keeping, writes retrieval cues for each, links related facts, and reconciles anything that restates a memory already stored. Or send **memories you have already formed** (`memories`), and they are stored as given. One or the other, not both.

{% hint style="warning" %}
**Asynchronous.** The response is `202`; the memory does not exist yet, and there is no endpoint to poll for completion. See [Why hasn't my memory shown up?](https://docs.gitloom.cloud/help-center/why-hasnt-my-memory-shown-up)
{% endhint %}

| field         | type                       | required       | notes                                                                                  |
| ------------- | -------------------------- | -------------- | -------------------------------------------------------------------------------------- |
| `messages`    | array of `{role, content}` | one of the two | a conversation to extract memories from; `role` is `user` or `assistant`               |
| `memories`    | array of memories          | one of the two | memories already formed, stored as given — see below                                   |
| `namespace`   | string                     | no             | defaults to `default`                                                                  |
| `session_id`  | string                     | no             | your id for the conversation; identical bodies within 5 minutes dedupe                 |
| `tags`        | array of strings           | no             | your tags, put on every memory drawn from the conversation                             |
| `occurred_at` | string or number           | no             | when the conversation happened, not now; omitted means now                             |
| `timezone`    | string                     | no             | IANA zone, such as `Asia/Kolkata`, for an `occurred_at` without an offset; default UTC |
| `date`        | string                     | no             | the older name for `occurred_at`, still accepted                                       |

**`occurred_at`** takes epoch seconds or milliseconds, RFC 3339 with an offset, or a date or datetime without one, read in `timezone`. A date alone is that calendar day wherever you are. On a conversation it dates the conversation, so a backfill of last year's transcripts does not claim everything happened today; each memory drawn from it is then dated by the event it describes when it names one, and by this otherwise.

**Tags** are kept apart from the ones GitLoom infers, and come back as `user_tags`: never capped, and no merge drops them. A tag is trimmed and lowercased; it is letters, digits, spaces and `- _ . : / # @`, at most 64 characters, and a memory takes up to 32.

Each entry in `memories`:

| field         | required | notes                                                                                                                   |
| ------------- | -------- | ----------------------------------------------------------------------------------------------------------------------- |
| `path`        | yes      | repo-relative, under a tier, ending in `.md`, such as `facts/home/lease.md`                                             |
| `content`     | yes      | the memory's body                                                                                                       |
| `tags`        | no       | your tags, as on a conversation                                                                                         |
| `occurred_at` | no       | when what the memory describes happened, in the forms above, read in the request's `timezone`; `date` is its older name |
| `confidence`  | no       | `[0, 1]`                                                                                                                |
| `ttl`         | no       | incidents only, such as `30d`                                                                                           |
| `supersedes`  | no       | the path of a memory this one replaces                                                                                  |
| `cues`        | no       | retrieval cues: the questions someone would ask to find this memory                                                     |
| `related`     | no       | paths of related memories, optionally labelled: `spouse: facts/people/maya.md`                                          |

A request carries up to 500 memories, or a conversation of up to 200 turns and 200,000 characters, in at most 256KB. The free plan accepts a conversation of up to 20,000 characters.

{% tabs %}
{% tab title="A conversation" %}

```bash
curl -s -X POST "$GITLOOM_API/v1/memories" \
  -H "Authorization: Bearer $GITLOOM_KEY" \
  -H "content-type: application/json" \
  -d '{"namespace":"user-8213","session_id":"chat-1",
    "occurred_at":"2026-07-31","timezone":"Asia/Kolkata","tags":["purchase"],
    "messages":[
      {"role":"user","content":"I bought a Sony A7III today."},
      {"role":"assistant","content":"Nice pick."}]}'
```

{% endtab %}

{% tab title="Memories already formed" %}

```bash
curl -s -X POST "$GITLOOM_API/v1/memories" \
  -H "Authorization: Bearer $GITLOOM_KEY" \
  -H "content-type: application/json" \
  -d '{"namespace":"user-8213","memories":[
    {"path":"facts/home/lease.md","content":"Signed the lease for the Indiranagar flat.",
     "tags":["home","lease"],"occurred_at":"2026-03-05","confidence":0.9}]}'
```

{% endtab %}
{% endtabs %}

```json
{"id":"3f2b9e01-7c44-4d1a-9f6e-0a1b2c3d4e5f","namespace":"user-8213","status":"accepted"}
```

`id` is a queue message id, not a memory id — no endpoint accepts it back.

| status | code                                                                                                                                                                                                                               |
| ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `400`  | `no_content` (neither `messages` nor `memories`), `ambiguous_write` (both), `invalid_tag`, `invalid_date`, `invalid_timezone`, `invalid_path`, `empty_memory`, `invalid_id`, `invalid_branch`, `invalid_namespace`, `invalid_body` |
| `404`  | `namespace_not_found`                                                                                                                                                                                                              |
| `413`  | `too_many_memories`, `too_many_turns`, `session_too_long`, `payload_too_large`, `write_too_large` (past the free plan's limit)                                                                                                     |
| `429`  | `quota_exceeded`, `rate_limited` (with `Retry-After`)                                                                                                                                                                              |
| `402`  | `balance_exhausted`                                                                                                                                                                                                                |

A refused tag or time names its field, such as `invalid_tag memories[1].tags[0]` or `invalid_date occurred_at`, and nothing is queued.

#### GET /v1/retrieve

Runs lexical (BM25), semantic (cue and body vectors) and graph (one-hop relations) search concurrently, and fuses them by **calibrated score**. The only model call is the query embedding — unless you ask for one with `mode`.

Every result is one **memory**, never a fragment. A memory whose sections matched separately is still one entry, with the matching sections named in `sections`, and `content` is the whole body — so for most questions nothing else needs fetching.

| param             | required | default        | notes                                                                                                                                                                     |
| ----------------- | -------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `q`               | no       | —              | the question, verbatim. Required unless a filter is given — see Filters without a question, below                                                                         |
| `namespace`       | no       | `default`      |                                                                                                                                                                           |
| `mode`            | no       | `raw`          | `raw`, `summary`, `agentic` — see below                                                                                                                                   |
| `limit`           | no       | `24`           | capped at 200                                                                                                                                                             |
| `tiers`           | no       | all            | comma-separated: `facts`, `incidents`, `rules`, `skills`                                                                                                                  |
| `paths`           | no       | all            | comma-separated directories, e.g. `facts/events,incidents`                                                                                                                |
| `tags`            | no       | —              | memories carrying **any** of these tags                                                                                                                                   |
| `tags_all`        | no       | —              | memories carrying **every** one of these tags                                                                                                                             |
| `since` / `until` | no       | —              | bound `time_field`: epoch seconds or milliseconds, RFC 3339, or a date or datetime read in `tz`; a date alone in `until` includes that whole day                          |
| `time_field`      | no       | `updated`      | the time `since` and `until` bound, and what a listing without `q` is ordered by: `occurred` (when the subject happened), `created` or `updated`                          |
| `tz`              | no       | UTC            | IANA zone, such as `Asia/Kolkata`, or a fixed offset, such as `+05:30`, for `since`/`until` without an offset and for `time_format=iso`; `timezone` is the same parameter |
| `time_format`     | no       | `epoch`        | how each memory's `created_at`, `updated_at`, `occurred_at` and `expires_at` are written: `epoch` (unix seconds) or `iso` (RFC 3339 in `tz`)                              |
| `min_score`       | no       | `0`            | drop memories scoring below this                                                                                                                                          |
| `context`         | no       | `1`            | `0` drops graph neighbours, leaving only direct matches                                                                                                                   |
| `detail`          | no       | `compact`      | `full` adds revision history, the last diff, relation snippets and cues                                                                                                   |
| `include_expired` | no       | `0`            | include TTL-expired incidents                                                                                                                                             |
| `rank`            | no       | —              | `fused` or `jev`: retrieve on the lane path, below. Not with `mode=agentic`                                                                                               |
| `max_chars`       | no       | `0`            | the most characters of memory content the response carries, 300 to 200,000; `0` keeps every memory whole                                                                  |
| `model`           | no       | the mode's own | `haiku` or `sonnet`: the model that reads the memories in `mode=summary` or `agentic`; refused with `mode=raw`                                                            |

Tags match in any case. URL-encode every parameter — a raw `#` ends the query string, so send `%23` — and a tag filter that arrives empty is refused rather than ignored.

{% hint style="info" %}
**Filters apply inside every arm**, and to graph neighbours. `paths=facts/commitments` is a boundary, not a cut made after the fact: nothing outside it can arrive as a neighbour either.
{% endhint %}

```bash
curl -s -G "$GITLOOM_API/v1/retrieve" \
  -H "Authorization: Bearer $GITLOOM_KEY" \
  --data-urlencode "q=why did we leave Postgres" \
  --data-urlencode "namespace=user-8213" \
  --data-urlencode "tiers=facts,incidents"
```

```json
{
  "tenant": "acme", "namespace": "user-8213",
  "query": "why did we leave Postgres", "mode": "raw",
  "memories": [{
    "path": "facts/ghmev/ghmev-migrated-off-postgres.md",
    "tier": "facts", "topic": "facts/ghmev",
    "title": "Ghmev moved off Postgres",
    "content": "[2026-08-04] Ghmev moved off Postgres because connection limits capped concurrency …",
    "snippet": "[2026-08-04] Ghmev moved off [Postgres] because …",
    "score": 0.94,
    "matched": ["lexical", "cue", "body"],
    "sections": ["what-replaced-it"],
    "tags": ["migration", "database", "infrastructure"],
    "user_tags": ["migration"],
    "created_at": 1785833774,
    "updated_at": 1786011160,
    "occurred_at": 1785844800,
    "occurred_source": "extracted",
    "occurred_precision": "day",
    "created": "2026-08-04T08:56:14Z",
    "updated": "2026-08-06T10:12:40Z",
    "scores": { "bm25": 3.35, "cue": 0.68, "body": 0.57, "coverage": 1 },
    "related": [
      { "label": "replaced-by", "path": "facts/ghmev/moved-to-dynamo.md" },
      { "label": "caused-by", "path": "incidents/ghmev/postgres-connection-limit-hit.md" }
    ],
    "provenance": { "commit": "865754b9…", "when": "2026-08-06T10:12:40Z", "revisions": 2 }
  }, {
    "path": "incidents/ghmev/postgres-connection-limit-hit.md",
    "tier": "incidents", "topic": "incidents/ghmev",
    "title": "Postgres hit its connection limit under launch load",
    "content": "[2026-08-01] Postgres hit its connection limit under launch load; requests queued for 40 seconds.",
    "score": 0.29,
    "matched": ["graph"],
    "via": ["facts/ghmev/ghmev-migrated-off-postgres.md"],
    "tags": ["database", "outage"],
    "user_tags": [],
    "created_at": 1785583800,
    "updated_at": 1785583800,
    "occurred_at": 1785585600,
    "occurred_source": "extracted",
    "occurred_precision": "day",
    "expires_at": 1793361600,
    "created": "2026-08-01T11:30:00Z",
    "updated": "2026-08-01T11:30:00Z",
    "scores": { "graph_hops": 1 }
  }],
  "candidates": 6, "filtered_out": 4,
  "millis": 118,
  "timings": { "lexical_ms": 6, "vector_ms": 103, "graph_ms": 4 },
  "cold_start": false
}
```

**`score` is a calibrated relevance in `[0, 1]`, comparable across queries.** A memory that answers the question outright scores near 1 whatever else the namespace holds. That is a change from the fused rank this route used to return, which was an artefact of position and meant nothing on its own. A listing without `q` scores every memory `1`.

**`matched` says which arms produced the memory** — `lexical`, `cue`, `body`, `graph`, and `time` on the lane path. A memory matched only by `graph` is *context* that rode in beside a real match rather than evidence: `via` names what pulled it in, and it scores a fraction of that memory. `scores.coverage` is the fraction of the query's content terms the memory actually contains.

**`filtered_out` with an empty `memories`** means the question was asked of a namespace holding nothing relevant. Retrieval abstained rather than returning the least-bad memories, which is the distinction that makes "I don't know" answerable.

**Times are unix seconds**; `time_format=iso` writes them as RFC 3339 in `tz` instead. `created_at` and `updated_at` are the author times of the commits that added the memory's file and last changed it; `updated_at` is absent on a conversation turn. `occurred_at` is when the memory's subject happened, and `occurred_source` says how that is known: `user` (you said), `extracted` (the memory names the day), `said` (when its conversation happened) or `written`. `occurred_precision` is `day` when only the date is known — held as noon UTC on that date, so show it as a date — or `instant`. `expires_at` appears on a memory with a TTL. `created` and `updated` (RFC 3339) remain for now and are **deprecated** in favour of `created_at` and `updated_at`.

**`user_tags`** is your tags alone, lowercased and sorted rather than in the order you sent them: `["Lease", "home"]` comes back as `["home", "lease"]`. `tags` lists those first, then the ones GitLoom inferred, each group sorted.

#### Filters without a question

Leave out `q` and give at least one filter — `tags`, `tags_all`, `since`/`until`, `tiers` or `paths` — to list every memory the filters match, newest first by `time_field`, up to `limit`. Each scores `1`; nothing is ranked or dropped. `mode` must be `raw`, and `rank` does not apply.

```bash
curl -s -G "$GITLOOM_API/v1/retrieve" \
  -H "Authorization: Bearer $GITLOOM_KEY" \
  --data-urlencode "namespace=user-8213" \
  --data-urlencode "tags=lease" \
  --data-urlencode "time_field=occurred" \
  --data-urlencode "since=2026-03-01"
```

With a question, the default path keeps only memories that are evidence for it, so a vague `q` inside a filter can return fewer than the filter matches; ask a specific question, use `rank=fused`, or leave `q` out. Conversation turns have no `occurred` time and are never updated, so an `occurred` or `updated` range leaves them out.

#### The lane path

`rank` retrieves differently. Five lanes — lexical, cue, body, graph and time — each search on their own, over the curated memories and, when the namespace keeps conversation turns and no `tiers`, `paths` or `tags` narrow the query, over those turns too. The time lane reads dates in the question ("last month", "in May") against when each memory was said. `rank=fused` merges the lanes by score; `rank=jev` has a ranking model order everything they found, and answers in lane order with `rank_fallback: true` when it cannot. Each memory then says which `store` it came from (`memory`, or a word-for-word conversation `turn`) and the days it was `said`. `rank=jev` is metered as a chat.

A memory that does not fit `max_chars` is cut to its opening sentence and the sentences matching the question, and marked `excerpted`.

| you want                           | use                                                                                                    |
| ---------------------------------- | ------------------------------------------------------------------------------------------------------ |
| memories for an agent's own prompt | `mode=raw&rank=fused`, with `max_chars` set to the room you have                                       |
| an answer from GitLoom             | `mode=summary&rank=jev`; add `model=sonnet` when answers combine several memories or reason over dates |
| a model that searches on its own   | `mode=agentic`, which takes no `rank`                                                                  |

#### Answering modes

`mode` decides whether a model runs on the read path. `raw` is the default and makes no model call beyond the query embedding.

{% tabs %}
{% tab title="raw" %}
Ranked memories, no model. Single-digit milliseconds plus the query embedding. Metered as a **read**.
{% endtab %}

{% tab title="summary" %}
The same retrieval, then one call to a fast model that writes an `answer` from it. The memories it used come back beneath. Metered as a **chat**.

```json
{
  "mode": "summary",
  "answer": "You moved off Postgres on 2026-08-04 because connection limits capped concurrency [1].",
  "model": "global.anthropic.claude-haiku-4-5-20251001-v1:0",
  "memories": [ "… the evidence the answer was built from …" ],
  "timings": { "lexical_ms": 6, "vector_ms": 103, "graph_ms": 4, "model_ms": 1090 }
}
```

{% endtab %}

{% tab title="agentic" %}
A stronger model searches the memory itself — search, read, list the tree, follow relations, look up an entity or a defined term — and answers when it has enough. Returns its `trace`. Bounded to roughly 24 seconds so it fits inside the gateway's limit; `truncated: true` means it hit that budget before choosing to stop. Metered as a **chat**.

```json
{
  "mode": "agentic",
  "answer": "You moved off Postgres on 2026-08-04 (facts/ghmev/ghmev-migrated-off-postgres.md).",
  "model": "global.anthropic.claude-sonnet-4-6",
  "truncated": false,
  "trace": [
    {"type": "tool_use", "tool": "search_memory", "id": "tu_01", "input": {"query": "postgres migration"}},
    {"type": "tool_result", "tool": "search_memory", "id": "tu_01", "result": {"memories": ["…"]}},
    {"type": "text", "text": "You moved off Postgres on 2026-08-04 …"}
  ]
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Every memory carries its evidence, on every surface.** `scores` says why it surfaced, `provenance` is its git history, `related` holds its outgoing edges with enough of each neighbour to decide whether to follow it. A `defined` list accompanies `memories` when the query mentions a term the namespace's [vocabulary](https://docs.gitloom.cloud/api-reference/vocabulary.md) defines. `detail=full` adds revision history, the last diff and relation snippets. This is the same shape the [TypeScript SDK](https://docs.gitloom.cloud/documentation/typescript)'s `recall()` returns.
{% endhint %}

{% hint style="warning" %}
`memories` is `[]` when nothing matched — never absent. Errors carry the same envelope as every other route's; a missing or refused credential is the gateway's bare `401` or `403` — see the [Overview](https://docs.gitloom.cloud/api-reference/overview.md).
{% endhint %}

| status | code                                                                                                                                                                                                                                                                                                                                                                                                   |
| ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `400`  | `missing_query` (no `q` and no filter, or no `q` outside `mode=raw`), `invalid_tier`, `invalid_path`, `invalid_tag`, `invalid_mode`, `invalid_detail`, `invalid_min_score`, `invalid_date` (also `since` after `until`), `invalid_time_field`, `invalid_timezone`, `invalid_time_format`, `invalid_rank`, `invalid_max_chars`, `invalid_model`, `rank_conflict`, `model_conflict`, `invalid_namespace` |
| `404`  | `namespace_not_found`                                                                                                                                                                                                                                                                                                                                                                                  |
| `429`  | `rate_limited`, with a `Retry-After` header: the whole seconds until the request is admitted again. `quota_exceeded` has none; a monthly allowance resets on the first of the next month at 00:00 UTC                                                                                                                                                                                                  |
| `402`  | `balance_exhausted` — the plan's allowance is spent and the wallet cannot cover the overage; recharge and retry                                                                                                                                                                                                                                                                                        |
| `502`  | `model_failed` — a `summary` or `agentic` run produced nothing; retry with `mode=raw`                                                                                                                                                                                                                                                                                                                  |
| `503`  | `model_unavailable` — the answering model is not configured                                                                                                                                                                                                                                                                                                                                            |

#### GET /v1/memories

Reads what a retrieval hit names: a file, or one of its sections as `file.md#section`. For a file, `content` is the whole body without its frontmatter, and its tags and times come back as fields beside it, built the same way a retrieval builds them. Meters as a read.

| param         | required | default   | notes                                                                                                          |
| ------------- | -------- | --------- | -------------------------------------------------------------------------------------------------------------- |
| `path`        | yes      | —         | a repo-relative file path, or `file.md#section`. URL-encode it: a raw `#` ends the query string, so send `%23` |
| `namespace`   | no       | `default` |                                                                                                                |
| `time_format` | no       | `epoch`   | `epoch` (unix seconds) or `iso` (RFC 3339 in `tz`)                                                             |
| `tz`          | no       | UTC       | the zone `time_format=iso` renders in; `timezone` is the same parameter                                        |

```bash
curl -s -G "$GITLOOM_API/v1/memories" \
  -H "Authorization: Bearer $GITLOOM_KEY" \
  --data-urlencode "namespace=user-8213" \
  --data-urlencode "path=facts/home/lease.md"
```

```json
{
  "namespace": "user-8213",
  "path": "facts/home/lease.md",
  "title": "Signed the lease for the Indiranagar flat",
  "tier": "facts", "kind": "file",
  "content": "Signed the lease for the Indiranagar flat.",
  "tags": ["home", "lease"], "user_tags": ["home", "lease"],
  "confidence": 0.9,
  "created_at": 1785662042, "updated_at": 1785662042,
  "occurred_at": 1772712000, "occurred_source": "user", "occurred_precision": "day",
  "created": "2026-08-02T09:14:02Z", "updated": "2026-08-02T09:14:02Z",
  "millis": 3
}
```

The tags, `confidence`, `related`, `cues` and the created, updated and occurred times belong to a file, so a section or a directory carries none of them; a section of a memory with a TTL carries its `expires_at`. `created` and `updated` are deprecated here too.

| status | code                                                                                                                         |
| ------ | ---------------------------------------------------------------------------------------------------------------------------- |
| `400`  | `missing_path`, `invalid_time_format`, `invalid_timezone`, `invalid_namespace`                                               |
| `403`  | `forbidden_namespace` — the key is scoped to another namespace                                                               |
| `404`  | `namespace_not_found`, or `not_found` when nothing is at `path` — a forgotten memory or a stale retrieval hit, not a failure |
| `429`  | `quota_exceeded`, `rate_limited` (with `Retry-After`)                                                                        |
| `402`  | `balance_exhausted`                                                                                                          |

#### DELETE /v1/memories

Removes memories from the namespace, and so from retrieval. Earlier revisions stay in the repository's git history.

{% hint style="warning" %}
**Asynchronous**, like every write. The deletion is queued behind the namespace's other writes and lands in seconds; until then the memories are still there.
{% endhint %}

Paths travel in the query string, so the request needs no body.

| param       | required | default   | notes                                                                  |
| ----------- | -------- | --------- | ---------------------------------------------------------------------- |
| `path`      | yes      | —         | the paths to delete, comma-separated; a repeated `path` reads the same |
| `namespace` | no       | `default` |                                                                        |

```bash
curl -s -X DELETE -G "$GITLOOM_API/v1/memories" \
  -H "Authorization: Bearer $GITLOOM_KEY" \
  --data-urlencode "namespace=user-8213" \
  --data-urlencode "path=facts/home/old-lease.md"
```

```json
{"id":"3f2b9e01-7c44-4d1a-9f6e-0a1b2c3d4e5f","namespace":"user-8213","paths":["facts/home/old-lease.md"],"status":"accepted"}
```

| status | code                                                                                                                                                                   |
| ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `400`  | `missing_path`; `invalid_path` (a path that is not printable text, or is over 1024 bytes); `invalid_namespace`, which a key scoped to another namespace also gets here |
| `404`  | `namespace_not_found`                                                                                                                                                  |

#### GET /v1/tree

The table of contents: tier, topic directory, file, and each file's `##` sections, with a summary where one exists. An agent can descend it to orient itself instead of guessing at the words a search would need. Bounded by default, because an unbounded tree of a large namespace is a second copy of the repository. Meters as a read.

| param       | required | default          | notes                                                 |
| ----------- | -------- | ---------------- | ----------------------------------------------------- |
| `path`      | no       | the whole memory | roots the tree, e.g. `facts`                          |
| `depth`     | no       | `2`              | levels to descend; below 1 is read as 2, above 8 as 8 |
| `namespace` | no       | `default`        |                                                       |

```bash
curl -s -G "$GITLOOM_API/v1/tree" -H "Authorization: Bearer $GITLOOM_KEY" \
  --data-urlencode "namespace=user-8213" --data-urlencode "path=facts" --data-urlencode "depth=1"
```

```json
{
  "namespace": "user-8213", "depth": 1,
  "tree": {
    "path": "facts", "kind": "dir", "tier": "facts",
    "children": [{ "path": "facts/home", "kind": "dir", "tier": "facts" }]
  },
  "millis": 4
}
```

Each node has a `path`, and where they apply a `title`, `kind` (`dir`, `file` or `section`), `tier` and `summary`. `children` is absent below the requested depth, and on a leaf.

| status | code                                                  |
| ------ | ----------------------------------------------------- |
| `400`  | `invalid_namespace`                                   |
| `403`  | `forbidden_namespace`                                 |
| `404`  | `namespace_not_found`                                 |
| `429`  | `quota_exceeded`, `rate_limited` (with `Retry-After`) |
| `402`  | `balance_exhausted`                                   |

#### GET /v1/topics

Topic directories and how many memories each holds. Nothing imposes a taxonomy, so a writer can invent `facts/databases` beside an existing `facts/database` and split one subject in two; listing the topics first is how a writer avoids that. Meters as a read.

| param       | required | default   | notes                                            |
| ----------- | -------- | --------- | ------------------------------------------------ |
| `tier`      | no       | all       | `facts`, `incidents`, `rules` or `skills`        |
| `prefix`    | no       | —         | only topics under this path, e.g. `facts/home`   |
| `like`      | no       | —         | a case-insensitive substring of the topic's name |
| `max_depth` | no       | —         | only topics up to this depth                     |
| `min_files` | no       | —         | only topics holding at least this many memories  |
| `limit`     | no       | `200`     | absent, below 1 or above 500 is read as 200      |
| `namespace` | no       | `default` |                                                  |

```bash
curl -s -G "$GITLOOM_API/v1/topics" -H "Authorization: Bearer $GITLOOM_KEY" \
  --data-urlencode "namespace=user-8213" --data-urlencode "like=databas"
```

```json
{
  "namespace": "user-8213",
  "topics": [{ "path": "facts/home", "name": "home", "tier": "facts", "parent": "facts", "depth": 2, "memories": 3 }],
  "millis": 2
}
```

`depth` counts path segments, so a tier is 1; `memories` counts the memory files under the topic.

| status | code                                                  |
| ------ | ----------------------------------------------------- |
| `400`  | `invalid_namespace`                                   |
| `403`  | `forbidden_namespace`                                 |
| `404`  | `namespace_not_found`                                 |
| `429`  | `quota_exceeded`, `rate_limited` (with `Retry-After`) |
| `402`  | `balance_exhausted`                                   |

#### GET /v1/graph

The namespace's whole tree (depth 8, capped at 400 nodes) plus one hop of relations between the nodes returned — for drawing a picture, never for reading content. Meters and rate-limits as a read.

| param       | required | default   |
| ----------- | -------- | --------- |
| `namespace` | no       | `default` |

```bash
curl -s "$GITLOOM_API/v1/graph?namespace=user-8213" -H "Authorization: Bearer $GITLOOM_KEY"
```

```json
{
  "namespace": "user-8213",
  "nodes": [{"path":"facts/camera-gear/bought-a-sony-a7iii-1f4b9c2a.md","tier":"facts","kind":"file","title":"Bought a Sony A7III","hash":"a1b2c3d"}],
  "edges": [{"src":"facts/camera-gear/bought-a-sony-a7iii-1f4b9c2a.md","dst":"facts/japan-trip/trip-planned-for-october-7d2e05b1.md","label":"packed-for","origin":"inline"}],
  "truncated": false, "millis": 22,
  "index": {"files": 87, "sections": 214, "cues": 340, "embedded": 340}
}
```

`404 namespace_not_found`; `402` and `429` as on a retrieval.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.gitloom.cloud/api-reference/memories.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
