> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://stelltec.com/rhebok/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://stelltec.com/rhebok/docs/_mcp/server.

# Create or edit a memory

POST http://127.0.0.1:7331/api/memory/save
Content-Type: application/json

Without `id`, creates a memory, and `outcome` is one of:

- `saved`: the memory was written.
- `replaced`: a lesson or fact of the same kind was similar enough to
  count as a near-duplicate (`[memory] duplicate_similarity`). The new
  memory was written and the old one deleted; `previous_title` names it.
- `duplicate`: nothing was written, and `id` is the memory that already
  exists. This happens when the same text is already stored under the
  same id, and when an episode has a near-duplicate episode, because
  episodes are never replaced.

With `id`, edits that memory. A successful edit always answers
`replaced`, with the memory's id after the edit and its own old title
in `previous_title`. Tell an edit from a replaced near-duplicate by
whether you sent `id`. An edit that changes the kind or text changes
the id, because the id derives from both. If that new id belongs to a
different memory that already exists, nothing is written and the
answer is `duplicate` with that memory's id.

Writes are serialised inside the dashboard.


Reference: https://stelltec.com/rhebok/docs/api/memories/save-memory

## Request

### Body (application/json)

This endpoint expects a MemorySaveRequest.

- `kind` (string, required) — `lesson`, `fact` or `episode` (case-insensitive).
- `text` (string, required) — 10 to 2,000 characters after trimming.
- `scope` (string, required) — `global` or an empty string for a global memory; otherwise the project path it applies to.
- `id` (string, optional) — Leave out to create a memory. Give an existing id (or unique prefix) to edit it. A blank id is refused.
- `confidence` (integer, optional, default: 100) — A percent.

## Response

### 200

The outcome of the write.

- `MemorySaveOutcome`
  - `outcome`: `saved` (Saved)
    - `id` (string, required)
  - `outcome`: `replaced` (Replaced)
    - `id` (string, required)
    - `previous_title` (string, required) — The title of the memory that was replaced, or, for an edit, the edited memory's own title before the edit.
  - `outcome`: `duplicate` (Duplicate)
    - `id` (string, required)

## Errors

### 400 Bad Request Error

The body is not the expected JSON, `kind` is not `lesson`, `fact` or `episode`, `confidence` is over 100, `id` is present but blank, or the memory was rejected (for example its text is not 10 to 2,000 characters, or memory is disabled in config).

- `error` (string, required) — What went wrong, in plain words.

### 404 Not Found Error

The `id` of an edit matches no memory, or matches more than one.

- `error` (string, required) — What went wrong, in plain words.

### 409 Conflict Error

Another rhebok process holds the memory store's lock, or the request `Origin` is not this dashboard.

- `error` (string, required) — What went wrong, in plain words.

### 413 Content Too Large Error

The declared `Content-Length` is over 65,536 bytes.

- `error` (string, required) — What went wrong, in plain words.

### 421 Misdirected Request Error

The `Host` header does not name this dashboard (see the rules at the top of this page).

- `error` (string, required) — What went wrong, in plain words.

### 503 Service Unavailable Error

Any other failure to write the memory, such as an embedding failure.

- `error` (string, required) — What went wrong, in plain words.

## Examples

### Create a new memory

**Request**

```json
{
  "kind": "lesson",
  "text": "Run cargo clippy --all-targets before pushing; zero warnings is the bar.",
  "scope": "global",
  "confidence": 100
}
```

**Response**

```json
{
  "outcome": "saved",
  "id": "7e1f0c3a9b2d"
}
```

**SDK Code**

```python Create a new memory
import requests

url = "http://127.0.0.1:7331/api/memory/save"

payload = {
    "kind": "lesson",
    "text": "Run cargo clippy --all-targets before pushing; zero warnings is the bar.",
    "scope": "global",
    "confidence": 100
}
headers = {"Content-Type": "application/json"}

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

print(response.json())
```

```javascript Create a new memory
const url = 'http://127.0.0.1:7331/api/memory/save';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"kind":"lesson","text":"Run cargo clippy --all-targets before pushing; zero warnings is the bar.","scope":"global","confidence":100}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Create a new memory
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "http://127.0.0.1:7331/api/memory/save"

	payload := strings.NewReader("{\n  \"kind\": \"lesson\",\n  \"text\": \"Run cargo clippy --all-targets before pushing; zero warnings is the bar.\",\n  \"scope\": \"global\",\n  \"confidence\": 100\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Create a new memory
require 'uri'
require 'net/http'

url = URI("http://127.0.0.1:7331/api/memory/save")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"kind\": \"lesson\",\n  \"text\": \"Run cargo clippy --all-targets before pushing; zero warnings is the bar.\",\n  \"scope\": \"global\",\n  \"confidence\": 100\n}"

response = http.request(request)
puts response.read_body
```

```java Create a new memory
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("http://127.0.0.1:7331/api/memory/save")
  .header("Content-Type", "application/json")
  .body("{\n  \"kind\": \"lesson\",\n  \"text\": \"Run cargo clippy --all-targets before pushing; zero warnings is the bar.\",\n  \"scope\": \"global\",\n  \"confidence\": 100\n}")
  .asString();
```

```php Create a new memory
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'http://127.0.0.1:7331/api/memory/save', [
  'body' => '{
  "kind": "lesson",
  "text": "Run cargo clippy --all-targets before pushing; zero warnings is the bar.",
  "scope": "global",
  "confidence": 100
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Create a new memory
using RestSharp;

var client = new RestClient("http://127.0.0.1:7331/api/memory/save");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"kind\": \"lesson\",\n  \"text\": \"Run cargo clippy --all-targets before pushing; zero warnings is the bar.\",\n  \"scope\": \"global\",\n  \"confidence\": 100\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Create a new memory
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "kind": "lesson",
  "text": "Run cargo clippy --all-targets before pushing; zero warnings is the bar.",
  "scope": "global",
  "confidence": 100
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "http://127.0.0.1:7331/api/memory/save")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Create a memory that replaces a near-duplicate

**Request**

```json
{
  "kind": "lesson",
  "text": "Run cargo clippy --all-targets before every push; zero warnings is the bar.",
  "scope": "global",
  "confidence": 100
}
```

**Response**

```json
{
  "outcome": "replaced",
  "id": "3d8b5e21c6f4",
  "previous_title": "Run clippy before you push"
}
```

**SDK Code**

```python Create a memory that replaces a near-duplicate
import requests

url = "http://127.0.0.1:7331/api/memory/save"

payload = {
    "kind": "lesson",
    "text": "Run cargo clippy --all-targets before every push; zero warnings is the bar.",
    "scope": "global",
    "confidence": 100
}
headers = {"Content-Type": "application/json"}

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

print(response.json())
```

```javascript Create a memory that replaces a near-duplicate
const url = 'http://127.0.0.1:7331/api/memory/save';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"kind":"lesson","text":"Run cargo clippy --all-targets before every push; zero warnings is the bar.","scope":"global","confidence":100}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Create a memory that replaces a near-duplicate
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "http://127.0.0.1:7331/api/memory/save"

	payload := strings.NewReader("{\n  \"kind\": \"lesson\",\n  \"text\": \"Run cargo clippy --all-targets before every push; zero warnings is the bar.\",\n  \"scope\": \"global\",\n  \"confidence\": 100\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Create a memory that replaces a near-duplicate
require 'uri'
require 'net/http'

url = URI("http://127.0.0.1:7331/api/memory/save")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"kind\": \"lesson\",\n  \"text\": \"Run cargo clippy --all-targets before every push; zero warnings is the bar.\",\n  \"scope\": \"global\",\n  \"confidence\": 100\n}"

response = http.request(request)
puts response.read_body
```

```java Create a memory that replaces a near-duplicate
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("http://127.0.0.1:7331/api/memory/save")
  .header("Content-Type", "application/json")
  .body("{\n  \"kind\": \"lesson\",\n  \"text\": \"Run cargo clippy --all-targets before every push; zero warnings is the bar.\",\n  \"scope\": \"global\",\n  \"confidence\": 100\n}")
  .asString();
```

```php Create a memory that replaces a near-duplicate
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'http://127.0.0.1:7331/api/memory/save', [
  'body' => '{
  "kind": "lesson",
  "text": "Run cargo clippy --all-targets before every push; zero warnings is the bar.",
  "scope": "global",
  "confidence": 100
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Create a memory that replaces a near-duplicate
using RestSharp;

var client = new RestClient("http://127.0.0.1:7331/api/memory/save");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"kind\": \"lesson\",\n  \"text\": \"Run cargo clippy --all-targets before every push; zero warnings is the bar.\",\n  \"scope\": \"global\",\n  \"confidence\": 100\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Create a memory that replaces a near-duplicate
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "kind": "lesson",
  "text": "Run cargo clippy --all-targets before every push; zero warnings is the bar.",
  "scope": "global",
  "confidence": 100
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "http://127.0.0.1:7331/api/memory/save")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Create a memory that already exists

**Request**

```json
{
  "kind": "lesson",
  "text": "One commit per pull request. Squash the branch before you open the PR, and again after review fixes land.",
  "scope": "global",
  "confidence": 100
}
```

**Response**

```json
{
  "outcome": "duplicate",
  "id": "a41c09e2f7b3"
}
```

**SDK Code**

```python Create a memory that already exists
import requests

url = "http://127.0.0.1:7331/api/memory/save"

payload = {
    "kind": "lesson",
    "text": "One commit per pull request. Squash the branch before you open the PR, and again after review fixes land.",
    "scope": "global",
    "confidence": 100
}
headers = {"Content-Type": "application/json"}

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

print(response.json())
```

```javascript Create a memory that already exists
const url = 'http://127.0.0.1:7331/api/memory/save';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"kind":"lesson","text":"One commit per pull request. Squash the branch before you open the PR, and again after review fixes land.","scope":"global","confidence":100}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Create a memory that already exists
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "http://127.0.0.1:7331/api/memory/save"

	payload := strings.NewReader("{\n  \"kind\": \"lesson\",\n  \"text\": \"One commit per pull request. Squash the branch before you open the PR, and again after review fixes land.\",\n  \"scope\": \"global\",\n  \"confidence\": 100\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Create a memory that already exists
require 'uri'
require 'net/http'

url = URI("http://127.0.0.1:7331/api/memory/save")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"kind\": \"lesson\",\n  \"text\": \"One commit per pull request. Squash the branch before you open the PR, and again after review fixes land.\",\n  \"scope\": \"global\",\n  \"confidence\": 100\n}"

response = http.request(request)
puts response.read_body
```

```java Create a memory that already exists
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("http://127.0.0.1:7331/api/memory/save")
  .header("Content-Type", "application/json")
  .body("{\n  \"kind\": \"lesson\",\n  \"text\": \"One commit per pull request. Squash the branch before you open the PR, and again after review fixes land.\",\n  \"scope\": \"global\",\n  \"confidence\": 100\n}")
  .asString();
```

```php Create a memory that already exists
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'http://127.0.0.1:7331/api/memory/save', [
  'body' => '{
  "kind": "lesson",
  "text": "One commit per pull request. Squash the branch before you open the PR, and again after review fixes land.",
  "scope": "global",
  "confidence": 100
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Create a memory that already exists
using RestSharp;

var client = new RestClient("http://127.0.0.1:7331/api/memory/save");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"kind\": \"lesson\",\n  \"text\": \"One commit per pull request. Squash the branch before you open the PR, and again after review fixes land.\",\n  \"scope\": \"global\",\n  \"confidence\": 100\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Create a memory that already exists
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "kind": "lesson",
  "text": "One commit per pull request. Squash the branch before you open the PR, and again after review fixes land.",
  "scope": "global",
  "confidence": 100
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "http://127.0.0.1:7331/api/memory/save")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Edit a memory

**Request**

```json
{
  "kind": "lesson",
  "text": "One commit per pull request. Squash the branch before you open the PR, again after review fixes land, and before you merge.",
  "scope": "global",
  "id": "a41c09e2f7b3",
  "confidence": 100
}
```

**Response**

```json
{
  "outcome": "replaced",
  "id": "c5902b7d1e8a",
  "previous_title": "One commit per pull request"
}
```

**SDK Code**

```python Edit a memory
import requests

url = "http://127.0.0.1:7331/api/memory/save"

payload = {
    "kind": "lesson",
    "text": "One commit per pull request. Squash the branch before you open the PR, again after review fixes land, and before you merge.",
    "scope": "global",
    "id": "a41c09e2f7b3",
    "confidence": 100
}
headers = {"Content-Type": "application/json"}

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

print(response.json())
```

```javascript Edit a memory
const url = 'http://127.0.0.1:7331/api/memory/save';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"kind":"lesson","text":"One commit per pull request. Squash the branch before you open the PR, again after review fixes land, and before you merge.","scope":"global","id":"a41c09e2f7b3","confidence":100}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Edit a memory
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "http://127.0.0.1:7331/api/memory/save"

	payload := strings.NewReader("{\n  \"kind\": \"lesson\",\n  \"text\": \"One commit per pull request. Squash the branch before you open the PR, again after review fixes land, and before you merge.\",\n  \"scope\": \"global\",\n  \"id\": \"a41c09e2f7b3\",\n  \"confidence\": 100\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Edit a memory
require 'uri'
require 'net/http'

url = URI("http://127.0.0.1:7331/api/memory/save")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"kind\": \"lesson\",\n  \"text\": \"One commit per pull request. Squash the branch before you open the PR, again after review fixes land, and before you merge.\",\n  \"scope\": \"global\",\n  \"id\": \"a41c09e2f7b3\",\n  \"confidence\": 100\n}"

response = http.request(request)
puts response.read_body
```

```java Edit a memory
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("http://127.0.0.1:7331/api/memory/save")
  .header("Content-Type", "application/json")
  .body("{\n  \"kind\": \"lesson\",\n  \"text\": \"One commit per pull request. Squash the branch before you open the PR, again after review fixes land, and before you merge.\",\n  \"scope\": \"global\",\n  \"id\": \"a41c09e2f7b3\",\n  \"confidence\": 100\n}")
  .asString();
```

```php Edit a memory
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'http://127.0.0.1:7331/api/memory/save', [
  'body' => '{
  "kind": "lesson",
  "text": "One commit per pull request. Squash the branch before you open the PR, again after review fixes land, and before you merge.",
  "scope": "global",
  "id": "a41c09e2f7b3",
  "confidence": 100
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Edit a memory
using RestSharp;

var client = new RestClient("http://127.0.0.1:7331/api/memory/save");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"kind\": \"lesson\",\n  \"text\": \"One commit per pull request. Squash the branch before you open the PR, again after review fixes land, and before you merge.\",\n  \"scope\": \"global\",\n  \"id\": \"a41c09e2f7b3\",\n  \"confidence\": 100\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Edit a memory
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "kind": "lesson",
  "text": "One commit per pull request. Squash the branch before you open the PR, again after review fixes land, and before you merge.",
  "scope": "global",
  "id": "a41c09e2f7b3",
  "confidence": 100
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "http://127.0.0.1:7331/api/memory/save")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```