{
  "openapi": "3.1.0",
  "info": {
    "title": "Synapse Memory API",
    "version": "2026-05-20",
    "description": "Persistent memory for AI agents. Zero LLM calls per write."
  },
  "servers": [
    {
      "url": "https://synapse.by-kit.com"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/api/v1/record": {
      "post": {
        "operationId": "synapse_remember",
        "summary": "Store a memory",
        "description": "Persist a memory record to Synapse. No LLM call is made — the body is stored directly in Postgres and classified by a local model.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["agent_id", "title", "body", "type"],
                "properties": {
                  "agent_id": {
                    "type": "string",
                    "description": "Unique identifier for the agent or user. Memories are namespaced by agent_id."
                  },
                  "title": {
                    "type": "string",
                    "description": "Short summary title for this memory (1-2 sentences)."
                  },
                  "body": {
                    "type": "string",
                    "description": "Full content of the memory. Maximum 64KB.",
                    "maxLength": 65536
                  },
                  "type": {
                    "type": "string",
                    "enum": ["fact", "decision", "exchange", "deliverable", "open_item", "signal"],
                    "description": "Memory classification type. Use 'fact' for preferences/context, 'decision' for choices made, 'exchange' for conversation turns, 'deliverable' for outputs, 'open_item' for follow-ups, 'signal' for behavioral indicators."
                  },
                  "client": {
                    "type": "string",
                    "description": "Optional client or project identifier for multi-tenant use."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Memory stored successfully.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid",
                      "description": "Unique ID of the created memory record."
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time",
                      "description": "ISO 8601 timestamp of when the record was created."
                    },
                    "tenant_id": {
                      "type": "string",
                      "format": "uuid",
                      "description": "Tenant ID associated with your API key."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — missing required fields or invalid type."
          },
          "401": {
            "description": "Unauthorized — invalid or missing API key."
          },
          "413": {
            "description": "Payload too large — body exceeds 64KB limit."
          },
          "429": {
            "description": "Rate limit exceeded — too many requests."
          },
          "507": {
            "description": "Insufficient storage — monthly record quota exceeded."
          }
        }
      }
    },
    "/api/v1/query": {
      "get": {
        "operationId": "synapse_recall",
        "summary": "Search memories",
        "description": "Full-text search across all memories for the given agent. Returns the most relevant records, optionally filtered by type or date.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Full-text search query. Omit to retrieve recent records without filtering."
          },
          {
            "name": "agent_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Filter results to a specific agent or user namespace."
          },
          {
            "name": "type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": ["fact", "decision", "exchange", "deliverable", "open_item", "signal"]
            },
            "description": "Filter by memory type."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            },
            "description": "Maximum number of records to return (1–100, default 20)."
          },
          {
            "name": "since",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "ISO 8601 date (YYYY-MM-DD). Only return records created on or after this date."
          }
        ],
        "responses": {
          "200": {
            "description": "Array of matching memory records, ranked by relevance.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "agent_id": {
                        "type": "string"
                      },
                      "type": {
                        "type": "string"
                      },
                      "title": {
                        "type": "string"
                      },
                      "body": {
                        "type": "string"
                      },
                      "client": {
                        "type": "string"
                      },
                      "created_at": {
                        "type": "string",
                        "format": "date-time"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized — invalid or missing API key."
          },
          "429": {
            "description": "Rate limit exceeded — too many requests."
          },
          "500": {
            "description": "Internal server error."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API Key",
        "description": "Pass your Synapse API key as a Bearer token: Authorization: Bearer sk_syn_your_key_here"
      }
    }
  }
}
