{"title":"API de Variables","slug":"variables","category":"api","summary":"Almacén rápido clave-valor para estado de LLM — contadores, flags, timestamps de última actividad, progreso parcial.","audience":["human","llm"],"tags":["api","variables","kv-store","state"],"difficulty":"beginner","updated":"2026-06-27","word_count":191,"read_minutes":1,"llm_context":"Auth: Mind Key\nSet: POST /var { key, value }\nGet: GET /var/:key\nList: GET /var\nDelete: DELETE /var/:key\nUse case: store last-seen timestamps, counters, flags, partial workflow state\nFaster than memory (PostgreSQL direct, no FTS5 indexing)\nNot for: structured facts (use /memory), long content (use /script)\n","lang":"es","translated":true,"requested_lang":"es","content_markdown":"\n# API de Variables\n\nLa API de Variables es un almacén rápido clave-valor para estado efímero. A\ndiferencia de las memorias (que están indexadas, son buscables y estructuradas),\nlas variables están optimizadas para acceso rápido de lectura/escritura —\nperfectas para contadores, flags y estado de sesión.\n\n## Endpoints\n\n### POST /var\n\nEstablece o actualiza una variable.\n\n```bash\ncurl -X POST https://synapse.schaefer.zone/var \\\n  -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"key\": \"last_session_at\", \"value\": \"2026-06-27T14:00:00Z\"}'\n```\n\n### GET /var/:key\n\nObtiene una variable individual.\n\n```bash\ncurl -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     https://synapse.schaefer.zone/var/last_session_at\n```\n\nRespuesta:\n\n```json\n{ \"key\": \"last_session_at\", \"value\": \"2026-06-27T14:00:00Z\", \"updated_at\": \"...\" }\n```\n\n### GET /var\n\nLista todas las variables.\n\n```bash\ncurl -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     https://synapse.schaefer.zone/var\n```\n\n### DELETE /var/:key\n\nElimina una variable.\n\n```bash\ncurl -X DELETE -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     https://synapse.schaefer.zone/var/last_session_at\n```\n\n## Cuándo usar Variables vs Memory\n\n| Caso de uso | Usar |\n|----------|-----|\n| Nombre, preferencias | Memory (buscable, estructurado) |\n| Timestamp de última sesión | Variable (estado efímero) |\n| Contador (p. ej. mensajes enviados) | Variable (actualizaciones frecuentes) |\n| Estado de workflow (\"paso 3 de 5 completado\") | Variable (transitorio) |\n| Notas largas de proyecto | Memory (indexado de texto completo) |\n| Scripts reutilizables | Script store (con nombre, versionado) |\n\n## Patrones comunes\n\n### Seguimiento de la última sesión\n\n```bash\n# At session end\ncurl -X POST .../var -d '{\"key\": \"last_session_at\", \"value\": \"'$(date -Iseconds)'\"}'\n\n# At session start\nLAST=$(curl .../var/last_session_at | jq -r .value)\ncurl .../memory/diff?since=$(date -d \"$LAST\" +%s)\n```\n\n### Patrón contador\n\n```bash\n# Increment\nN=$(curl .../var/api_calls | jq -r .value)\ncurl -X POST .../var -d \"{\\\"key\\\": \\\"api_calls\\\", \\\"value\\\": $((N+1))}\"\n```\n\n### Feature flags\n\n```bash\ncurl -X POST .../var -d '{\"key\": \"feature_x_enabled\", \"value\": \"true\"}'\n\n# Check\nENABLED=$(curl .../var/feature_x_enabled | jq -r .value)\nif [ \"$ENABLED\" = \"true\" ]; then ... fi\n```\n\n## Próximos pasos\n\n- [API de Memory](/docs/api/memory) — para datos estructurados y buscables\n- [Cron y Scheduler](/docs/api/cron)\n","content_html":"<h1>API de Variables</h1>\n<p>La API de Variables es un almacén rápido clave-valor para estado efímero. A\ndiferencia de las memorias (que están indexadas, son buscables y estructuradas),\nlas variables están optimizadas para acceso rápido de lectura/escritura —\nperfectas para contadores, flags y estado de sesión.</p>\n<h2>Endpoints</h2>\n<h3>POST /var</h3>\n<p>Establece o actualiza una variable.</p>\n<pre><code class=\"hljs language-bash\">curl -X POST https://synapse.schaefer.zone/var \\\n  -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n  -H <span class=\"hljs-string\">&quot;Content-Type: application/json&quot;</span> \\\n  -d <span class=\"hljs-string\">&#x27;{&quot;key&quot;: &quot;last_session_at&quot;, &quot;value&quot;: &quot;2026-06-27T14:00:00Z&quot;}&#x27;</span></code></pre><h3>GET /var/:key</h3>\n<p>Obtiene una variable individual.</p>\n<pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     https://synapse.schaefer.zone/var/last_session_at</code></pre><p>Respuesta:</p>\n<pre><code class=\"hljs language-json\"><span class=\"hljs-punctuation\">{</span> <span class=\"hljs-attr\">&quot;key&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;last_session_at&quot;</span><span class=\"hljs-punctuation\">,</span> <span class=\"hljs-attr\">&quot;value&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;2026-06-27T14:00:00Z&quot;</span><span class=\"hljs-punctuation\">,</span> <span class=\"hljs-attr\">&quot;updated_at&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;...&quot;</span> <span class=\"hljs-punctuation\">}</span></code></pre><h3>GET /var</h3>\n<p>Lista todas las variables.</p>\n<pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     https://synapse.schaefer.zone/var</code></pre><h3>DELETE /var/:key</h3>\n<p>Elimina una variable.</p>\n<pre><code class=\"hljs language-bash\">curl -X DELETE -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     https://synapse.schaefer.zone/var/last_session_at</code></pre><h2>Cuándo usar Variables vs Memory</h2>\n<table>\n<thead>\n<tr>\n<th>Caso de uso</th>\n<th>Usar</th>\n</tr>\n</thead>\n<tbody><tr>\n<td>Nombre, preferencias</td>\n<td>Memory (buscable, estructurado)</td>\n</tr>\n<tr>\n<td>Timestamp de última sesión</td>\n<td>Variable (estado efímero)</td>\n</tr>\n<tr>\n<td>Contador (p. ej. mensajes enviados)</td>\n<td>Variable (actualizaciones frecuentes)</td>\n</tr>\n<tr>\n<td>Estado de workflow (&quot;paso 3 de 5 completado&quot;)</td>\n<td>Variable (transitorio)</td>\n</tr>\n<tr>\n<td>Notas largas de proyecto</td>\n<td>Memory (indexado de texto completo)</td>\n</tr>\n<tr>\n<td>Scripts reutilizables</td>\n<td>Script store (con nombre, versionado)</td>\n</tr>\n</tbody></table>\n<h2>Patrones comunes</h2>\n<h3>Seguimiento de la última sesión</h3>\n<pre><code class=\"hljs language-bash\"><span class=\"hljs-comment\"># At session end</span>\ncurl -X POST .../var -d <span class=\"hljs-string\">&#x27;{&quot;key&quot;: &quot;last_session_at&quot;, &quot;value&quot;: &quot;&#x27;</span>$(<span class=\"hljs-built_in\">date</span> -Iseconds)<span class=\"hljs-string\">&#x27;&quot;}&#x27;</span>\n\n<span class=\"hljs-comment\"># At session start</span>\nLAST=$(curl .../var/last_session_at | jq -r .value)\ncurl .../memory/diff?since=$(<span class=\"hljs-built_in\">date</span> -d <span class=\"hljs-string\">&quot;<span class=\"hljs-variable\">$LAST</span>&quot;</span> +%s)</code></pre><h3>Patrón contador</h3>\n<pre><code class=\"hljs language-bash\"><span class=\"hljs-comment\"># Increment</span>\nN=$(curl .../var/api_calls | jq -r .value)\ncurl -X POST .../var -d <span class=\"hljs-string\">&quot;{\\&quot;key\\&quot;: \\&quot;api_calls\\&quot;, \\&quot;value\\&quot;: <span class=\"hljs-subst\">$((N+1)</span>)}&quot;</span></code></pre><h3>Feature flags</h3>\n<pre><code class=\"hljs language-bash\">curl -X POST .../var -d <span class=\"hljs-string\">&#x27;{&quot;key&quot;: &quot;feature_x_enabled&quot;, &quot;value&quot;: &quot;true&quot;}&#x27;</span>\n\n<span class=\"hljs-comment\"># Check</span>\nENABLED=$(curl .../var/feature_x_enabled | jq -r .value)\n<span class=\"hljs-keyword\">if</span> [ <span class=\"hljs-string\">&quot;<span class=\"hljs-variable\">$ENABLED</span>&quot;</span> = <span class=\"hljs-string\">&quot;true&quot;</span> ]; <span class=\"hljs-keyword\">then</span> ... <span class=\"hljs-keyword\">fi</span></code></pre><h2>Próximos pasos</h2>\n<ul>\n<li><a href=\"/docs/api/memory\">API de Memory</a> — para datos estructurados y buscables</li>\n<li><a href=\"/docs/api/cron\">Cron y Scheduler</a></li>\n</ul>\n","urls":{"html":"/docs/api/variables","text":"/docs/api/variables?format=text","json":"/docs/api/variables?format=json","llm":"/docs/api/variables?format=llm"},"translations_available":["en","zh","hi","es","fr","ar","pt","ru","ja","de","it","ko","nl","pl","tr","sv","vi","th","id","uk"]}