# Variables API The Variables API is a fast key-value store for ephemeral state. Unlike memories (which are indexed, searchable, and structured), variables are optimized for quick read/write access — perfect for counters, flags, and session state. ## Endpoints ### POST /var Set or update a variable. ```bash curl -X POST https://synapse.schaefer.zone/var \ -H "Authorization: Bearer YOUR_MIND_KEY" \ -H "Content-Type: application/json" \ -d '{"key": "last_session_at", "value": "2026-06-27T14:00:00Z"}' ``` ### GET /var/:key Get a single variable. ```bash curl -H "Authorization: Bearer YOUR_MIND_KEY" \ https://synapse.schaefer.zone/var/last_session_at ``` Response: ```json { "key": "last_session_at", "value": "2026-06-27T14:00:00Z", "updated_at": "..." } ``` ### GET /var List all variables. ```bash curl -H "Authorization: Bearer YOUR_MIND_KEY" \ https://synapse.schaefer.zone/var ``` ### DELETE /var/:key Delete a variable. ```bash curl -X DELETE -H "Authorization: Bearer YOUR_MIND_KEY" \ https://synapse.schaefer.zone/var/last_session_at ``` ## When to Use Variables vs Memory | Use Case | Use | |----------|-----| | User name, preferences | Memory (searchable, structured) | | Last session timestamp | Variable (ephemeral state) | | Counter (e.g. messages sent) | Variable (frequent updates) | | Workflow state ("step 3 of 5 done") | Variable (transient) | | Long-form project notes | Memory (full-text indexed) | | Reusable scripts | Script store (named, versioned) | ## Common Patterns ### Track last session ```bash # At session end curl -X POST .../var -d '{"key": "last_session_at", "value": "'$(date -Iseconds)'"}' # At session start LAST=$(curl .../var/last_session_at | jq -r .value) curl .../memory/diff?since=$(date -d "$LAST" +%s) ``` ### Counter pattern ```bash # Increment N=$(curl .../var/api_calls | jq -r .value) curl -X POST .../var -d "{\"key\": \"api_calls\", \"value\": $((N+1))}" ``` ### Feature flags ```bash curl -X POST .../var -d '{"key": "feature_x_enabled", "value": "true"}' # Check ENABLED=$(curl .../var/feature_x_enabled | jq -r .value) if [ "$ENABLED" = "true" ]; then ... fi ``` ## Next Steps - [Memory API](/docs/api/memory) — for structured, searchable data - [Cron & Scheduler](/docs/api/cron)