{
 "openapi": "3.0.3",
 "info": {
  "title": "Verdika API",
  "version": "1.0.0",
  "description": "Decision verification for AI agents and automations: deterministic verdict (approve / review / block), evidence-capped confidence and a hash-chained audit log. Docs: https://verdika.pro/api.html"
 },
 "servers": [
  {
   "url": "https://verdika.pro"
  }
 ],
 "components": {
  "securitySchemes": {
   "bearer": {
    "type": "http",
    "scheme": "bearer",
    "description": "API key (vk_...). Create it in the app: Account → API for agents (Pro plan)."
   }
  },
  "schemas": {
   "Evidence": {
    "type": "object",
    "required": [
     "content"
    ],
    "properties": {
     "content": {
      "type": "string"
     },
     "source": {
      "type": "string"
     },
     "signature": {
      "type": "string",
      "description": "Optional base64 ML-DSA signature over the canonical evidence message."
     },
     "key_id": {
      "type": "string",
      "description": "Evidence key registered in the account."
     },
     "signed_at": {
      "type": "string",
      "format": "date-time",
      "description": "UTC, YYYY-MM-DDTHH:MM:SSZ. Covered by the signature."
     }
    }
   },
   "File": {
    "type": "object",
    "required": [
     "filename",
     "content_base64"
    ],
    "properties": {
     "filename": {
      "type": "string",
      "example": "pnl-2026.xlsx"
     },
     "content_base64": {
      "type": "string",
      "description": "File bytes, base64. CSV, TSV, XLSX, JSON or TXT. Max 2 MB."
     },
     "signature": {
      "type": "string",
      "description": "ML-DSA signature of the file bytes, with source = filename."
     },
     "key_id": {
      "type": "string"
     },
     "signed_at": {
      "type": "string"
     }
    }
   },
   "Policy": {
    "type": "object",
    "properties": {
     "min_confidence": {
      "type": "number",
      "default": 0.6
     },
     "min_margin": {
      "type": "number",
      "default": 0.1
     },
     "min_evidence_quality": {
      "type": "number",
      "default": 0.3
     },
     "require_signed_evidence": {
      "type": "boolean",
      "default": false
     },
     "max_evidence_age_hours": {
      "type": "number",
      "description": "Signatures older than this, or undated, do not count as verified."
     }
    }
   },
   "VerifyRequest": {
    "type": "object",
    "required": [
     "action"
    ],
    "properties": {
     "action": {
      "type": "string",
      "description": "The action the agent intends to execute (8-2000 chars)."
     },
     "alternatives": {
      "type": "array",
      "maxItems": 8,
      "items": {
       "type": "string"
      }
     },
     "context": {
      "type": "string"
     },
     "evidence": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Evidence"
      }
     },
     "files": {
      "type": "array",
      "maxItems": 5,
      "items": {
       "$ref": "#/components/schemas/File"
      }
     },
     "policy": {
      "$ref": "#/components/schemas/Policy"
     },
     "agent": {
      "type": "object",
      "additionalProperties": true
     },
     "language": {
      "type": "string",
      "enum": [
       "es",
       "en"
      ]
     }
    }
   },
   "VerifyResponse": {
    "type": "object",
    "properties": {
     "verification_id": {
      "type": "string"
     },
     "verdict": {
      "type": "string",
      "enum": [
       "approve",
       "review",
       "block"
      ]
     },
     "reasons": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "proposed_action": {
      "type": "object",
      "nullable": true
     },
     "recommended": {
      "type": "object"
     },
     "margin": {
      "type": "number",
      "nullable": true
     },
     "confidence": {
      "type": "number",
      "nullable": true
     },
     "confidence_cap": {
      "type": "number"
     },
     "evidence_quality": {
      "type": "number"
     },
     "uncertainty": {
      "type": "object",
      "nullable": true,
      "description": "Lower/upper bound of the top option's score from the uncertainty engine."
     },
     "evidence_items": {
      "type": "integer"
     },
     "ranking": {
      "type": "array",
      "items": {
       "type": "object"
      }
     },
     "key_assumptions": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "key_risks": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "audit": {
      "type": "object"
     },
     "session_id": {
      "type": "string"
     },
     "evidence_integrity": {
      "type": "object"
     },
     "evidence_integrity_verified": {
      "type": "boolean"
     },
     "confidence_cap_applied": {
      "type": "integer",
      "description": "Percent."
     },
     "warnings": {
      "type": "array",
      "items": {
       "type": "string"
      }
     }
    }
   }
  }
 },
 "paths": {
  "/v1": {
   "get": {
    "summary": "Service descriptor",
    "responses": {
     "200": {
      "description": "Endpoints, MCP url and limits"
     }
    }
   }
  },
  "/v1/verify": {
   "post": {
    "summary": "Verify a proposed action before executing it",
    "security": [
     {
      "bearer": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/VerifyRequest"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Verdict and audit record",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/VerifyResponse"
        }
       }
      }
     },
     "401": {
      "description": "Missing or invalid API key"
     },
     "403": {
      "description": "Pro plan required"
     },
     "429": {
      "description": "Daily or rate limit reached"
     }
    }
   }
  },
  "/v1/ingest": {
   "post": {
    "summary": "Turn CSV/XLSX/JSON files into evidence items (no auth, not stored)",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "files"
        ],
        "properties": {
         "files": {
          "type": "array",
          "maxItems": 5,
          "items": {
           "$ref": "#/components/schemas/File"
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Evidence items",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "evidence": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Evidence"
           }
          },
          "items": {
           "type": "integer"
          },
          "stored": {
           "type": "boolean"
          }
         }
        }
       }
      }
     },
     "413": {
      "description": "File too large"
     },
     "415": {
      "description": "Unsupported file type"
     }
    }
   }
  },
  "/v1/audit": {
   "get": {
    "summary": "List audit entries and check chain integrity",
    "security": [
     {
      "bearer": []
     }
    ],
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 50,
       "maximum": 200
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Chain status and entries"
     }
    }
   }
  },
  "/v1/audit/{id}": {
   "get": {
    "summary": "Get a verification and its follow-ups",
    "security": [
     {
      "bearer": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Audit record"
     },
     "404": {
      "description": "Not found"
     }
    }
   }
  },
  "/v1/audit/{id}/resolution": {
   "post": {
    "summary": "Record what was finally done with the verdict",
    "security": [
     {
      "bearer": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "executed"
        ],
        "properties": {
         "executed": {
          "type": "boolean"
         },
         "decided_by": {
          "type": "string"
         },
         "note": {
          "type": "string"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Recorded"
     }
    }
   }
  },
  "/v1/audit/{id}/outcome": {
   "post": {
    "summary": "Record the real-world outcome",
    "security": [
     {
      "bearer": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "success"
        ],
        "properties": {
         "success": {
          "type": "boolean"
         },
         "note": {
          "type": "string"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Recorded"
     }
    }
   }
  },
  "/v1/audit/{id}/receipt": {
   "get": {
    "summary": "ML-DSA-87 signed receipt of an audit entry",
    "security": [
     {
      "bearer": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Signed receipt"
     },
     "404": {
      "description": "Not found"
     },
     "409": {
      "description": "Audit chain broken"
     },
     "503": {
      "description": "Receipts not configured"
     }
    }
   }
  },
  "/v1/signing-key": {
   "get": {
    "summary": "Public key to verify receipts",
    "responses": {
     "200": {
      "description": "Algorithm and base64 public key"
     },
     "503": {
      "description": "Receipts not configured"
     }
    }
   }
  }
 }
}