{"title":"Authentication & Mind Keys","slug":"authentication","category":"getting-started","summary":"Synapse の認証の仕組み：エージェント向け Mind Key、人間向け JWT、URL 単体ツール向け ?key=。","audience":["human","llm"],"tags":["auth","mind-key","jwt","security"],"difficulty":"beginner","updated":"2026-06-27","word_count":272,"read_minutes":1,"llm_context":"Two auth methods: Mind Key (token-scoped, never expires) and JWT (user-scoped, 7-day expiry).\nMind Key: Authorization: Bearer mk_xxx OR ?key=mk_xxx (60 req/min limit on query)\nJWT: Authorization: Bearer eyJ... (no rate limit, used for /register, /login, /minds, /sharing)\nMind Key is shown only once at creation. Store it permanently.\nEach mind has exactly one Mind Key. Multiple minds = multiple keys.\n","lang":"ja","translated":true,"requested_lang":"ja","content_markdown":"\n# Authentication & Mind Keys\n\nSynapse は 2 つの認証方法を使用し、それぞれが異なるユースケースに最適化されています。信頼できる連携を構築するには、この違いを理解することが不可欠です。\n\n## 2 つの認証方法\n\n| 方法 | ユースケース | レート制限 | 有効期限 |\n|--------|----------|------------|--------|\n| **Mind Key** | LLM エージェント、自動化ツール | なし（ヘッダー）/ 60/分（クエリ） | なし |\n| **JWT** | ヒューマン向け UI、アカウント操作 | なし | 7 日 |\n\n## Mind Key（エージェント向け）\n\nMind Key はテナントスコープの API トークンです。単一 mind のデータ（メモリ、タスク、チャット、スクリプトなど）を認証します。以下に使用します。\n\n- API を呼び出す LLM エージェント\n- バックグラウンド自動化スクリプト\n- MCP サーバー設定\n- 任意の長期間の連携\n\n### ヘッダー認証（推奨）\n\n```bash\ncurl -H \"Authorization: Bearer mk_yourMindKeyHere\" \\\n     https://synapse.schaefer.zone/memory/recall\n```\n\n### クエリパラメータ（URL 単体ツール向け）\n\n```bash\ncurl https://synapse.schaefer.zone/memory/recall?key=mk_yourMindKeyHere\n```\n\n> [!WARNING]\n> `?key=` クエリパラメータは **60 リクエスト/分** にレート制限されます。Bearer ヘッダーにはレート制限がありません。クライアントがカスタムヘッダーをサポートする場合は常にヘッダーを使用してください。\n\n### Mind Key の作成\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 '{\"name\": \"Work Mind\", \"description\": \"Project memories\"}'\n```\n\nレスポンスに `mind_key` が含まれます — **すぐに保存してください**。一度しか表示されません。\n\n### mind の一覧\n\n```bash\ncurl -H \"Authorization: Bearer YOUR_JWT\" \\\n     https://synapse.schaefer.zone/minds\n```\n\n### mind の削除（不可逆！）\n\n```bash\ncurl -X DELETE -H \"Authorization: Bearer YOUR_JWT\" \\\n     https://synapse.schaefer.zone/minds/m_xyz789\n```\n\n## JWT（人間向け）\n\nJWT は特定の mind ではなく**ユーザーアカウント**を認証します。以下に使用します。\n\n- アカウントの登録とログイン\n- mind の作成/一覧/削除\n- 他のユーザーとの mind 共有\n- Web Push サブスクリプション管理\n\n### 登録\n\n```bash\ncurl -X POST https://synapse.schaefer.zone/register \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"email\": \"you@example.com\", \"password\": \"secret\"}'\n```\n\n返却値：`{ \"jwt\": \"eyJ...\", \"user\": {...} }`\n\n### ログイン\n\n```bash\ncurl -X POST https://synapse.schaefer.zone/login \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"email\": \"you@example.com\", \"password\": \"secret\"}'\n```\n\n返却値：`{ \"jwt\": \"eyJ...\", \"user\": {...} }`\n\n### JWT の有効期限\n\nJWT は **7 日後**に期限切れになります。期限切れの場合は、再度 `/login` を呼び出して新しい JWT を取得してください。Mind Key は期限切れにならないため、既存のエージェント連携は継続して動作します。\n\n## セキュリティのベストプラクティス\n\n> [!CRITICAL]\n> - **Mind Key を git にコミットしない。** 環境変数を使用してください。\n> - **Mind Key をログに出力しない。** ログではマスクしてください（`mk_***...***xyz`）。\n> - **漏洩が疑われる場合はキーをローテーション**（mind を削除し、新規作成）。\n> - **プロジェクトごとに 1 つの mind を使用**し、キー漏洩時の被害範囲を限定。\n\n### 環境変数パターン\n\n```bash\n# .env (NEVER commit this file)\nSYNAPSE_MIND_KEY=mk_yourMindKeyHere\nSYNAPSE_URL=https://synapse.schaefer.zone\n```\n\n```typescript\n// Node.js\nconst mindKey = process.env.SYNAPSE_MIND_KEY;\nconst url = process.env.SYNAPSE_URL;\nawait fetch(`${url}/memory/recall`, {\n  headers: { Authorization: `Bearer ${mindKey}` },\n});\n```\n\n### MCP サーバー設定\n\n```json\n{\n  \"mcpServers\": {\n    \"synapse\": {\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"synapse-mcp-api@latest\"],\n      \"env\": {\n        \"SYNAPSE_MIND_KEY\": \"mk_yourMindKeyHere\",\n        \"SYNAPSE_URL\": \"https://synapse.schaefer.zone\"\n      }\n    }\n  }\n}\n```\n\n## マルチ mind パターン\n\n各ユーザーは複数の mind を持てます。よくあるパターン：\n\n| Mind 名 | 目的 |\n|-----------|---------|\n| `work` | 仕事関連のメモリ |\n| `personal` | 個人の設定、家族 |\n| `project-synapse` | 特定プロジェクトのコンテキスト |\n| `learning-german` | 学習の進捗 |\n| `assistant-default` | 汎用フォールバック |\n\n異なる LLM セッションで異なる Mind Key を使用し、コンテキストを分離してください。\n\n## レート制限\n\n| 認証方法 | 制限 | スコープ |\n|-------------|-------|-------|\n| Mind Key（ヘッダー） | なし | mind ごと |\n| Mind Key（?key=） | 60/分 | IP ごと |\n| JWT（ヘッダー） | なし | ユーザーごと |\n| パブリックエンドポイント | なし | グローバル |\n\n該当する場合、レスポンスにレート制限ヘッダー（`X-RateLimit-Limit`、`X-RateLimit-Remaining`、`Retry-After`）が含まれます。\n\n## 次のステップ\n\n- [Mind Key vs JWT](/docs/getting-started/mind-key-vs-jwt) — どちらを使うべきか\n- [Memory API](/docs/api/memory) — Mind Key でできること\n- [User API](/docs/api/user) — JWT によるアカウント管理\n","content_html":"<h1>Authentication &amp; Mind Keys</h1>\n<p>Synapse は 2 つの認証方法を使用し、それぞれが異なるユースケースに最適化されています。信頼できる連携を構築するには、この違いを理解することが不可欠です。</p>\n<h2>2 つの認証方法</h2>\n<table>\n<thead>\n<tr>\n<th>方法</th>\n<th>ユースケース</th>\n<th>レート制限</th>\n<th>有効期限</th>\n</tr>\n</thead>\n<tbody><tr>\n<td><strong>Mind Key</strong></td>\n<td>LLM エージェント、自動化ツール</td>\n<td>なし（ヘッダー）/ 60/分（クエリ）</td>\n<td>なし</td>\n</tr>\n<tr>\n<td><strong>JWT</strong></td>\n<td>ヒューマン向け UI、アカウント操作</td>\n<td>なし</td>\n<td>7 日</td>\n</tr>\n</tbody></table>\n<h2>Mind Key（エージェント向け）</h2>\n<p>Mind Key はテナントスコープの API トークンです。単一 mind のデータ（メモリ、タスク、チャット、スクリプトなど）を認証します。以下に使用します。</p>\n<ul>\n<li>API を呼び出す LLM エージェント</li>\n<li>バックグラウンド自動化スクリプト</li>\n<li>MCP サーバー設定</li>\n<li>任意の長期間の連携</li>\n</ul>\n<h3>ヘッダー認証（推奨）</h3>\n<pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer mk_yourMindKeyHere&quot;</span> \\\n     https://synapse.schaefer.zone/memory/recall</code></pre><h3>クエリパラメータ（URL 単体ツール向け）</h3>\n<pre><code class=\"hljs language-bash\">curl https://synapse.schaefer.zone/memory/recall?key=mk_yourMindKeyHere</code></pre><div class=\"callout callout-warn\">`?key=` クエリパラメータは **60 リクエスト/分** にレート制限されます。Bearer ヘッダーにはレート制限がありません。クライアントがカスタムヘッダーをサポートする場合は常にヘッダーを使用してください。</div><h3>Mind Key の作成</h3>\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;{&quot;name&quot;: &quot;Work Mind&quot;, &quot;description&quot;: &quot;Project memories&quot;}&#x27;</span></code></pre><p>レスポンスに <code>mind_key</code> が含まれます — <strong>すぐに保存してください</strong>。一度しか表示されません。</p>\n<h3>mind の一覧</h3>\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><h3>mind の削除（不可逆！）</h3>\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><h2>JWT（人間向け）</h2>\n<p>JWT は特定の mind ではなく<strong>ユーザーアカウント</strong>を認証します。以下に使用します。</p>\n<ul>\n<li>アカウントの登録とログイン</li>\n<li>mind の作成/一覧/削除</li>\n<li>他のユーザーとの mind 共有</li>\n<li>Web Push サブスクリプション管理</li>\n</ul>\n<h3>登録</h3>\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;{&quot;email&quot;: &quot;you@example.com&quot;, &quot;password&quot;: &quot;secret&quot;}&#x27;</span></code></pre><p>返却値：<code>{ &quot;jwt&quot;: &quot;eyJ...&quot;, &quot;user&quot;: {...} }</code></p>\n<h3>ログイン</h3>\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;{&quot;email&quot;: &quot;you@example.com&quot;, &quot;password&quot;: &quot;secret&quot;}&#x27;</span></code></pre><p>返却値：<code>{ &quot;jwt&quot;: &quot;eyJ...&quot;, &quot;user&quot;: {...} }</code></p>\n<h3>JWT の有効期限</h3>\n<p>JWT は <strong>7 日後</strong>に期限切れになります。期限切れの場合は、再度 <code>/login</code> を呼び出して新しい JWT を取得してください。Mind Key は期限切れにならないため、既存のエージェント連携は継続して動作します。</p>\n<h2>セキュリティのベストプラクティス</h2>\n<div class=\"callout callout-critical\"></div><h3>環境変数パターン</h3>\n<pre><code class=\"hljs language-bash\"><span class=\"hljs-comment\"># .env (NEVER commit this file)</span>\nSYNAPSE_MIND_KEY=mk_yourMindKeyHere\nSYNAPSE_URL=https://synapse.schaefer.zone</code></pre><pre><code class=\"hljs language-typescript\"><span class=\"hljs-comment\">// Node.js</span>\n<span class=\"hljs-keyword\">const</span> mindKey = process.<span class=\"hljs-property\">env</span>.<span class=\"hljs-property\">SYNAPSE_MIND_KEY</span>;\n<span class=\"hljs-keyword\">const</span> url = process.<span class=\"hljs-property\">env</span>.<span class=\"hljs-property\">SYNAPSE_URL</span>;\n<span class=\"hljs-keyword\">await</span> <span class=\"hljs-title function_\">fetch</span>(<span class=\"hljs-string\">`<span class=\"hljs-subst\">${url}</span>/memory/recall`</span>, {\n  <span class=\"hljs-attr\">headers</span>: { <span class=\"hljs-title class_\">Authorization</span>: <span class=\"hljs-string\">`Bearer <span class=\"hljs-subst\">${mindKey}</span>`</span> },\n});</code></pre><h3>MCP サーバー設定</h3>\n<pre><code class=\"hljs language-json\"><span class=\"hljs-punctuation\">{</span>\n  <span class=\"hljs-attr\">&quot;mcpServers&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-punctuation\">{</span>\n    <span class=\"hljs-attr\">&quot;synapse&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-punctuation\">{</span>\n      <span class=\"hljs-attr\">&quot;command&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;npx&quot;</span><span class=\"hljs-punctuation\">,</span>\n      <span class=\"hljs-attr\">&quot;args&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-punctuation\">[</span><span class=\"hljs-string\">&quot;-y&quot;</span><span class=\"hljs-punctuation\">,</span> <span class=\"hljs-string\">&quot;synapse-mcp-api@latest&quot;</span><span class=\"hljs-punctuation\">]</span><span class=\"hljs-punctuation\">,</span>\n      <span class=\"hljs-attr\">&quot;env&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-punctuation\">{</span>\n        <span class=\"hljs-attr\">&quot;SYNAPSE_MIND_KEY&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;mk_yourMindKeyHere&quot;</span><span class=\"hljs-punctuation\">,</span>\n        <span class=\"hljs-attr\">&quot;SYNAPSE_URL&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;https://synapse.schaefer.zone&quot;</span>\n      <span class=\"hljs-punctuation\">}</span>\n    <span class=\"hljs-punctuation\">}</span>\n  <span class=\"hljs-punctuation\">}</span>\n<span class=\"hljs-punctuation\">}</span></code></pre><h2>マルチ mind パターン</h2>\n<p>各ユーザーは複数の mind を持てます。よくあるパターン：</p>\n<table>\n<thead>\n<tr>\n<th>Mind 名</th>\n<th>目的</th>\n</tr>\n</thead>\n<tbody><tr>\n<td><code>work</code></td>\n<td>仕事関連のメモリ</td>\n</tr>\n<tr>\n<td><code>personal</code></td>\n<td>個人の設定、家族</td>\n</tr>\n<tr>\n<td><code>project-synapse</code></td>\n<td>特定プロジェクトのコンテキスト</td>\n</tr>\n<tr>\n<td><code>learning-german</code></td>\n<td>学習の進捗</td>\n</tr>\n<tr>\n<td><code>assistant-default</code></td>\n<td>汎用フォールバック</td>\n</tr>\n</tbody></table>\n<p>異なる LLM セッションで異なる Mind Key を使用し、コンテキストを分離してください。</p>\n<h2>レート制限</h2>\n<table>\n<thead>\n<tr>\n<th>認証方法</th>\n<th>制限</th>\n<th>スコープ</th>\n</tr>\n</thead>\n<tbody><tr>\n<td>Mind Key（ヘッダー）</td>\n<td>なし</td>\n<td>mind ごと</td>\n</tr>\n<tr>\n<td>Mind Key（?key=）</td>\n<td>60/分</td>\n<td>IP ごと</td>\n</tr>\n<tr>\n<td>JWT（ヘッダー）</td>\n<td>なし</td>\n<td>ユーザーごと</td>\n</tr>\n<tr>\n<td>パブリックエンドポイント</td>\n<td>なし</td>\n<td>グローバル</td>\n</tr>\n</tbody></table>\n<p>該当する場合、レスポンスにレート制限ヘッダー（<code>X-RateLimit-Limit</code>、<code>X-RateLimit-Remaining</code>、<code>Retry-After</code>）が含まれます。</p>\n<h2>次のステップ</h2>\n<ul>\n<li><a href=\"/docs/getting-started/mind-key-vs-jwt\">Mind Key vs JWT</a> — どちらを使うべきか</li>\n<li><a href=\"/docs/api/memory\">Memory API</a> — Mind Key でできること</li>\n<li><a href=\"/docs/api/user\">User API</a> — JWT によるアカウント管理</li>\n</ul>\n","urls":{"html":"/docs/getting-started/authentication","text":"/docs/getting-started/authentication?format=text","json":"/docs/getting-started/authentication?format=json","llm":"/docs/getting-started/authentication?format=llm"},"translations_available":["en","zh","hi","es","fr","ar","pt","ru","ja","de","it","ko","nl","pl","tr","sv","vi","th","id","uk"]}