{
  "openapi": "3.1.0",
  "info": {
    "title": "Korva Vault API",
    "version": "1.36.2",
    "summary": "Public HTTP API exposed by korva-vault on localhost:7437.",
    "description": "Korva Vault exposes an HTTP API on `localhost:7437` for the CLI,\nthe Beacon dashboard, and external tooling. This document covers\nonly the public surface — admin (`/admin/*`) and team (`/team/*`)\nendpoints require authentication headers and are documented in the\nKorva docs.\n\nAll requests and responses use `application/json`. Time format is\nRFC 3339. IDs are ULIDs (26-char Crockford base32).",
    "contact": {
      "name": "Korva",
      "email": "support@korva.dev",
      "url": "https://korva.dev"
    },
    "license": {
      "name": "MIT",
      "identifier": "MIT"
    }
  },
  "servers": [
    {
      "url": "http://localhost:7437",
      "description": "Local Vault (default)"
    },
    {
      "url": "https://vault.example.com",
      "description": "Self-hosted shared Vault (substitute your own host)"
    }
  ],
  "externalDocs": {
    "url": "https://korva.dev/docs/api",
    "description": "Public REST API guide"
  },
  "tags": [
    {
      "name": "Health",
      "description": "Liveness, status, metrics."
    },
    {
      "name": "Observations",
      "description": "The vault's atomic unit of memory."
    },
    {
      "name": "Sessions",
      "description": "Tracked AI work sessions."
    },
    {
      "name": "Prompts",
      "description": "Reusable prompt templates."
    },
    {
      "name": "Hive",
      "description": "Optional cross-team sync worker."
    },
    {
      "name": "OpenSpec",
      "description": "Per-project conventions."
    },
    {
      "name": "SDD",
      "description": "Spec-Driven Development phase state."
    },
    {
      "name": "Auth boundary",
      "description": "Public endpoints used to redeem invites and manage sessions."
    }
  ],
  "paths": {
    "/healthz": {
      "get": {
        "tags": [
          "Health"
        ],
        "summary": "Liveness probe",
        "operationId": "getHealthz",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                },
                "example": {
                  "status": "ok"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/status": {
      "get": {
        "tags": [
          "Health"
        ],
        "summary": "Server status snapshot",
        "operationId": "getStatus",
        "responses": {
          "200": {
            "description": "Status snapshot",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Status"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/metrics": {
      "get": {
        "tags": [
          "Health"
        ],
        "summary": "Prometheus-format metrics",
        "operationId": "getMetrics",
        "responses": {
          "200": {
            "description": "Prometheus metrics text",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/observations/{id}": {
      "get": {
        "tags": [
          "Observations"
        ],
        "summary": "Fetch an observation by ULID",
        "operationId": "getObservation",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "ulid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Observation"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/api/v1/observations": {
      "post": {
        "tags": [
          "Observations"
        ],
        "summary": "Save an observation",
        "description": "Subject to the privacy filter and dedup. Same-session content_hash collisions are silently dropped.",
        "operationId": "saveObservation",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SaveObservationRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved (or deduplicated)",
            "content": {
              "application/json": {
                "oneOf": [
                  {
                    "schema": {
                      "$ref": "#/components/schemas/SaveObservationResponse"
                    }
                  },
                  {
                    "schema": {
                      "$ref": "#/components/schemas/DeduplicatedResponse"
                    }
                  }
                ]
              }
            }
          },
          "400": {
            "description": "Invalid payload"
          },
          "429": {
            "description": "Rate limit exceeded"
          }
        }
      }
    },
    "/api/v1/search": {
      "get": {
        "tags": [
          "Observations"
        ],
        "summary": "Full-text search (FTS5)",
        "operationId": "searchObservations",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Search query, supports FTS5 syntax."
          },
          {
            "name": "cloud",
            "in": "query",
            "schema": {
              "type": "integer",
              "enum": [
                0,
                1
              ]
            },
            "description": "Set to 1 for hybrid local + Hive search."
          },
          {
            "name": "project",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/ObservationType"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Search results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Observation"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/context/{project}": {
      "get": {
        "tags": [
          "Observations"
        ],
        "summary": "Recent observations for a project",
        "operationId": "getContext",
        "parameters": [
          {
            "name": "project",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Context",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Observation"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/timeline/{project}": {
      "get": {
        "tags": [
          "Observations"
        ],
        "summary": "Date-range query",
        "operationId": "getTimeline",
        "parameters": [
          {
            "name": "project",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Timeline"
          }
        }
      }
    },
    "/api/v1/summary/{project}": {
      "get": {
        "tags": [
          "Observations"
        ],
        "summary": "High-level project summary",
        "operationId": "getSummary",
        "parameters": [
          {
            "name": "project",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Summary"
          }
        }
      }
    },
    "/api/v1/stats": {
      "get": {
        "tags": [
          "Observations"
        ],
        "summary": "Global statistics",
        "operationId": "getStats",
        "responses": {
          "200": {
            "description": "Stats"
          }
        }
      }
    },
    "/api/v1/sessions": {
      "post": {
        "tags": [
          "Sessions"
        ],
        "summary": "Start a tracked session",
        "operationId": "startSession",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/StartSessionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Started"
          }
        }
      }
    },
    "/api/v1/sessions/{id}": {
      "put": {
        "tags": [
          "Sessions"
        ],
        "summary": "End a session with a summary",
        "operationId": "endSession",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "ulid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "summary": {
                    "type": "string"
                  }
                },
                "required": [
                  "summary"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ended"
          }
        }
      }
    },
    "/api/v1/sessions/all": {
      "get": {
        "tags": [
          "Sessions"
        ],
        "summary": "List all sessions",
        "operationId": "listSessions",
        "responses": {
          "200": {
            "description": "Sessions"
          }
        }
      }
    },
    "/api/v1/prompts": {
      "post": {
        "tags": [
          "Prompts"
        ],
        "summary": "Save a prompt template",
        "operationId": "savePrompt",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "content"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "content": {
                    "type": "string"
                  },
                  "tags": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved"
          }
        }
      }
    },
    "/api/v1/openspec/{project}": {
      "get": {
        "tags": [
          "OpenSpec"
        ],
        "summary": "Project conventions",
        "operationId": "getOpenSpec",
        "parameters": [
          {
            "name": "project",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OpenSpec"
          }
        }
      }
    },
    "/api/v1/sdd/{project}": {
      "get": {
        "tags": [
          "SDD"
        ],
        "summary": "Current SDD phase for a project",
        "operationId": "getSddPhase",
        "parameters": [
          {
            "name": "project",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "SDD state"
          }
        }
      }
    },
    "/api/v1/hive/status": {
      "get": {
        "tags": [
          "Hive"
        ],
        "summary": "Hive worker state",
        "operationId": "getHiveStatus",
        "responses": {
          "200": {
            "description": "Worker state"
          }
        }
      }
    },
    "/auth/redeem": {
      "post": {
        "tags": [
          "Auth boundary"
        ],
        "summary": "Redeem an invite token for a session token",
        "operationId": "redeemInvite",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "token"
                ],
                "properties": {
                  "token": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Session token",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "session_token": {
                      "type": "string"
                    },
                    "expires_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid invite token"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "sessionToken": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Session-Token",
        "description": "Required by /auth/me, /auth/session, and /team/* endpoints (not documented here)."
      }
    },
    "schemas": {
      "Health": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "ok"
            ]
          }
        },
        "required": [
          "status"
        ]
      },
      "Status": {
        "type": "object",
        "properties": {
          "version": {
            "type": "string"
          },
          "uptime_seconds": {
            "type": "integer"
          },
          "tier": {
            "type": "string",
            "enum": [
              "community",
              "teams"
            ]
          },
          "observations_total": {
            "type": "integer"
          }
        },
        "required": [
          "version",
          "uptime_seconds",
          "tier"
        ]
      },
      "ObservationType": {
        "type": "string",
        "enum": [
          "decision",
          "pattern",
          "bugfix",
          "learning",
          "context",
          "antipattern",
          "task",
          "feature",
          "refactor",
          "discovery"
        ]
      },
      "Observation": {
        "type": "object",
        "required": [
          "id",
          "type",
          "title",
          "content",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "ulid"
          },
          "session_id": {
            "type": "string",
            "format": "ulid",
            "nullable": true
          },
          "project": {
            "type": "string"
          },
          "team": {
            "type": "string"
          },
          "country": {
            "type": "string"
          },
          "type": {
            "$ref": "#/components/schemas/ObservationType"
          },
          "title": {
            "type": "string",
            "maxLength": 100
          },
          "content": {
            "type": "string"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "author": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "SaveObservationRequest": {
        "type": "object",
        "required": [
          "title",
          "content",
          "type"
        ],
        "properties": {
          "title": {
            "type": "string",
            "maxLength": 100
          },
          "content": {
            "type": "string"
          },
          "type": {
            "$ref": "#/components/schemas/ObservationType"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "project": {
            "type": "string"
          },
          "team": {
            "type": "string"
          },
          "country": {
            "type": "string"
          },
          "author": {
            "type": "string"
          },
          "session_id": {
            "type": "string",
            "format": "ulid"
          },
          "dry_run": {
            "type": "boolean",
            "default": false
          },
          "force": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "SaveObservationResponse": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "ulid"
          }
        }
      },
      "DeduplicatedResponse": {
        "type": "object",
        "required": [
          "deduplicated",
          "existing_id"
        ],
        "properties": {
          "deduplicated": {
            "type": "boolean",
            "enum": [
              true
            ]
          },
          "existing_id": {
            "type": "string",
            "format": "ulid"
          }
        }
      },
      "StartSessionRequest": {
        "type": "object",
        "required": [
          "project"
        ],
        "properties": {
          "project": {
            "type": "string"
          },
          "team": {
            "type": "string"
          },
          "country": {
            "type": "string"
          },
          "agent": {
            "type": "string",
            "description": "AI assistant name (claude-code, cursor, …)"
          },
          "goal": {
            "type": "string"
          }
        }
      }
    }
  }
}