{"title":"User & Minds API","slug":"user","category":"api","summary":"Quản lý tài khoản — đăng ký, đăng nhập, tạo mind, liệt kê mind, xóa mind. Được bảo vệ bằng JWT.","audience":["human","llm"],"tags":["api","user","account","minds","jwt"],"difficulty":"beginner","updated":"2026-06-27","word_count":370,"read_minutes":2,"llm_context":"Auth: JWT (from /register or /login)\nRegister: POST /register { email, password, display_name? } → returns JWT\nLogin: POST /login { email, password } → returns JWT\nCreate mind: POST /minds { name, description? } → returns mind_key (shown once!)\nList minds: GET /minds\nDelete mind: DELETE /minds/:id (irreversible — deletes all memories!)\nJWT expires after 7 days. Mind Key never expires.\nMind Key is shown only once at creation — save it permanently.\n","lang":"vi","translated":true,"requested_lang":"vi","content_markdown":"\n# User & Minds API\n\nUser & Minds API xử lý quản lý tài khoản. Các endpoint này sử dụng xác thực JWT\n(không phải Mind Key) vì chúng hoạt động ở cấp tài khoản, không phải cấp mind.\n\n## Endpoint xác thực\n\n### POST /register\n\nTạo tài khoản người dùng mới.\n\n```bash\ncurl -X POST https://synapse.schaefer.zone/register \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"email\": \"you@example.com\",\n    \"password\": \"your-secure-password\",\n    \"display_name\": \"Michael\"\n  }'\n```\n\nPhản hồi:\n\n```json\n{\n  \"jwt\": \"eyJhbGci...\",\n  \"user\": {\n    \"id\": \"u_abc123\",\n    \"email\": \"you@example.com\",\n    \"display_name\": \"Michael\",\n    \"created_at\": \"2026-06-27T...\"\n  }\n}\n```\n\n### POST /login\n\nĐăng nhập vào tài khoản hiện có.\n\n```bash\ncurl -X POST https://synapse.schaefer.zone/login \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"email\": \"you@example.com\",\n    \"password\": \"your-secure-password\"\n  }'\n```\n\nPhản hồi: giống như `/register`.\n\n## Endpoint Minds\n\n### POST /minds\n\nTạo một mind mới. Trả về Mind Key — **lưu ngay lập tức**, nó chỉ hiển thị một lần.\n\n```bash\ncurl -X POST https://synapse.schaefer.zone/minds \\\n  -H \"Authorization: Bearer YOUR_JWT\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"name\": \"Work Mind\",\n    \"description\": \"Job-related memories\"\n  }'\n```\n\nPhản hồi:\n\n```json\n{\n  \"id\": \"m_xyz789\",\n  \"name\": \"Work Mind\",\n  \"description\": \"Job-related memories\",\n  \"mind_key\": \"mk_aBcDeFgHiJkLmNoPqRsTuVwXyZ0123456789\",\n  \"created_at\": \"2026-06-27T...\"\n}\n```\n\n> [!CRITICAL]\n> `mind_key` chỉ hiển thị một lần. Nếu bạn mất nó, bạn không thể lấy lại —\n> bạn phải xóa mind và tạo mind mới (điều này mất tất cả bộ nhớ đã lưu).\n\n### GET /minds\n\nLiệt kê tất cả mind của người dùng hiện tại.\n\n```bash\ncurl -H \"Authorization: Bearer YOUR_JWT\" \\\n     https://synapse.schaefer.zone/minds\n```\n\nPhản hồi:\n\n```json\n{\n  \"minds\": [\n    {\n      \"id\": \"m_xyz789\",\n      \"name\": \"Work Mind\",\n      \"description\": \"Job-related memories\",\n      \"created_at\": \"2026-06-27T...\",\n      \"memory_count\": 142,\n      \"last_activity\": \"2026-06-27T...\"\n    }\n  ]\n}\n```\n\n### DELETE /minds/:id\n\nXóa vĩnh viễn một mind.\n\n```bash\ncurl -X DELETE -H \"Authorization: Bearer YOUR_JWT\" \\\n     https://synapse.schaefer.zone/minds/m_xyz789\n```\n\n> [!WARNING]\n> Xóa mind là **không thể đảo ngược**. Tất cả bộ nhớ, tác vụ, lịch sử chat và\n> script trong mind đó sẽ mất vĩnh viễn. Xuất trước qua `GET /memory/mind-export`\n> nếu bạn cần sao lưu.\n\n## Mẫu Multi-Mind\n\nHầu hết người dùng được lợi từ việc có nhiều mind để giữ các ngữ cảnh tách biệt:\n\n```bash\n# Create minds for different contexts\ncurl -X POST .../minds -d '{\"name\": \"work\", \"description\": \"Job\"}'\n# → mind_key: mk_work...\n\ncurl -X POST .../minds -d '{\"name\": \"personal\", \"description\": \"Personal life\"}'\n# → mind_key: mk_personal...\n\ncurl -X POST .../minds -d '{\"name\": \"project-synapse\", \"description\": \"Synapse dev\"}'\n# → mind_key: mk_synapse...\n```\n\nSử dụng các Mind Key khác nhau trong các phiên LLM khác nhau để giữ ngữ cảnh tách biệt.\n\n## Bảo mật tài khoản\n\n### Yêu cầu mật khẩu\n\n- Tối thiểu 6 ký tự\n- Không có giới hạn tối đa (sử dụng trình quản lý mật khẩu)\n- Lưu dưới dạng bcrypt hash (không bao giờ plaintext)\n\n### Hết hạn JWT\n\nJWT hết hạn sau **7 ngày**. Khi hết hạn, chỉ cần gọi lại `/login`.\n\n### Bảo mật Mind Key\n\nMind Key không bao giờ hết hạn. Nếu Mind Key bị xâm phạm:\n\n1. Tạo mind mới qua `POST /minds`\n2. Cập nhật cấu hình LLM với Mind Key mới\n3. Xóa mind bị xâm phạm qua `DELETE /minds/:id`\n\n## Bước tiếp theo\n\n- [Xác thực](/docs/getting-started/authentication) — hướng dẫn xác thực đầy đủ\n- [Mind Key vs JWT](/docs/getting-started/mind-key-vs-jwt) — hướng dẫn quyết định\n- [Sharing API](/docs/api/user) — chia sẻ mind với người dùng khác\n","content_html":"<h1>User &amp; Minds API</h1>\n<p>User &amp; Minds API xử lý quản lý tài khoản. Các endpoint này sử dụng xác thực JWT\n(không phải Mind Key) vì chúng hoạt động ở cấp tài khoản, không phải cấp mind.</p>\n<h2>Endpoint xác thực</h2>\n<h3>POST /register</h3>\n<p>Tạo tài khoản người dùng mới.</p>\n<pre><code class=\"hljs language-bash\">curl -X POST https://synapse.schaefer.zone/register \\\n  -H <span class=\"hljs-string\">&quot;Content-Type: application/json&quot;</span> \\\n  -d <span class=\"hljs-string\">&#x27;{\n    &quot;email&quot;: &quot;you@example.com&quot;,\n    &quot;password&quot;: &quot;your-secure-password&quot;,\n    &quot;display_name&quot;: &quot;Michael&quot;\n  }&#x27;</span></code></pre><p>Phản hồi:</p>\n<pre><code class=\"hljs language-json\"><span class=\"hljs-punctuation\">{</span>\n  <span class=\"hljs-attr\">&quot;jwt&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;eyJhbGci...&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;user&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-punctuation\">{</span>\n    <span class=\"hljs-attr\">&quot;id&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;u_abc123&quot;</span><span class=\"hljs-punctuation\">,</span>\n    <span class=\"hljs-attr\">&quot;email&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;you@example.com&quot;</span><span class=\"hljs-punctuation\">,</span>\n    <span class=\"hljs-attr\">&quot;display_name&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;Michael&quot;</span><span class=\"hljs-punctuation\">,</span>\n    <span class=\"hljs-attr\">&quot;created_at&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;2026-06-27T...&quot;</span>\n  <span class=\"hljs-punctuation\">}</span>\n<span class=\"hljs-punctuation\">}</span></code></pre><h3>POST /login</h3>\n<p>Đăng nhập vào tài khoản hiện có.</p>\n<pre><code class=\"hljs language-bash\">curl -X POST https://synapse.schaefer.zone/login \\\n  -H <span class=\"hljs-string\">&quot;Content-Type: application/json&quot;</span> \\\n  -d <span class=\"hljs-string\">&#x27;{\n    &quot;email&quot;: &quot;you@example.com&quot;,\n    &quot;password&quot;: &quot;your-secure-password&quot;\n  }&#x27;</span></code></pre><p>Phản hồi: giống như <code>/register</code>.</p>\n<h2>Endpoint Minds</h2>\n<h3>POST /minds</h3>\n<p>Tạo một mind mới. Trả về Mind Key — <strong>lưu ngay lập tức</strong>, nó chỉ hiển thị một lần.</p>\n<pre><code class=\"hljs language-bash\">curl -X POST https://synapse.schaefer.zone/minds \\\n  -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_JWT&quot;</span> \\\n  -H <span class=\"hljs-string\">&quot;Content-Type: application/json&quot;</span> \\\n  -d <span class=\"hljs-string\">&#x27;{\n    &quot;name&quot;: &quot;Work Mind&quot;,\n    &quot;description&quot;: &quot;Job-related memories&quot;\n  }&#x27;</span></code></pre><p>Phản hồi:</p>\n<pre><code class=\"hljs language-json\"><span class=\"hljs-punctuation\">{</span>\n  <span class=\"hljs-attr\">&quot;id&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;m_xyz789&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;name&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;Work Mind&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;description&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;Job-related memories&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;mind_key&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;mk_aBcDeFgHiJkLmNoPqRsTuVwXyZ0123456789&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;created_at&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;2026-06-27T...&quot;</span>\n<span class=\"hljs-punctuation\">}</span></code></pre><div class=\"callout callout-critical\">`mind_key` chỉ hiển thị một lần. Nếu bạn mất nó, bạn không thể lấy lại —\nbạn phải xóa mind và tạo mind mới (điều này mất tất cả bộ nhớ đã lưu).</div><h3>GET /minds</h3>\n<p>Liệt kê tất cả mind của người dùng hiện tại.</p>\n<pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_JWT&quot;</span> \\\n     https://synapse.schaefer.zone/minds</code></pre><p>Phản hồi:</p>\n<pre><code class=\"hljs language-json\"><span class=\"hljs-punctuation\">{</span>\n  <span class=\"hljs-attr\">&quot;minds&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-punctuation\">[</span>\n    <span class=\"hljs-punctuation\">{</span>\n      <span class=\"hljs-attr\">&quot;id&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;m_xyz789&quot;</span><span class=\"hljs-punctuation\">,</span>\n      <span class=\"hljs-attr\">&quot;name&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;Work Mind&quot;</span><span class=\"hljs-punctuation\">,</span>\n      <span class=\"hljs-attr\">&quot;description&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;Job-related memories&quot;</span><span class=\"hljs-punctuation\">,</span>\n      <span class=\"hljs-attr\">&quot;created_at&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;2026-06-27T...&quot;</span><span class=\"hljs-punctuation\">,</span>\n      <span class=\"hljs-attr\">&quot;memory_count&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-number\">142</span><span class=\"hljs-punctuation\">,</span>\n      <span class=\"hljs-attr\">&quot;last_activity&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;2026-06-27T...&quot;</span>\n    <span class=\"hljs-punctuation\">}</span>\n  <span class=\"hljs-punctuation\">]</span>\n<span class=\"hljs-punctuation\">}</span></code></pre><h3>DELETE /minds/:id</h3>\n<p>Xóa vĩnh viễn một mind.</p>\n<pre><code class=\"hljs language-bash\">curl -X DELETE -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_JWT&quot;</span> \\\n     https://synapse.schaefer.zone/minds/m_xyz789</code></pre><div class=\"callout callout-warn\">Xóa mind là **không thể đảo ngược**. Tất cả bộ nhớ, tác vụ, lịch sử chat và\nscript trong mind đó sẽ mất vĩnh viễn. Xuất trước qua `GET /memory/mind-export`\nnếu bạn cần sao lưu.</div><h2>Mẫu Multi-Mind</h2>\n<p>Hầu hết người dùng được lợi từ việc có nhiều mind để giữ các ngữ cảnh tách biệt:</p>\n<pre><code class=\"hljs language-bash\"><span class=\"hljs-comment\"># Create minds for different contexts</span>\ncurl -X POST .../minds -d <span class=\"hljs-string\">&#x27;{&quot;name&quot;: &quot;work&quot;, &quot;description&quot;: &quot;Job&quot;}&#x27;</span>\n<span class=\"hljs-comment\"># → mind_key: mk_work...</span>\n\ncurl -X POST .../minds -d <span class=\"hljs-string\">&#x27;{&quot;name&quot;: &quot;personal&quot;, &quot;description&quot;: &quot;Personal life&quot;}&#x27;</span>\n<span class=\"hljs-comment\"># → mind_key: mk_personal...</span>\n\ncurl -X POST .../minds -d <span class=\"hljs-string\">&#x27;{&quot;name&quot;: &quot;project-synapse&quot;, &quot;description&quot;: &quot;Synapse dev&quot;}&#x27;</span>\n<span class=\"hljs-comment\"># → mind_key: mk_synapse...</span></code></pre><p>Sử dụng các Mind Key khác nhau trong các phiên LLM khác nhau để giữ ngữ cảnh tách biệt.</p>\n<h2>Bảo mật tài khoản</h2>\n<h3>Yêu cầu mật khẩu</h3>\n<ul>\n<li>Tối thiểu 6 ký tự</li>\n<li>Không có giới hạn tối đa (sử dụng trình quản lý mật khẩu)</li>\n<li>Lưu dưới dạng bcrypt hash (không bao giờ plaintext)</li>\n</ul>\n<h3>Hết hạn JWT</h3>\n<p>JWT hết hạn sau <strong>7 ngày</strong>. Khi hết hạn, chỉ cần gọi lại <code>/login</code>.</p>\n<h3>Bảo mật Mind Key</h3>\n<p>Mind Key không bao giờ hết hạn. Nếu Mind Key bị xâm phạm:</p>\n<ol>\n<li>Tạo mind mới qua <code>POST /minds</code></li>\n<li>Cập nhật cấu hình LLM với Mind Key mới</li>\n<li>Xóa mind bị xâm phạm qua <code>DELETE /minds/:id</code></li>\n</ol>\n<h2>Bước tiếp theo</h2>\n<ul>\n<li><a href=\"/docs/getting-started/authentication\">Xác thực</a> — hướng dẫn xác thực đầy đủ</li>\n<li><a href=\"/docs/getting-started/mind-key-vs-jwt\">Mind Key vs JWT</a> — hướng dẫn quyết định</li>\n<li><a href=\"/docs/api/user\">Sharing API</a> — chia sẻ mind với người dùng khác</li>\n</ul>\n","urls":{"html":"/docs/api/user","text":"/docs/api/user?format=text","json":"/docs/api/user?format=json","llm":"/docs/api/user?format=llm"},"translations_available":["en","zh","hi","es","fr","ar","pt","ru","ja","de","it","ko","nl","pl","tr","sv","vi","th","id","uk"]}