{
  "openapi": "3.1.0",
  "info": {
    "title": "Memory by Kiawak",
    "version": "1.0.0",
    "description": "Long-term memory for AI assistants: Markdown notes with [[links]] and #tags. Call getContext at the start, searchMemory before answering about the user, remember to store lasting facts and preferences. Never store secrets."
  },
  "servers": [
    {
      "url": "https://memory.kiawak.com/v1"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key mem_… from memory.kiawak.com/verbinden"
      }
    },
    "schemas": {
      "Note": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "folder": {
            "type": "string"
          },
          "body": {
            "type": "string"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "kind": {
            "type": "string"
          },
          "importance": {
            "type": "integer"
          },
          "pinned": {
            "type": "boolean"
          },
          "updated_at": {
            "type": "string"
          },
          "source": {
            "type": "string"
          }
        }
      }
    }
  },
  "security": [
    {
      "bearer": []
    }
  ],
  "paths": {
    "/context": {
      "get": {
        "operationId": "getContext",
        "summary": "Load pinned notes, standing instructions, important facts and recent changes.",
        "parameters": [
          {
            "name": "topic",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Optional topic of the conversation."
          }
        ],
        "responses": {
          "200": {
            "description": "Context",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/search": {
      "get": {
        "operationId": "searchMemory",
        "summary": "Full-text search over all notes.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "maximum": 50
            }
          },
          {
            "name": "tag",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Matches with snippets",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/memories": {
      "post": {
        "operationId": "remember",
        "summary": "Store a memory; with the title of an existing note it is appended there.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "content"
                ],
                "properties": {
                  "content": {
                    "type": "string"
                  },
                  "title": {
                    "type": "string"
                  },
                  "kind": {
                    "type": "string",
                    "enum": [
                      "note",
                      "fact",
                      "preference",
                      "person",
                      "project",
                      "event",
                      "instruction"
                    ]
                  },
                  "tags": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "importance": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 5
                  },
                  "links": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "folder": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Stored",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/notes": {
      "get": {
        "operationId": "listNotes",
        "summary": "List notes, newest first.",
        "parameters": [
          {
            "name": "folder",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tag",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "kind",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "note",
                "fact",
                "preference",
                "person",
                "project",
                "event",
                "instruction"
              ]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "maximum": 500
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Notes without body",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createNote",
        "summary": "Create a note.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "title"
                ],
                "properties": {
                  "title": {
                    "type": "string"
                  },
                  "body": {
                    "type": "string"
                  },
                  "folder": {
                    "type": "string"
                  },
                  "tags": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "kind": {
                    "type": "string",
                    "enum": [
                      "note",
                      "fact",
                      "preference",
                      "person",
                      "project",
                      "event",
                      "instruction"
                    ]
                  },
                  "importance": {
                    "type": "integer"
                  },
                  "pinned": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          }
        }
      }
    },
    "/notes/{ref}": {
      "get": {
        "operationId": "readNote",
        "summary": "Read a note with backlinks and outgoing links.",
        "parameters": [
          {
            "name": "ref",
            "in": "path",
            "required": true,
            "description": "Title of the note (URL-encoded) or its id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Note",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "writeNote",
        "summary": "Create or replace a note (the old text stays as a version).",
        "parameters": [
          {
            "name": "ref",
            "in": "path",
            "required": true,
            "description": "Title of the note (URL-encoded) or its id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "description": "New title to rename"
                  },
                  "body": {
                    "type": "string"
                  },
                  "folder": {
                    "type": "string"
                  },
                  "tags": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "kind": {
                    "type": "string",
                    "enum": [
                      "note",
                      "fact",
                      "preference",
                      "person",
                      "project",
                      "event",
                      "instruction"
                    ]
                  },
                  "importance": {
                    "type": "integer"
                  },
                  "pinned": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "forgetNote",
        "summary": "Move a note to the trash (restorable for 30 days).",
        "parameters": [
          {
            "name": "ref",
            "in": "path",
            "required": true,
            "description": "Title of the note (URL-encoded) or its id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Trashed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/notes/{ref}/append": {
      "post": {
        "operationId": "appendToNote",
        "summary": "Add a dated line at the end of a note (creates it if missing).",
        "parameters": [
          {
            "name": "ref",
            "in": "path",
            "required": true,
            "description": "Title of the note (URL-encoded) or its id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "text"
                ],
                "properties": {
                  "text": {
                    "type": "string"
                  },
                  "dated": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Appended",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/notes/{ref}/links": {
      "get": {
        "operationId": "getLinks",
        "summary": "Backlinks and outgoing links of a note.",
        "parameters": [
          {
            "name": "ref",
            "in": "path",
            "required": true,
            "description": "Title of the note (URL-encoded) or its id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Links",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/folders": {
      "get": {
        "operationId": "listFoldersAndTags",
        "summary": "Folders and tags with counts.",
        "responses": {
          "200": {
            "description": "Overview",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  }
}