> ## Documentation Index
> Fetch the complete documentation index at: https://platform.kimi.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Memory

> Create cross-session memory stores, manage memory files, and inspect or restore content by version.

## What is a memory store?

A memory store is a project-level collection of persistent files. When you mount a memory store at session creation, the agent can read or update its files during the session.

Memory stores, memory files, and file versions represent distinct objects:

| Object | Description |
| - | - |
| Memory store | A collection that holds memory files |
| Memory file | An individual file inside a memory store |
| Memory version | A historical record of creating, modifying, renaming, or deleting a file |

Memory stores do not provide automatic vector search. When a session starts, the platform provides the agent with up to 16 KiB each from root-level `README.md` and `index.md` files. Other files are read on demand by the agent using file tools.

> [!WARNING]
>
> Do not store API keys, access tokens, passwords, or other sensitive credentials in a memory store. Use [Vaults](https://platform.kimi.ai/docs/hosted-agents/vaults.md) to store credentials.

## Create and mount a memory store

The minimal end-to-end workflow takes three steps: create a memory store, create a memory file, and mount the memory store when creating a session. You can also create and manage memory stores on the **Memory** page in the console; see [Using the Console](https://platform.kimi.ai/docs/hosted-agents/console.md#memory). Beyond the console and REST API, you can also create and manage memory stores with the [kha CLI](https://platform.kimi.ai/docs/hosted-agents/kha.md).

The examples below provide both cURL and `kha` CLI commands for working with memory stores and memory files.

### Create a memory store

The request below creates a memory store named `project-conventions`:

```bash cURL theme={null}
curl --request POST "https://api.moonshot.ai/v1/memory-stores" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "project-conventions",
    "description": "Project conventions and decision records"
  }'
```

```bash CLI theme={null}
kha memory-stores create --name "project-conventions" --description "Project conventions and decision records"
```

Save `id` from the response as `MEMORY_STORE_ID` for subsequent requests. `name` must be unique within the project, be 1 to 64 characters long, and start with a Unicode letter or digit; subsequent characters may also include `_` and `-`.

### Create a memory file

Create a file using the memory store ID and file path. `content` is the Base64-encoded file body, and the decoded body can be at most 20 MiB. In the example below, `content` is the Base64 encoding of `"Project conventions\n"`:

```bash cURL theme={null}
curl --request POST "https://api.moonshot.ai/v1/memory-stores/$MEMORY_STORE_ID/memories" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta" \
  --header "Content-Type: application/json" \
  --data '{
    "path": "project/conventions.md",
    "content": "UHJvamVjdCBjb252ZW50aW9ucwo="
  }'
```

```bash CLI theme={null}
kha memory-stores memories create "$MEMORY_STORE_ID" --path "project/conventions.md" --content "Project conventions"
```

Save the file `id` from the response as `MEMORY_ID` for reading, updating, and listing versions. You can omit `content` or pass an empty string to create an empty file, but you cannot create another file at an existing path.

`path` must be a normalized relative path of at most 900 bytes (UTF-8 encoded) using `/` as the directory separator. Absolute paths, empty path segments, `.`, `..`, backslashes, control characters, and percent-encoding are not allowed.

### Mount a memory store in a session

Memory stores can only be attached when creating a session. The request below uses `MEMORY_STORE_ID` from the previous step and mounts the memory store in read-write mode:

```bash cURL theme={null}
curl --request POST "https://api.moonshot.ai/v1/sessions" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta" \
  --header "Content-Type: application/json" \
  --data '{
    "agent_id": "agent_your_agent_id",
    "environment_id": "env_your_environment_id",
    "resources": [
      {
        "type": "memory_store",
        "memory_store_id": "<MEMORY_STORE_ID from previous step>",
        "access": "read_write",
        "instructions": "Follow the project conventions and record important new takeaways."
      }
    ]
  }'
```

```bash CLI theme={null}
kha sessions create --file - <<'JSON'
{
  "agent_id": "agent_your_agent_id",
  "environment_id": "env_your_environment_id",
  "resources": [
    {
      "type": "memory_store",
      "memory_store_id": "<MEMORY_STORE_ID from previous step>",
      "access": "read_write",
      "instructions": "Follow the project conventions and record important new takeaways."
    }
  ]
}
JSON
```

Replace `agent_id` and `environment_id` with existing resource IDs, and replace `MEMORY_STORE_ID` with `id` from the memory store creation response.

`access` can be `read_only` or `read_write`:

* `read_only`: allows reading from the memory store only.
* `read_write`: allows both reading from and writing to the memory store.

A single session can mount at most 8 memory stores.

Each memory store is mounted at `/mnt/agents/memories/<store-name>/` inside the session. The binding, access mode, and `instructions` cannot be modified after the session is created, though you can unbind the memory store via the session resources endpoints.

## Manage memory files

### Read a file

Read a file using the memory store ID and file ID. `content` in the API response is Base64-encoded; save `content_sha256` from the response so you can pass it back unchanged for concurrency checking when updating the file:

```bash cURL theme={null}
curl --request GET "https://api.moonshot.ai/v1/memory-stores/$MEMORY_STORE_ID/memories/$MEMORY_ID" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha memory-stores memories get "$MEMORY_STORE_ID" "$MEMORY_ID"
```

### Update a file

Encode the new body in Base64 and update the file. Set `content_sha256` in the request to the value obtained when reading the current file; the platform uses it to check whether the file was modified after you read it:

```bash cURL theme={null}
curl --request PATCH "https://api.moonshot.ai/v1/memory-stores/$MEMORY_STORE_ID/memories/$MEMORY_ID" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta" \
  --header "Content-Type: application/json" \
  --data '{
    "content": "VXBkYXRlZCBwcm9qZWN0IGNvbnZlbnRpb25zCg==",
    "content_sha256": "<content_sha256 from current file response>"
  }'
```

```bash CLI theme={null}
kha memory-stores memories update "$MEMORY_STORE_ID" "$MEMORY_ID" --content "Updated project conventions" --sha256 "<content_sha256 from current file response>"
```

If the file has been modified by another source, updating with a stale `content_sha256` returns HTTP `409` without overwriting the newer content. Writes made through the session mount path and file tools do not go through the API's `content_sha256` concurrency check, so concurrent session writes can overwrite each other. Every successful file change creates a new version.

### Delete a file

Deleting a file removes only the current file while preserving its historical versions:

```bash cURL theme={null}
curl --request DELETE "https://api.moonshot.ai/v1/memory-stores/$MEMORY_STORE_ID/memories/$MEMORY_ID" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha memory-stores memories delete "$MEMORY_STORE_ID" "$MEMORY_ID"
```

After deletion, you can still query the version list and historical version contents under the original `memory_id`, but you can no longer send `PATCH` requests to that `memory_id`.

## Inspect versions and restore files

### Inspect file versions

Creating, modifying, renaming, and deleting a file each generate a version whose `operation` field is `created`, `modified`, `renamed`, or `deleted`, respectively. Query the file's version list first, then choose a version to read:

```bash cURL theme={null}
curl --request GET "https://api.moonshot.ai/v1/memory-stores/$MEMORY_STORE_ID/memories/$MEMORY_ID/versions?order=desc" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha memory-stores memories versions list "$MEMORY_STORE_ID" "$MEMORY_ID" --order desc
```

Select a version that includes file content and read its `content`. Versions with `operation` set to `deleted` do not return `content` and cannot be used to restore a file:

```bash cURL theme={null}
curl --request GET "https://api.moonshot.ai/v1/memory-stores/$MEMORY_STORE_ID/memories/$MEMORY_ID/versions/<version_id>" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha memory-stores memories versions get "$MEMORY_STORE_ID" "$MEMORY_ID" "<version_id>"
```

Each version also records how it was written: `source` is `api` for writes through the API and `session` for writes from a session. When `source` is `session`, `source_id` contains the ID of the session that wrote the version. To find changes produced by a given session, filter for versions where `source` is `session` and `source_id` equals that session ID.

`content` in historical versions is also Base64-encoded. To restore a file, write the historical version's `content` back as the new file body along with the current file's `content_sha256`:

```bash cURL theme={null}
curl --request PATCH "https://api.moonshot.ai/v1/memory-stores/$MEMORY_STORE_ID/memories/$MEMORY_ID" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta" \
  --header "Content-Type: application/json" \
  --data '{
    "content": "<content from historical version response>",
    "content_sha256": "<content_sha256 from current file response>"
  }'
```

```bash CLI theme={null}
kha memory-stores memories update "$MEMORY_STORE_ID" "$MEMORY_ID" --file - <<'JSON'
{
  "content": "<content from historical version response>",
  "content_sha256": "<content_sha256 from current file response>"
}
JSON
```

Restoring generates a new version for the file. When restoring multiple files, read the current `content_sha256` and write back the historical content for each file individually, then verify each restored file.

### Restore a deleted file

A version with `operation` set to `deleted` does not include file content. To restore a deleted file, read a pre-deletion version that includes content, then recreate the file at the original path using that version's `content`:

```bash cURL theme={null}
curl --request POST "https://api.moonshot.ai/v1/memory-stores/$MEMORY_STORE_ID/memories" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta" \
  --header "Content-Type: application/json" \
  --data '{
    "path": "project/conventions.md",
    "content": "<content from pre-deletion version response>"
  }'
```

```bash CLI theme={null}
kha memory-stores memories create "$MEMORY_STORE_ID" --file - <<'JSON'
{
  "path": "project/conventions.md",
  "content": "<content from pre-deletion version response>"
}
JSON
```

Recreating the file generates a new `memory_id` and starts a new version history from a fresh `created` version; the pre-deletion version history is still retained and queryable under the original `memory_id`. Before restoring, make sure `content` in the historical version has not been redacted.

### Redact historical version content

If the body of a historical version no longer needs to be retained, call the redact endpoint to permanently erase its body while keeping the version metadata:

```bash cURL theme={null}
curl --request POST "https://api.moonshot.ai/v1/memory-stores/$MEMORY_STORE_ID/memories/$MEMORY_ID/versions/<version_id>/redact" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha memory-stores memories versions redact "$MEMORY_STORE_ID" "$MEMORY_ID" "<version_id>"
```

* Redaction affects only the selected version; the current file and other versions are unaffected.
* You cannot redact the version corresponding to the current file, and repeating the call on an already redacted version is a no-op.
* Redacted content cannot be recovered, and any version with `redacted_at` in its response can no longer be used for restoration.

## Memory store lifecycle

### Update a memory store

Call `PATCH /v1/memory-stores/{id}` to modify a memory store's name and description; fields omitted from the request body keep their current values. Archived memory stores cannot be updated.

### Duplicate a memory store

Duplicating a memory store is currently supported only in the console and is not exposed via the API. Click **Duplicate memory store** on the memory store details page in the console to create a new memory store and copy all memory files from the current store into it. Only current file contents are copied, without version history; files in the copy start from a new `created` version with new `memory_id` values.

### Archive a memory store

Call `POST /v1/memory-stores/{id}/archive` or click **Archive** on the console details page to archive an unused memory store. Archiving is irreversible. After archiving:

* The memory store cannot be mounted in new sessions, and its metadata and memory files cannot be modified via the API.
* Files and version history remain readable, and historical version content can still be redacted.

### Delete a memory store

Call `DELETE /v1/memory-stores/{id}` to permanently delete a memory store along with all of its files and version history. The memory store's Dreams policy is deleted together with it; its managed trigger is archived so it stops firing, while past run records are retained. A memory store must be archived first and must not be attached to any session.

> [!WARNING]
>
> Permanently deleting a memory store may result in unrecoverable data loss. Proceed with caution.

## Related resources

> [card] [Dreams](https://platform.kimi.ai/docs/hosted-agents/dreams.md)
>
> Consolidate memory stores by policy, and inspect or restore changes through version history.

> [card] [Create a Session](https://platform.kimi.ai/docs/hosted-agents/sessions.md)
>
> Learn how to create sessions and attach resources.

> [card] [Sandbox Reference](https://platform.kimi.ai/docs/hosted-agents/sandbox-reference.md)
>
> Check memory store mount paths and sandbox boundaries.

> [card] [Vaults](https://platform.kimi.ai/docs/hosted-agents/vaults.md)
>
> Manage credentials used by sessions.
