{
  "openapi": "3.1.0",
  "info": {
    "title": "KorClaw API",
    "version": "1.0.0",
    "description": "AI-native compliance infrastructure. Govern agents, enforce policies, manage approvals, and maintain immutable audit trails.",
    "contact": {
      "name": "KorClaw Support",
      "email": "founder@korclaw.com",
      "url": "https://korclaw.com"
    },
    "license": {
      "name": "Proprietary"
    }
  },
  "servers": [
    {
      "url": "https://app.korclaw.com/api/v1",
      "description": "Production"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "x-rate-limits": {
    "window": "1 minute",
    "tiers": {
      "free": 60,
      "pro": 300,
      "business": 1000,
      "enterprise": "configurable"
    },
    "headers": [
      "RateLimit-Limit",
      "RateLimit-Remaining",
      "RateLimit-Reset",
      "Retry-After"
    ]
  },
  "tags": [
    {
      "name": "Agents",
      "description": "AI agent registration and management"
    },
    {
      "name": "Policies",
      "description": "Compliance policy management"
    },
    {
      "name": "Approvals",
      "description": "Human approval workflows"
    },
    {
      "name": "Audit",
      "description": "Immutable audit events"
    },
    {
      "name": "Reports",
      "description": "Compliance reports"
    },
    {
      "name": "Usage",
      "description": "Platform usage metrics"
    },
    {
      "name": "Organizations",
      "description": "Workspace organizations"
    },
    {
      "name": "Billing",
      "description": "Subscription status"
    },
    {
      "name": "Health",
      "description": "API health"
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "tags": [
          "Health"
        ],
        "summary": "Check API health",
        "operationId": "getHealth",
        "security": [],
        "responses": {
          "200": {
            "description": "Healthy API response"
          }
        }
      }
    },
    "/organizations": {
      "get": {
        "tags": [
          "Organizations"
        ],
        "summary": "List organizations",
        "operationId": "listOrganizations",
        "responses": {
          "200": {
            "description": "Organizations"
          }
        }
      },
      "post": {
        "tags": [
          "Organizations"
        ],
        "summary": "Create organization",
        "operationId": "createOrganization",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 120
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Organization created"
          },
          "422": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/agents": {
      "get": {
        "tags": [
          "Agents"
        ],
        "summary": "List agents",
        "description": "Returns all AI agents in the workspace.",
        "operationId": "listAgents",
        "responses": {
          "200": {
            "description": "List of agents",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentList"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "tags": [
          "Agents"
        ],
        "summary": "Register agent",
        "description": "Register a new AI agent.",
        "operationId": "createAgent",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateAgentRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Agent created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Agent"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/agents/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Agents"
        ],
        "summary": "Retrieve agent",
        "operationId": "retrieveAgent",
        "responses": {
          "200": {
            "description": "Agent",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Agent"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "patch": {
        "tags": [
          "Agents"
        ],
        "summary": "Update agent",
        "operationId": "updateAgent",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateAgentRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated agent"
          }
        }
      },
      "delete": {
        "tags": [
          "Agents"
        ],
        "summary": "Delete agent",
        "operationId": "deleteAgent",
        "responses": {
          "200": {
            "description": "Deletion result"
          }
        }
      }
    },
    "/policies": {
      "get": {
        "tags": [
          "Policies"
        ],
        "summary": "List policies",
        "operationId": "listPolicies",
        "responses": {
          "200": {
            "description": "List of policies",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PolicyList"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Policies"
        ],
        "summary": "Create policy",
        "operationId": "createPolicy",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreatePolicyRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Policy created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Policy"
                }
              }
            }
          }
        }
      }
    },
    "/policies/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Policies"
        ],
        "summary": "Retrieve policy",
        "operationId": "retrievePolicy",
        "responses": {
          "200": {
            "description": "Policy"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "patch": {
        "tags": [
          "Policies"
        ],
        "summary": "Update or toggle policy",
        "operationId": "updatePolicy",
        "responses": {
          "200": {
            "description": "Updated policy"
          }
        }
      },
      "delete": {
        "tags": [
          "Policies"
        ],
        "summary": "Delete policy",
        "operationId": "deletePolicy",
        "responses": {
          "200": {
            "description": "Deletion result"
          }
        }
      }
    },
    "/approval/request": {
      "post": {
        "tags": [
          "Approvals"
        ],
        "summary": "Create approval request",
        "operationId": "createApproval",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateApprovalRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Approval created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Approval"
                }
              }
            }
          }
        }
      }
    },
    "/audit": {
      "post": {
        "tags": [
          "Audit"
        ],
        "summary": "Create audit event",
        "description": "Create an immutable audit event.",
        "operationId": "createAuditEvent",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateAuditEventRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Audit event created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuditEvent"
                }
              }
            }
          }
        }
      }
    },
    "/events": {
      "get": {
        "tags": [
          "Audit"
        ],
        "summary": "List audit events",
        "operationId": "listAuditEvents",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Cursor-paginated audit events"
          }
        }
      }
    },
    "/audit-logs": {
      "get": {
        "tags": [
          "Audit"
        ],
        "summary": "List audit logs",
        "operationId": "listAuditLogs",
        "responses": {
          "200": {
            "description": "Cursor-paginated audit logs"
          }
        }
      }
    },
    "/audit-events": {
      "post": {
        "tags": [
          "Audit"
        ],
        "summary": "Create audit event",
        "operationId": "createAuditEventAlias",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateAuditEventRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Audit event created"
          }
        }
      }
    },
    "/approvals": {
      "get": {
        "tags": [
          "Approvals"
        ],
        "summary": "List approval requests",
        "operationId": "listApprovals",
        "responses": {
          "200": {
            "description": "Approval requests"
          }
        }
      },
      "post": {
        "tags": [
          "Approvals"
        ],
        "summary": "Create approval request",
        "operationId": "createApprovalAlias",
        "responses": {
          "201": {
            "description": "Approval created"
          }
        }
      }
    },
    "/compliance/status": {
      "get": {
        "tags": [
          "Reports"
        ],
        "summary": "Get latest compliance status",
        "operationId": "getComplianceStatus",
        "responses": {
          "200": {
            "description": "Latest compliance score"
          }
        }
      }
    },
    "/reports": {
      "get": {
        "tags": [
          "Reports"
        ],
        "summary": "List compliance reports",
        "operationId": "listReports",
        "responses": {
          "200": {
            "description": "Compliance reports",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReportList"
                }
              }
            }
          }
        }
      }
    },
    "/subscription": {
      "get": {
        "tags": [
          "Billing"
        ],
        "summary": "Get workspace subscription",
        "operationId": "getSubscription",
        "responses": {
          "200": {
            "description": "Subscription"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/usage": {
      "get": {
        "tags": [
          "Usage"
        ],
        "summary": "Get current usage",
        "operationId": "getUsage",
        "responses": {
          "200": {
            "description": "Current usage metrics",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Usage"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API Key",
        "description": "API key prefixed with kc_live_ or kc_test_"
      }
    },
    "schemas": {
      "Agent": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "agent_01H..."
          },
          "name": {
            "type": "string",
            "example": "Support Agent"
          },
          "provider": {
            "type": "string",
            "example": "openai"
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "inactive"
            ]
          },
          "environment": {
            "type": "string",
            "enum": [
              "development",
              "production"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "AgentList": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Agent"
            }
          },
          "has_more": {
            "type": "boolean"
          }
        }
      },
      "CreateAgentRequest": {
        "type": "object",
        "required": [
          "name",
          "provider"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "provider": {
            "type": "string"
          },
          "environment": {
            "type": "string",
            "enum": [
              "development",
              "production"
            ]
          }
        }
      },
      "Policy": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "enabled": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "PolicyList": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Policy"
            }
          }
        }
      },
      "CreatePolicyRequest": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "enabled": {
            "type": "boolean",
            "default": true
          },
          "rules": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        }
      },
      "Approval": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "approved",
              "rejected"
            ]
          },
          "priority": {
            "type": "string",
            "enum": [
              "low",
              "medium",
              "high"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CreateApprovalRequest": {
        "type": "object",
        "required": [
          "title",
          "agent"
        ],
        "properties": {
          "title": {
            "type": "string"
          },
          "agent": {
            "type": "string"
          },
          "priority": {
            "type": "string",
            "enum": [
              "low",
              "medium",
              "high"
            ]
          }
        }
      },
      "AuditEvent": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "agent": {
            "type": "string"
          },
          "action": {
            "type": "string"
          },
          "immutable": {
            "type": "boolean",
            "const": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CreateAuditEventRequest": {
        "type": "object",
        "required": [
          "agent",
          "action"
        ],
        "properties": {
          "agent": {
            "type": "string"
          },
          "action": {
            "type": "string"
          },
          "resource": {
            "type": "string"
          },
          "severity": {
            "type": "string",
            "enum": [
              "low",
              "medium",
              "high",
              "critical"
            ]
          }
        }
      },
      "ReportList": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        }
      },
      "Usage": {
        "type": "object",
        "properties": {
          "requests_this_period": {
            "type": "integer"
          },
          "agents_count": {
            "type": "integer"
          },
          "policies_count": {
            "type": "integer"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "retry_after": {
                "type": "integer",
                "description": "Seconds until a retry is allowed."
              }
            }
          }
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Bad Request",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Unauthorized",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimitExceeded": {
        "description": "Rate limit exceeded",
        "headers": {
          "Retry-After": {
            "schema": {
              "type": "integer"
            },
            "description": "Seconds before retrying."
          },
          "RateLimit-Limit": {
            "schema": {
              "type": "integer"
            }
          },
          "RateLimit-Remaining": {
            "schema": {
              "type": "integer"
            }
          },
          "RateLimit-Reset": {
            "schema": {
              "type": "integer"
            },
            "description": "Unix reset timestamp."
          },
          "X-Request-Id": {
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "Not Found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}