{
  "openapi": "3.0.3",
  "info": {
    "title": "Neuroadapt API",
    "version": "1.0.0",
    "description": "Neuroadapt is a local, non-LLM memory and reasoning API exposed through an authenticating go-proxy. It stores session-scoped events, retrieves relevant evidence, exposes concept-level reasoning signals, and keeps enough state for frontend clients to inspect what the system knows.\n\n## Authentication\n\nSend `Authorization: Bearer <secretToken>`. The proxy looks the token up in the MongoDB `agents` collection and **forces `session_id = agentId` on every request**. Any `session_id` you put in the body (or in the `/memz/memories/{session_id}` path) is overwritten by the proxy, so the value you send is a placeholder. A missing or invalid token returns `401`.\n\nThe core memory endpoints do not call an LLM; the OpenAI-compatible chat route is present only for compatibility.\n\n## API prefix\n\nThe versioned API is served under `/api/v1`. Equivalent bowtie-compatible prefixes are also available: `/public/rei-ai-bowtie/v4` and `/rei-ai-bowtie/v4`."
  },
  "servers": [
    {
      "url": "https://rei-neuroadapt-api.reilabs.org",
      "description": "UAT (proxied, authenticated)"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Unit API Key mapped to an agent in the `agents` collection. The proxy forces `session_id = agentId`."
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Missing or invalid bearer token.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object"
            },
            "example": {
              "detail": "Unauthorized"
            }
          }
        }
      }
    },
    "schemas": {
      "DomainClearRequest": {
        "properties": {
          "session_id": {
            "title": "Session Id",
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false,
        "type": "object",
        "title": "DomainClearRequest"
      },
      "HTTPValidationError": {
        "properties": {
          "detail": {
            "items": {
              "$ref": "#/components/schemas/ValidationError"
            },
            "type": "array",
            "title": "Detail"
          }
        },
        "type": "object",
        "title": "HTTPValidationError"
      },
      "MemoryBatchStoreRequest": {
        "properties": {
          "session_id": {
            "title": "Session Id",
            "type": "string",
            "nullable": true
          },
          "items": {
            "items": {
              "$ref": "#/components/schemas/MemoryStoreRequest"
            },
            "type": "array",
            "maxItems": 50,
            "minItems": 1,
            "title": "Items"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": ["items"],
        "title": "MemoryBatchStoreRequest"
      },
      "MemoryCorrectRequest": {
        "properties": {
          "session_id": {
            "type": "string",
            "minLength": 1,
            "title": "Session Id"
          },
          "user_message": {
            "type": "string",
            "minLength": 1,
            "title": "User Message"
          },
          "ai_message": {
            "type": "string",
            "title": "Ai Message",
            "default": ""
          },
          "context": {
            "title": "Context",
            "additionalProperties": true,
            "type": "object",
            "nullable": true
          },
          "memory_id": {
            "type": "string",
            "minLength": 1,
            "title": "Memory Id"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": ["session_id", "user_message", "memory_id"],
        "title": "MemoryCorrectRequest"
      },
      "MemoryPruneRequest": {
        "properties": {
          "session_id": {
            "type": "string",
            "minLength": 1,
            "title": "Session Id"
          },
          "dry_run": {
            "type": "boolean",
            "title": "Dry Run",
            "default": true
          },
          "max_records": {
            "title": "Max Records",
            "type": "integer",
            "minimum": 0.0,
            "nullable": true
          },
          "max_bytes": {
            "title": "Max Bytes",
            "type": "integer",
            "minimum": 0.0,
            "nullable": true
          },
          "include_unique": {
            "type": "boolean",
            "title": "Include Unique",
            "default": false
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": ["session_id"],
        "title": "MemoryPruneRequest"
      },
      "MemoryQueryRequest": {
        "properties": {
          "session_id": {
            "type": "string",
            "minLength": 1,
            "title": "Session Id"
          },
          "user_message": {
            "type": "string",
            "minLength": 1,
            "title": "User Message"
          },
          "top_k": {
            "type": "integer",
            "maximum": 100.0,
            "minimum": 1.0,
            "title": "Top K",
            "default": 10
          },
          "include_reasoning": {
            "type": "boolean",
            "title": "Include Reasoning",
            "default": false
          },
          "metadata_filter": {
            "title": "Metadata Filter",
            "additionalProperties": true,
            "type": "object",
            "nullable": true
          },
          "update_memory_state": {
            "type": "boolean",
            "title": "Update Memory State",
            "default": true
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": ["session_id", "user_message"],
        "title": "MemoryQueryRequest"
      },
      "MemorySessionRequest": {
        "properties": {
          "session_id": {
            "type": "string",
            "minLength": 1,
            "title": "Session Id"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": ["session_id"],
        "title": "MemorySessionRequest"
      },
      "MemoryStoreRequest": {
        "properties": {
          "session_id": {
            "type": "string",
            "minLength": 1,
            "title": "Session Id"
          },
          "user_message": {
            "type": "string",
            "minLength": 1,
            "title": "User Message"
          },
          "ai_message": {
            "type": "string",
            "title": "Ai Message",
            "default": ""
          },
          "context": {
            "title": "Context",
            "additionalProperties": true,
            "type": "object",
            "nullable": true
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": ["session_id", "user_message"],
        "title": "MemoryStoreRequest"
      },
      "ValidationError": {
        "properties": {
          "loc": {
            "items": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "integer"
                }
              ]
            },
            "type": "array",
            "title": "Location"
          },
          "msg": {
            "type": "string",
            "title": "Message"
          },
          "type": {
            "type": "string",
            "title": "Error Type"
          },
          "input": {
            "title": "Input"
          },
          "ctx": {
            "type": "object",
            "title": "Context"
          }
        },
        "type": "object",
        "required": ["loc", "msg", "type"],
        "title": "ValidationError"
      }
    }
  },
  "tags": [
    {
      "name": "System",
      "description": "Health and version checks. Public — no auth required (passed through by the proxy)."
    },
    {
      "name": "Memory",
      "description": "Session-scoped, non-LLM memory and reasoning endpoints (/api/v1/memory/*)."
    },
    {
      "name": "Domains",
      "description": "Closed-source expansion surface. Declare schemas, rules, events, queries, and feedback over HTTP (/api/v1/domains/*)."
    },
    {
      "name": "Legacy",
      "description": "Low-level memory API (/memz/*)."
    },
    {
      "name": "Chat",
      "description": "OpenAI-compatible chat completion route. Use only when you explicitly want the chat pipeline."
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "summary": "Health check (readiness)",
        "tags": ["System"],
        "security": [],
        "responses": {
          "200": {
            "description": "Service is ready.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "status": "ok",
                  "service": "neuroadapt"
                }
              }
            }
          }
        }
      }
    },
    "/healthz": {
      "get": {
        "summary": "Health check (liveness)",
        "tags": ["System"],
        "security": [],
        "responses": {
          "200": {
            "description": "Service is alive.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "status": "ok",
                  "service": "neuroadapt"
                }
              }
            }
          }
        }
      }
    },
    "/version": {
      "get": {
        "summary": "Service version",
        "tags": ["System"],
        "security": [],
        "responses": {
          "200": {
            "description": "Version information.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "service": "neuroadapt",
                  "version": "1.0.0"
                }
              }
            }
          }
        }
      }
    },
    "/memz/store": {
      "post": {
        "summary": "Store memory",
        "description": "Low-level store. `session_id` is overwritten by the proxy with the agent ID resolved from the bearer token.",
        "tags": ["Legacy"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["payload"],
                "properties": {
                  "session_id": {
                    "type": "string",
                    "description": "Placeholder — overwritten by the proxy with the agent ID."
                  },
                  "payload": {
                    "type": "string",
                    "description": "Content to remember."
                  },
                  "metadata": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              },
              "example": {
                "session_id": "ignored",
                "payload": "Alice works at Reilabs and lives in Singapore.",
                "metadata": {
                  "source": "http-test"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Stored.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "status": "success",
                  "memory_id": "memory-uuid",
                  "accepted": true,
                  "action": "stored"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/memz/query": {
      "post": {
        "summary": "Query memory",
        "description": "Low-level query. `session_id` is overwritten by the proxy with the agent ID.",
        "tags": ["Legacy"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["payload"],
                "properties": {
                  "session_id": {
                    "type": "string",
                    "description": "Placeholder — overwritten by the proxy."
                  },
                  "payload": {
                    "type": "string"
                  },
                  "top_k": {
                    "type": "integer",
                    "default": 5
                  },
                  "metadata_filter": {
                    "type": "object",
                    "additionalProperties": true,
                    "nullable": true
                  }
                }
              },
              "example": {
                "session_id": "ignored",
                "payload": "Where does Alice work?",
                "top_k": 5,
                "metadata_filter": null
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Query result.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "memory_context": [],
                  "confidence_score": 0.0
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/memz/memories/{session_id}": {
      "get": {
        "summary": "List memories",
        "description": "Lists memories for the session. The path `session_id` is overwritten by the proxy with the agent ID.",
        "tags": ["Legacy"],
        "parameters": [
          {
            "name": "session_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Placeholder — overwritten by the proxy.",
            "example": "ignored"
          }
        ],
        "responses": {
          "200": {
            "description": "Stored memories for the session.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "items": []
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "delete": {
        "summary": "Clear all memories",
        "description": "Clears all memories for the session. The path `session_id` is overwritten by the proxy with the agent ID.",
        "tags": ["Legacy"],
        "parameters": [
          {
            "name": "session_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Placeholder — overwritten by the proxy.",
            "example": "ignored"
          }
        ],
        "responses": {
          "200": {
            "description": "Cleared.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "status": "success",
                  "deleted": 1
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/memz/memories/{session_id}/{memory_id}": {
      "delete": {
        "summary": "Delete a single memory",
        "description": "Deletes one memory by ID. The path `session_id` is overwritten by the proxy with the agent ID.",
        "tags": ["Legacy"],
        "parameters": [
          {
            "name": "session_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Placeholder — overwritten by the proxy.",
            "example": "ignored"
          },
          {
            "name": "memory_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "MEMORY_ID_HERE"
          }
        ],
        "responses": {
          "200": {
            "description": "Delete result.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "status": "success",
                  "memory_id": "MEMORY_ID_HERE",
                  "deleted": true
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/v1/memory/store": {
      "post": {
        "summary": "Store interaction",
        "description": "Stores one user-facing memory item. `session_id` is overwritten by the proxy with the agent ID.",
        "tags": ["Memory"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["user_message"],
                "properties": {
                  "session_id": {
                    "type": "string",
                    "description": "Placeholder — overwritten by the proxy."
                  },
                  "user_message": {
                    "type": "string",
                    "description": "User-facing content to remember."
                  },
                  "ai_message": {
                    "type": "string",
                    "description": "Optional assistant message paired with the user message."
                  },
                  "context": {
                    "type": "object",
                    "additionalProperties": true,
                    "description": "Arbitrary metadata stored with the memory."
                  }
                }
              },
              "example": {
                "session_id": "ignored",
                "user_message": "Alice works at Reilabs and lives in Singapore.",
                "ai_message": "Got it, I'll remember that about Alice.",
                "context": {
                  "source": "http-test"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Memory stored.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "status": "success",
                  "session_id": "agent-id",
                  "interaction_id": "memory-uuid",
                  "concepts_extracted": 0,
                  "extracted_concepts": [],
                  "storage_result": {
                    "backend": "neuroadapt-local",
                    "memory_id": "memory-uuid",
                    "session_id": "agent-id",
                    "accepted": true,
                    "action": "stored"
                  },
                  "timestamp": 1782200000.0
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/v1/memory/query": {
      "post": {
        "summary": "Memory Query",
        "operationId": "memory_query_api_v1_memory_query_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MemoryQueryRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "additionalProperties": true,
                  "type": "object",
                  "title": "Response Memory Query Api V1 Memory Query Post"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        },
        "tags": ["Memory"]
      }
    },
    "/api/v1/memory/search": {
      "post": {
        "summary": "Search memory",
        "description": "Returns ranked evidence without the full reasoning payload.",
        "tags": ["Memory"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["user_message"],
                "properties": {
                  "session_id": {
                    "type": "string",
                    "description": "Placeholder — overwritten by the proxy."
                  },
                  "user_message": {
                    "type": "string"
                  },
                  "top_k": {
                    "type": "integer",
                    "default": 10
                  },
                  "metadata_filter": {
                    "type": "object",
                    "additionalProperties": true,
                    "nullable": true
                  }
                }
              },
              "example": {
                "session_id": "ignored",
                "user_message": "Alice",
                "top_k": 10,
                "metadata_filter": null
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ranked evidence items.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "session_id": "agent-id",
                  "query": "Alice",
                  "items": [
                    {
                      "memory_id": "memory-uuid",
                      "content": "Alice works at Reilabs and lives in Singapore.",
                      "summary": "Alice works at Reilabs...",
                      "score": 0.57,
                      "matched_concepts": ["alice"],
                      "metadata": {},
                      "phase": "buffer"
                    }
                  ],
                  "support": {
                    "meta_summary": {},
                    "graph_stats": {},
                    "temporal_patterns": {}
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/v1/memory/explain": {
      "post": {
        "summary": "Explain memory",
        "description": "Returns the structured non-LLM reasoning view: evidence, hypotheses, causal chain, reasoning edges, discovered connections, conflicts, and predicted/missing observations. `score` is a bounded ranking/support score for UI ordering. `confidence` is a capped mechanistic support score, not a calibrated probability.",
        "tags": ["Memory"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["user_message"],
                "properties": {
                  "session_id": {
                    "type": "string",
                    "description": "Placeholder — overwritten by the proxy."
                  },
                  "user_message": {
                    "type": "string"
                  },
                  "top_k": {
                    "type": "integer",
                    "default": 10
                  },
                  "metadata_filter": {
                    "type": "object",
                    "additionalProperties": true,
                    "nullable": true
                  }
                }
              },
              "example": {
                "session_id": "ignored",
                "user_message": "Where does Alice work?",
                "top_k": 10,
                "metadata_filter": null
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Structured reasoning explanation.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "session_id": "agent-id",
                  "query": "Where does Alice work?",
                  "explanation": {
                    "evidence": [
                      {
                        "memory_id": "memory-uuid",
                        "content": "Alice works at Reilabs and lives in Singapore.",
                        "summary": "Alice works at Reilabs...",
                        "score": 0.57,
                        "matched_concepts": ["alice", "reilabs"],
                        "metadata": {
                          "source": "http-test"
                        },
                        "phase": "buffer"
                      }
                    ],
                    "seed_concepts": ["alice", "reilabs"],
                    "activated_concepts": [],
                    "reasoning_edges": [],
                    "discovered_connections": [],
                    "conflicts": [],
                    "resolution": {},
                    "hypotheses": [],
                    "causal_chain": [],
                    "predicted_next_observations": [],
                    "missing_observations": [],
                    "neurosymbolic": {
                      "enabled": true,
                      "used": true,
                      "reasoning_mode": "hybrid"
                    },
                    "graph_stats": {
                      "total_nodes": 0,
                      "total_edges": 0,
                      "total_hyperedges": 0
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/v1/memory/list": {
      "post": {
        "summary": "List memories",
        "tags": ["Memory"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "session_id": {
                    "type": "string",
                    "description": "Placeholder — overwritten by the proxy."
                  }
                }
              },
              "example": {
                "session_id": "ignored"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Stored memory items.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "items": [
                    {
                      "id": "memory-uuid",
                      "content": "Stored content...",
                      "metadata": {},
                      "user_id": "agent-id",
                      "tenant_id": "agent-id",
                      "summary": "Stored content...",
                      "phase": "buffer",
                      "access_count": 1
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/v1/memory/delete": {
      "post": {
        "summary": "Delete a memory",
        "tags": ["Memory"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["memory_id"],
                "properties": {
                  "session_id": {
                    "type": "string",
                    "description": "Placeholder — overwritten by the proxy."
                  },
                  "memory_id": {
                    "type": "string"
                  }
                }
              },
              "example": {
                "session_id": "ignored",
                "memory_id": "MEMORY_ID_HERE"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Delete result. `status` is `success` when deleted, or `not_found` when the memory is not in that session.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "examples": {
                  "deleted": {
                    "summary": "Memory deleted",
                    "value": {
                      "status": "success",
                      "session_id": "agent-id",
                      "memory_id": "memory-uuid",
                      "deleted": true
                    }
                  },
                  "not_found": {
                    "summary": "Memory not found in session",
                    "value": {
                      "status": "not_found",
                      "session_id": "agent-id",
                      "memory_id": "memory-uuid",
                      "deleted": false
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/v1/memory/clear": {
      "post": {
        "summary": "Clear session",
        "tags": ["Memory"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "session_id": {
                    "type": "string",
                    "description": "Placeholder — overwritten by the proxy."
                  }
                }
              },
              "example": {
                "session_id": "ignored"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Clear result.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "status": "success",
                  "session_id": "agent-id",
                  "deleted": 1
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/v1/memory/state": {
      "post": {
        "summary": "Session state",
        "description": "Returns the current session memory state without running a query.",
        "tags": ["Memory"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "session_id": {
                    "type": "string",
                    "description": "Placeholder — overwritten by the proxy."
                  }
                }
              },
              "example": {
                "session_id": "ignored"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Current session state.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "session_id": "agent-id",
                  "memory_count": 1,
                  "items": [],
                  "meta_summary": {},
                  "temporal_patterns": {},
                  "graph_stats": {},
                  "rhm": {},
                  "ml": {
                    "embedding_dims": 384,
                    "document_count": 1,
                    "centroids": 1
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/v1/domains": {
      "post": {
        "summary": "Create domain",
        "tags": ["Domains"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["domain_id"],
                "properties": {
                  "domain_id": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string"
                  },
                  "schema": {
                    "type": "object",
                    "additionalProperties": true
                  },
                  "hypotheses": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": true
                    }
                  },
                  "query_templates": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              },
              "example": {
                "domain_id": "demo-domain",
                "description": "Demo domain for HTTP testing",
                "schema": {},
                "hypotheses": [],
                "query_templates": {}
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Domain registered.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "status": "success",
                  "domain_id": "demo-domain"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "get": {
        "summary": "List domains",
        "tags": ["Domains"],
        "responses": {
          "200": {
            "description": "Registered domains.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "domains": ["demo-domain"]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/v1/domains/{domain_id}": {
      "get": {
        "summary": "Get a domain",
        "tags": ["Domains"],
        "parameters": [
          {
            "name": "domain_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "demo-domain"
          }
        ],
        "responses": {
          "200": {
            "description": "Domain definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "domain_id": "demo-domain",
                  "description": "Demo domain for HTTP testing",
                  "schema": {},
                  "hypotheses": [],
                  "query_templates": {}
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "delete": {
        "summary": "Domain Delete",
        "operationId": "domain_delete_api_v1_domains__domain_id__delete",
        "parameters": [
          {
            "name": "domain_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Domain Id"
            }
          },
          {
            "name": "session_id",
            "in": "query",
            "required": false,
            "schema": {
              "title": "Session Id",
              "type": "string",
              "nullable": true
            }
          },
          {
            "name": "X-Neuroadapt-Session-Id",
            "in": "header",
            "required": false,
            "schema": {
              "title": "X-Neuroadapt-Session-Id",
              "type": "string",
              "nullable": true
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true,
                  "title": "Response Domain Delete Api V1 Domains  Domain Id  Delete"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        },
        "tags": ["Domains"]
      }
    },
    "/api/v1/domains/{domain_id}/schemas": {
      "post": {
        "summary": "Update domain schema",
        "tags": ["Domains"],
        "parameters": [
          {
            "name": "domain_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "demo-domain"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "schema": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              },
              "example": {
                "schema": {}
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Schema updated.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "status": "success",
                  "domain_id": "demo-domain"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/v1/domains/{domain_id}/rules": {
      "post": {
        "summary": "Update domain rules",
        "tags": ["Domains"],
        "parameters": [
          {
            "name": "domain_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "demo-domain"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "hypotheses": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": true
                    }
                  },
                  "query_templates": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              },
              "example": {
                "hypotheses": [],
                "query_templates": {}
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Rules updated.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "status": "success",
                  "domain_id": "demo-domain"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/v1/domains/{domain_id}/events": {
      "post": {
        "summary": "Ingest domain event",
        "tags": ["Domains"],
        "parameters": [
          {
            "name": "domain_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "demo-domain"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["event_type"],
                "properties": {
                  "session_id": {
                    "type": "string",
                    "description": "Placeholder — overwritten by the proxy."
                  },
                  "event_type": {
                    "type": "string"
                  },
                  "timestamp": {
                    "type": "string",
                    "format": "date-time",
                    "nullable": true
                  },
                  "entities": {
                    "type": "object",
                    "additionalProperties": true
                  },
                  "values": {
                    "type": "object",
                    "additionalProperties": true
                  },
                  "relations": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": true
                    }
                  },
                  "text": {
                    "type": "string"
                  },
                  "metadata": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              },
              "example": {
                "session_id": "ignored",
                "event_type": "observation",
                "timestamp": null,
                "entities": {},
                "values": {},
                "relations": [],
                "text": "An example event",
                "metadata": {}
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Event stored.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "status": "success",
                  "domain_id": "demo-domain",
                  "session_id": "agent-id",
                  "event_type": "observation",
                  "memory_id": "memory-uuid",
                  "summary": "Stored event summary...",
                  "accepted": true,
                  "action": "stored"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/v1/domains/{domain_id}/query": {
      "post": {
        "summary": "Query domain",
        "tags": ["Domains"],
        "parameters": [
          {
            "name": "domain_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "demo-domain"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["question"],
                "properties": {
                  "session_id": {
                    "type": "string",
                    "description": "Placeholder — overwritten by the proxy."
                  },
                  "question": {
                    "type": "string"
                  },
                  "top_k": {
                    "type": "integer",
                    "default": 10
                  },
                  "return_fields": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "nullable": true
                  },
                  "metadata_filter": {
                    "type": "object",
                    "additionalProperties": true,
                    "nullable": true
                  }
                }
              },
              "example": {
                "session_id": "ignored",
                "question": "What happened?",
                "top_k": 10,
                "return_fields": null,
                "metadata_filter": null
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Domain query result.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "domain_id": "demo-domain",
                  "session_id": "agent-id",
                  "question": "What happened?",
                  "items": [],
                  "ranked_hypotheses": [],
                  "supporting_memories": [],
                  "missing_evidence": [],
                  "predicted_observations": []
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/v1/domains/{domain_id}/feedback": {
      "post": {
        "summary": "Domain feedback",
        "tags": ["Domains"],
        "parameters": [
          {
            "name": "domain_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "demo-domain"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["outcome"],
                "properties": {
                  "session_id": {
                    "type": "string",
                    "description": "Placeholder — overwritten by the proxy."
                  },
                  "outcome": {
                    "type": "string",
                    "example": "correct"
                  },
                  "target_memory_id": {
                    "type": "string",
                    "nullable": true
                  },
                  "values": {
                    "type": "object",
                    "additionalProperties": true
                  },
                  "text": {
                    "type": "string"
                  },
                  "metadata": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              },
              "example": {
                "session_id": "ignored",
                "outcome": "correct",
                "target_memory_id": null,
                "values": {},
                "text": "",
                "metadata": {}
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Feedback recorded.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "status": "success",
                  "domain_id": "demo-domain",
                  "session_id": "agent-id"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/v1/domains/{domain_id}/explain": {
      "post": {
        "summary": "Explain domain query",
        "description": "Returns schema, ranked hypotheses, supporting memories, missing evidence, predicted observations, and core Neuroadapt reasoning support.",
        "tags": ["Domains"],
        "parameters": [
          {
            "name": "domain_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "demo-domain"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["question"],
                "properties": {
                  "session_id": {
                    "type": "string",
                    "description": "Placeholder — overwritten by the proxy."
                  },
                  "question": {
                    "type": "string"
                  },
                  "top_k": {
                    "type": "integer",
                    "default": 10
                  },
                  "metadata_filter": {
                    "type": "object",
                    "additionalProperties": true,
                    "nullable": true
                  }
                }
              },
              "example": {
                "session_id": "ignored",
                "question": "What happened?",
                "top_k": 10,
                "metadata_filter": null
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Domain explanation payload.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "domain_id": "demo-domain",
                  "schema": {},
                  "ranked_hypotheses": [],
                  "supporting_memories": [],
                  "missing_evidence": [],
                  "predicted_observations": [],
                  "core_support": {}
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/v1/domains/{domain_id}/clear": {
      "post": {
        "summary": "Clear domain",
        "tags": ["Domains"],
        "parameters": [
          {
            "name": "domain_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "demo-domain"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "session_id": {
                    "type": "string",
                    "description": "Placeholder — overwritten by the proxy."
                  }
                }
              },
              "example": {
                "session_id": "ignored"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cleared.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "status": "success",
                  "domain_id": "demo-domain",
                  "session_id": "agent-id",
                  "deleted": 1
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/v1/chat/completions": {
      "post": {
        "summary": "Chat completions (OpenAI-compatible)",
        "description": "LLM-style compatibility route. Use only when you explicitly want the chat pipeline; the /api/v1/memory/* and /memz/* routes are the non-LLM memory/reasoning path. `session_id` is overwritten by the proxy with the agent ID.",
        "tags": ["Chat"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["messages"],
                "properties": {
                  "messages": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": ["role", "content"],
                      "properties": {
                        "role": {
                          "type": "string",
                          "enum": ["system", "user", "assistant", "tool"]
                        },
                        "content": {
                          "type": "string"
                        }
                      }
                    }
                  },
                  "session_id": {
                    "type": "string",
                    "description": "Placeholder — overwritten by the proxy."
                  },
                  "top_k": {
                    "type": "integer",
                    "default": 5
                  },
                  "metadata_filter": {
                    "type": "object",
                    "additionalProperties": true,
                    "nullable": true
                  },
                  "model": {
                    "type": "string",
                    "nullable": true
                  }
                }
              },
              "example": {
                "messages": [
                  {
                    "role": "user",
                    "content": "What do you know about Alice?"
                  }
                ],
                "session_id": "ignored",
                "top_k": 5,
                "metadata_filter": null,
                "model": null
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Chat completion result.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "id": "chatcmpl-uuid",
                  "object": "chat.completion",
                  "created": 1782200000,
                  "model": "neuroadapt",
                  "choices": [
                    {
                      "index": 0,
                      "finish_reason": "stop",
                      "message": {
                        "role": "assistant",
                        "content": "..."
                      }
                    }
                  ],
                  "usage": {
                    "prompt_tokens": 0,
                    "completion_tokens": 0,
                    "total_tokens": 0
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/readyz": {
      "get": {
        "summary": "Readyz",
        "operationId": "readyz_readyz_get",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "additionalProperties": true,
                  "type": "object",
                  "title": "Response Readyz Readyz Get"
                }
              }
            }
          }
        },
        "tags": ["System"],
        "security": []
      }
    },
    "/admission": {
      "get": {
        "summary": "Admission Stats",
        "operationId": "admission_stats_admission_get",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "additionalProperties": true,
                  "type": "object",
                  "title": "Response Admission Stats Admission Get"
                }
              }
            }
          }
        },
        "tags": ["System"]
      }
    },
    "/api/v1/memory/correct": {
      "post": {
        "summary": "Memory Correct",
        "operationId": "memory_correct_api_v1_memory_correct_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MemoryCorrectRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "additionalProperties": true,
                  "type": "object",
                  "title": "Response Memory Correct Api V1 Memory Correct Post"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        },
        "tags": ["Memory"]
      }
    },
    "/api/v1/memory/batch_store": {
      "post": {
        "summary": "Memory Batch Store",
        "operationId": "memory_batch_store_api_v1_memory_batch_store_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MemoryBatchStoreRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "additionalProperties": true,
                  "type": "object",
                  "title": "Response Memory Batch Store Api V1 Memory Batch Store Post"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        },
        "tags": ["Memory"]
      }
    },
    "/api/v1/memory/state/summary": {
      "post": {
        "summary": "Memory State Summary",
        "operationId": "memory_state_summary_api_v1_memory_state_summary_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MemorySessionRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "additionalProperties": true,
                  "type": "object",
                  "title": "Response Memory State Summary Api V1 Memory State Summary Post"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        },
        "tags": ["Memory"]
      }
    },
    "/api/v1/memory/prune": {
      "post": {
        "summary": "Memory Prune",
        "operationId": "memory_prune_api_v1_memory_prune_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MemoryPruneRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "additionalProperties": true,
                  "type": "object",
                  "title": "Response Memory Prune Api V1 Memory Prune Post"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        },
        "tags": ["Memory"]
      }
    },
    "/api/v1/domains/{domain_id}/policy/reset": {
      "post": {
        "summary": "Domain Policy Reset",
        "operationId": "domain_policy_reset_api_v1_domains__domain_id__policy_reset_post",
        "parameters": [
          {
            "name": "domain_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Domain Id"
            }
          },
          {
            "name": "X-Neuroadapt-Session-Id",
            "in": "header",
            "required": false,
            "schema": {
              "title": "X-Neuroadapt-Session-Id",
              "type": "string",
              "nullable": true
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DomainClearRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true,
                  "title": "Response Domain Policy Reset Api V1 Domains  Domain Id  Policy Reset Post"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        },
        "tags": ["Domains"]
      }
    }
  }
}
