{"title":"Autenticazione e Mind Key","slug":"authentication","category":"getting-started","summary":"Come funziona l'autenticazione di Synapse: Mind Key per agenti, JWT per umani, ?key= per strumenti solo-URL.","audience":["human","llm"],"tags":["auth","mind-key","jwt","security"],"difficulty":"beginner","updated":"2026-06-27","word_count":508,"read_minutes":3,"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":"it","translated":true,"requested_lang":"it","content_markdown":"\n# Autenticazione e Mind Key\n\nSynapse usa due metodi di autenticazione, ciascuno ottimizzato per un caso\nd'uso diverso. Comprendere la differenza è essenziale per costruire\nintegrazioni affidabili.\n\n## Due metodi di auth\n\n| Metodo | Caso d'uso | Rate limit | Scadenza |\n|--------|----------|------------|--------|\n| **Mind Key** | Agenti LLM, strumenti automatizzati | Nessuno (header) / 60 min (query) | Mai |\n| **JWT** | UI human-facing, operazioni account | Nessuno | 7 giorni |\n\n## Mind Key (per agenti)\n\nUna Mind Key è un token API con scope tenant. Autentica i dati di una singola\nmente (memorie, attività, chat, script, ecc.). La usi per:\n\n- Agenti LLM che chiamano l'API\n- Script di automazione in background\n- Configurazione del server MCP\n- Qualsiasi integrazione long-lived\n\n### Autenticazione tramite header (consigliata)\n\n```bash\ncurl -H \"Authorization: Bearer mk_yourMindKeyHere\" \\\n     https://synapse.schaefer.zone/memory/recall\n```\n\n### Parametro query (per strumenti solo-URL)\n\n```bash\ncurl https://synapse.schaefer.zone/memory/recall?key=mk_yourMindKeyHere\n```\n\n> [!WARNING]\n> Il parametro query `?key=` è limitato a **60 richieste al minuto**.\n> L'header Bearer non ha rate limit. Usi l'header quando il suo client\n> supporta header personalizzati.\n\n### Creare una 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\nLa risposta include `mind_key` — **la salvi immediatamente**, viene mostrata\nuna sola volta.\n\n### Elencare le sue menti\n\n```bash\ncurl -H \"Authorization: Bearer YOUR_JWT\" \\\n     https://synapse.schaefer.zone/minds\n```\n\n### Eliminare una mente (irreversibile!)\n\n```bash\ncurl -X DELETE -H \"Authorization: Bearer YOUR_JWT\" \\\n     https://synapse.schaefer.zone/minds/m_xyz789\n```\n\n## JWT (per umani)\n\nI JWT autenticano l'**account utente**, non una specifica mente. Li usi per:\n\n- Registrazione e login dell'account\n- Creare / elencare / eliminare menti\n- Condividere menti con altri utenti\n- Gestione delle sottoscrizioni Web Push\n\n### Registrazione\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\nRestituisce: `{ \"jwt\": \"eyJ...\", \"user\": {...} }`\n\n### Login\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\nRestituisce: `{ \"jwt\": \"eyJ...\", \"user\": {...} }`\n\n### Scadenza del JWT\n\nI JWT scadono dopo **7 giorni**. Quando un JWT scade, chiami semplicemente\n`/login` nuovamente per ottenerne uno nuovo. La Mind Key non scade mai, quindi\nle integrazioni agente esistenti continuano a funzionare.\n\n## Best practice di sicurezza\n\n> [!CRITICAL]\n> - **Non committi mai le Mind Key su git.** Usi variabili di ambiente.\n> - **Non logghi mai le Mind Key.** Le mascheri nei log (`mk_***...***xyz`).\n> - **Roti le chiavi** se sospetta una leak (elimini la mente, ne crei una nuova).\n> - **Usi una mente per progetto** per limitare il raggio d'azione se una chiave leaka.\n\n### Modello con variabili di ambiente\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### Configurazione del server 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## Modello multi-mente\n\nOgni utente può avere menti multiple. Modelli comuni:\n\n| Nome mente | Scopo |\n|-----------|---------|\n| `work` | Memorie relative al lavoro |\n| `personal` | Preferenze personali, famiglia |\n| `project-synapse` | Contesto di progetto specifico |\n| `learning-german` | Avanzamento dell'apprendimento |\n| `assistant-default` | Fallback generico |\n\nUsi Mind Key diverse per sessioni LLM diverse per mantenere i contesti\nisolati.\n\n## Limiti di traffico\n\n| Metodo di auth | Limite | Ambito |\n|-------------|-------|-------|\n| Mind Key (header) | Nessuno | Per-mente |\n| Mind Key (?key=) | 60/min | Per-IP |\n| JWT (header) | Nessuno | Per-utente |\n| Endpoint pubblici | Nessuno | Globale |\n\nGli header di rate limit (`X-RateLimit-Limit`, `X-RateLimit-Remaining`,\n`Retry-After`) sono inclusi nelle risposte quando applicabile.\n\n## Prossimi passi\n\n- [Mind Key vs JWT](/docs/getting-started/mind-key-vs-jwt) — quando usare quale\n- [Memory API](/docs/api/memory) — cosa può fare con una Mind Key\n- [API User](/docs/api/user) — gestione account con JWT\n","content_html":"<h1>Autenticazione e Mind Key</h1>\n<p>Synapse usa due metodi di autenticazione, ciascuno ottimizzato per un caso\nd&#39;uso diverso. Comprendere la differenza è essenziale per costruire\nintegrazioni affidabili.</p>\n<h2>Due metodi di auth</h2>\n<table>\n<thead>\n<tr>\n<th>Metodo</th>\n<th>Caso d&#39;uso</th>\n<th>Rate limit</th>\n<th>Scadenza</th>\n</tr>\n</thead>\n<tbody><tr>\n<td><strong>Mind Key</strong></td>\n<td>Agenti LLM, strumenti automatizzati</td>\n<td>Nessuno (header) / 60 min (query)</td>\n<td>Mai</td>\n</tr>\n<tr>\n<td><strong>JWT</strong></td>\n<td>UI human-facing, operazioni account</td>\n<td>Nessuno</td>\n<td>7 giorni</td>\n</tr>\n</tbody></table>\n<h2>Mind Key (per agenti)</h2>\n<p>Una Mind Key è un token API con scope tenant. Autentica i dati di una singola\nmente (memorie, attività, chat, script, ecc.). La usi per:</p>\n<ul>\n<li>Agenti LLM che chiamano l&#39;API</li>\n<li>Script di automazione in background</li>\n<li>Configurazione del server MCP</li>\n<li>Qualsiasi integrazione long-lived</li>\n</ul>\n<h3>Autenticazione tramite header (consigliata)</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>Parametro query (per strumenti solo-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\">Il parametro query `?key=` è limitato a **60 richieste al minuto**.\nL'header Bearer non ha rate limit. Usi l'header quando il suo client\nsupporta header personalizzati.</div><h3>Creare una 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>La risposta include <code>mind_key</code> — <strong>la salvi immediatamente</strong>, viene mostrata\nuna sola volta.</p>\n<h3>Elencare le sue menti</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>Eliminare una mente (irreversibile!)</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 (per umani)</h2>\n<p>I JWT autenticano l&#39;<strong>account utente</strong>, non una specifica mente. Li usi per:</p>\n<ul>\n<li>Registrazione e login dell&#39;account</li>\n<li>Creare / elencare / eliminare menti</li>\n<li>Condividere menti con altri utenti</li>\n<li>Gestione delle sottoscrizioni Web Push</li>\n</ul>\n<h3>Registrazione</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>Restituisce: <code>{ &quot;jwt&quot;: &quot;eyJ...&quot;, &quot;user&quot;: {...} }</code></p>\n<h3>Login</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>Restituisce: <code>{ &quot;jwt&quot;: &quot;eyJ...&quot;, &quot;user&quot;: {...} }</code></p>\n<h3>Scadenza del JWT</h3>\n<p>I JWT scadono dopo <strong>7 giorni</strong>. Quando un JWT scade, chiami semplicemente\n<code>/login</code> nuovamente per ottenerne uno nuovo. La Mind Key non scade mai, quindi\nle integrazioni agente esistenti continuano a funzionare.</p>\n<h2>Best practice di sicurezza</h2>\n<div class=\"callout callout-critical\"></div><h3>Modello con variabili di ambiente</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>Configurazione del server 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>Modello multi-mente</h2>\n<p>Ogni utente può avere menti multiple. Modelli comuni:</p>\n<table>\n<thead>\n<tr>\n<th>Nome mente</th>\n<th>Scopo</th>\n</tr>\n</thead>\n<tbody><tr>\n<td><code>work</code></td>\n<td>Memorie relative al lavoro</td>\n</tr>\n<tr>\n<td><code>personal</code></td>\n<td>Preferenze personali, famiglia</td>\n</tr>\n<tr>\n<td><code>project-synapse</code></td>\n<td>Contesto di progetto specifico</td>\n</tr>\n<tr>\n<td><code>learning-german</code></td>\n<td>Avanzamento dell&#39;apprendimento</td>\n</tr>\n<tr>\n<td><code>assistant-default</code></td>\n<td>Fallback generico</td>\n</tr>\n</tbody></table>\n<p>Usi Mind Key diverse per sessioni LLM diverse per mantenere i contesti\nisolati.</p>\n<h2>Limiti di traffico</h2>\n<table>\n<thead>\n<tr>\n<th>Metodo di auth</th>\n<th>Limite</th>\n<th>Ambito</th>\n</tr>\n</thead>\n<tbody><tr>\n<td>Mind Key (header)</td>\n<td>Nessuno</td>\n<td>Per-mente</td>\n</tr>\n<tr>\n<td>Mind Key (?key=)</td>\n<td>60/min</td>\n<td>Per-IP</td>\n</tr>\n<tr>\n<td>JWT (header)</td>\n<td>Nessuno</td>\n<td>Per-utente</td>\n</tr>\n<tr>\n<td>Endpoint pubblici</td>\n<td>Nessuno</td>\n<td>Globale</td>\n</tr>\n</tbody></table>\n<p>Gli header di rate limit (<code>X-RateLimit-Limit</code>, <code>X-RateLimit-Remaining</code>,\n<code>Retry-After</code>) sono inclusi nelle risposte quando applicabile.</p>\n<h2>Prossimi passi</h2>\n<ul>\n<li><a href=\"/docs/getting-started/mind-key-vs-jwt\">Mind Key vs JWT</a> — quando usare quale</li>\n<li><a href=\"/docs/api/memory\">Memory API</a> — cosa può fare con una Mind Key</li>\n<li><a href=\"/docs/api/user\">API User</a> — gestione account con 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"]}