---
title: "Add data to the memory graph"
description: "Add arbitrary data (text, JSON, or message) to a knowledge graph.\n\nTarget exactly one scope: `agent_id` writes to the calling user's memory\n(shared agents write to the shared graph, agent-scoped agents to their\nown); `graph_id` writes to a shared namespace and requires a service\ntoken. Processing is asynchronous — entity extraction and\nrelationship building happen in the background. Returns 202 immediately."
---

> 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/graph`

Add arbitrary data (text, JSON, or message) to a knowledge graph.

Target exactly one scope: `agent_id` writes to the calling user's memory
(shared agents write to the shared graph, agent-scoped agents to their
own); `graph_id` writes to a shared namespace and requires a service
token. Processing is asynchronous — entity extraction and
relationship building happen in the background. Returns 202 immediately.

## Authentication

- `HTTPBearer`, http, header `Authorization`

## Header parameters

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

## Request body

_Required._

- `data` (`add_memory_data.data`; string, required)
  - maxLength 50000
- `type` (`add_memory_data.type`; string, required) — Content shape; selects the extraction rules and nothing else. In a user scope, `message` is one user turn and is stored like a chat exchange (see `assistant_message`). `document` is a note or document the user brought in whole (`note` is accepted as its older name).
  - one of `"message"`, `"json"`, `"text"`, `"document"`, `"note"`, `"transcribe"`
- `agent_id` (`add_memory_data.agent_id`; any of, optional) — Target the calling user's memory, scoped by this agent. Provide exactly one of agent_id or graph_id.
  - any of: `string`, `null`
- `graph_id` (`add_memory_data.graph_id`; any of, optional) — Target a shared namespace instead of user memory. Requires a service token.
  - any of: `string`, `null`
- `source_description` (`add_memory_data.source_description`; any of, optional)
  - any of: `string`, `null`
- `created_at` (`add_memory_data.created_at`; any of, optional)
  - any of: `string`, `null`
- `assistant_message` (`add_memory_data.assistant_message`; any of, optional) — For a user-scope `type=message` only: the assistant turn that answered `data`. Stored with it as one exchange so extraction reads the turn in context.
  - any of: `string`, `null`
- `wait` (`add_memory_data.wait`; boolean, optional) — When true, wait for processing to complete before responding.
  - default `false`

## Example request

```json
{
  "data": "string",
  "type": "message",
  "agent_id": "string",
  "graph_id": "string",
  "source_description": "string",
  "created_at": "2019-08-24T14:15:22Z",
  "assistant_message": "string",
  "wait": false
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url https://truememory-api.mvstg.com/memories/graph \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "data": "string",
  "type": "message",
  "agent_id": "string",
  "graph_id": "string",
  "source_description": "string",
  "created_at": "2019-08-24T14:15:22Z",
  "assistant_message": "string",
  "wait": false
}
'
```

### TypeScript

```typescript
const url = 'https://truememory-api.mvstg.com/memories/graph';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({
    data: 'string',
    type: 'message',
    agent_id: 'string',
    graph_id: 'string',
    source_description: 'string',
    created_at: '2019-08-24T14:15:22Z',
    assistant_message: 'string',
    wait: false
  })
};

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/graph"

payload = {
    "data": "string",
    "type": "message",
    "agent_id": "string",
    "graph_id": "string",
    "source_description": "string",
    "created_at": "2019-08-24T14:15:22Z",
    "assistant_message": "string",
    "wait": False
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

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

print(response.text)
```

## Responses

### 200

Ingestion finished inline (`wait=true`).

#### Example

```json
{
  "status": "completed"
}
```

- `status` (`add_memory_data.response.200.status`; string, optional)
  - default `"completed"`

### 202

Ingestion was queued; poll the job for completion.

#### Example

```json
{
  "status": "processing",
  "job_id": "string"
}
```

- `job_id` (`add_memory_data.response.202.job_id`; string, required) — Poll GET /memories/graph/status/{job_id} with this.
- `status` (`add_memory_data.response.202.status`; string, optional)
  - default `"processing"`

### 422

Validation Error

#### Example

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

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


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