---
title: "Merge two memories"
description: "Collapse two entity-node memories into one.\n\nLive edges incident to ``duplicate_id`` are repointed at ``primary_id``;\nthe duplicate is soft-marked via ``merged_into``; an ``IS_DUPLICATE_OF``\naudit edge is written for traceability. Both nodes must already live in\nthe requested user+agent scope."
---

> Documentation Index
> Fetch the complete documentation index at: https://truememory-docs.mvstg.com/llms.txt
> Use this file to discover all available pages before exploring further.

Path: AI Gateway API › Memory

`POST /memories/{agent_id}/merge`

Collapse two entity-node memories into one.

Live edges incident to ``duplicate_id`` are repointed at ``primary_id``;
the duplicate is soft-marked via ``merged_into``; an ``IS_DUPLICATE_OF``
audit edge is written for traceability. Both nodes must already live in
the requested user+agent scope.

## Authentication

- `HTTPBearer`, http, header `Authorization`

## Path parameters

- `agent_id` (`merge_memories.path.agent_id`; string, required)

## Header parameters

- `X-On-Behalf-Of` (`merge_memories.header.X-On-Behalf-Of`; any of, optional)
  - any of: `string`, `null`
- `X-External-User-Id` (`merge_memories.header.X-External-User-Id`; any of, optional)
  - any of: `string`, `null`
- `X-App-Id` (`merge_memories.header.X-App-Id`; any of, optional)
  - any of: `string`, `null`

## Request body

_Required._

- `primary_id` (`merge_memories.primary_id`; string, required) — UUID of the entity node to keep.
- `duplicate_id` (`merge_memories.duplicate_id`; string, required) — UUID of the entity node to fold into primary.
- `graph_id` (`merge_memories.graph_id`; any of, optional) — Optional. Merge within a shared namespace instead of the user's own memory. Requires a service token; the agent_id path segment is ignored.
  - any of: `string`, `null`

## Example request

```json
{
  "primary_id": "string",
  "duplicate_id": "string",
  "graph_id": "string"
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url 'https://truememory-api.mvstg.com/memories/<agent_id>/merge' \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "primary_id": "string",
  "duplicate_id": "string",
  "graph_id": "string"
}
'
```

### TypeScript

```typescript
const url = 'https://truememory-api.mvstg.com/memories/<agent_id>/merge';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({primary_id: 'string', duplicate_id: 'string', graph_id: 'string'})
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://truememory-api.mvstg.com/memories/<agent_id>/merge"

payload = {
    "primary_id": "string",
    "duplicate_id": "string",
    "graph_id": "string"
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 200

Successful Response

#### Example

```json
{
  "primary_id": "string",
  "duplicate_id": "string",
  "rewired_outgoing": 0,
  "rewired_incoming": 0,
  "audit_edge_id": "string",
  "merged_at": "string",
  "enriched": true,
  "enriched_summary": "string",
  "enriched_labels": [
    "string"
  ]
}
```

- `primary_id` (`merge_memories.response.200.primary_id`; string, required)
- `duplicate_id` (`merge_memories.response.200.duplicate_id`; string, required)
- `rewired_outgoing` (`merge_memories.response.200.rewired_outgoing`; integer, required)
- `rewired_incoming` (`merge_memories.response.200.rewired_incoming`; integer, required)
- `audit_edge_id` (`merge_memories.response.200.audit_edge_id`; any of, required)
  - any of: `string`, `null`
- `merged_at` (`merge_memories.response.200.merged_at`; any of, required)
  - any of: `string`, `null`
- `enriched` (`merge_memories.response.200.enriched`; boolean, required)
- `enriched_summary` (`merge_memories.response.200.enriched_summary`; any of, required)
  - any of: `string`, `null`
- `enriched_labels` (`merge_memories.response.200.enriched_labels`; any of, required) — Null when enrichment failed.
  - any of: `array<string>`, `null`

### 422

Validation Error

#### Example

```json
{
  "detail": [
    {
      "loc": [
        "string"
      ],
      "msg": "string",
      "type": "string",
      "input": null,
      "ctx": {}
    }
  ]
}
```

- `detail` (`merge_memories.response.422.detail`; array<object>, optional)
  - `loc` (`merge_memories.response.422.detail.loc`; array<any of>, required)
    - any of: `string`, `integer`
  - `msg` (`merge_memories.response.422.detail.msg`; string, required)
  - `type` (`merge_memories.response.422.detail.type`; string, required)
  - `input` (`merge_memories.response.422.detail.input`; unknown, optional)
  - `ctx` (`merge_memories.response.422.detail.ctx`; object, optional)


Source: https://truememory-docs.mvstg.com/api/memories/merge/index.md
