{
  "openapi": "3.1.0",
  "info": {
    "title": "Evidentia API",
    "version": "0.1.0-open-beta",
    "description": "Initial Open Beta API surface for creating, polling, verifying, and exporting Evidentia Proof metadata including event_hash, signature, chain anchor metadata, and Platform Signing Key metadata when available. Raw payloads, private keys, and secrets are not exposed by default."
  },
  "servers": [
    {
      "url": "https://www.evidentiaaiapp.com",
      "description": "Production"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Use an Evidentia API key from your backend only."
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "minLength": 1
        },
        "description": "Required for Proof creation. Use the same value for the same AI usage record to prevent duplicate Proof requests."
      }
    },
    "schemas": {
      "ProofRequest": {
        "type": "object",
        "required": ["event_type", "input", "output"],
        "properties": {
          "event_type": {
            "type": "string",
            "example": "ai_decision"
          },
          "input": {
            "type": "object",
            "additionalProperties": true,
            "example": {
              "request": "Sample decision request"
            }
          },
          "output": {
            "type": "object",
            "additionalProperties": true,
            "example": {
              "decision": "approved",
              "reason": "Sample result"
            }
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true,
            "example": {
              "source": "api_example"
            }
          }
        }
      },
      "ProofQueuedResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean", "example": true },
          "queued": { "type": "boolean", "example": true },
          "job_id": { "type": "string", "example": "decision_123" },
          "status": { "type": "string", "example": "processing" },
          "status_url": { "type": "string", "example": "/api/proof/status/decision_123" },
          "message": { "type": "string", "example": "Proof request accepted" }
        }
      },
      "ProofStatusResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "status": { "type": "string", "example": "completed" },
          "job_id": { "type": "string" },
          "proof_id": { "type": ["string", "null"], "example": "EV-..." },
          "verification_url": { "type": ["string", "null"] },
          "public_proof_api_url": { "type": ["string", "null"] }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean", "example": false },
          "error": { "type": "string", "example": "idempotency_key_required" },
          "message": { "type": "string" }
        }
      }
    }
  },
  "paths": {
    "/api/proof/request": {
      "post": {
        "summary": "Create a Proof request",
        "description": "Queues a Proof generation job using the authenticated organization from the API key.",
        "parameters": [
          { "$ref": "#/components/parameters/IdempotencyKey" }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ProofRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Proof request queued",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ProofQueuedResponse" }
              }
            }
          },
          "400": {
            "description": "Invalid request or missing idempotency key",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "402": {
            "description": "Quota or billing requirement"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/api/proof/status/{jobId}": {
      "get": {
        "summary": "Get Proof job status",
        "parameters": [
          {
            "name": "jobId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Proof job status",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ProofStatusResponse" }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          }
        }
      }
    },
    "/api/proofs/{proofId}": {
      "get": {
        "summary": "Get authorized Proof detail",
        "parameters": [
          {
            "name": "proofId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": { "description": "Authorized Proof detail metadata" },
          "401": { "description": "Authentication required for private Proofs" },
          "403": { "description": "Forbidden" },
          "404": { "description": "Proof not found" }
        }
      }
    },
    "/api/public/proofs/{proofId}": {
      "get": {
        "summary": "Get public Proof verification metadata",
        "security": [],
        "parameters": [
          {
            "name": "proofId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": { "description": "Public-safe Proof verification metadata" },
          "403": { "description": "Proof is private" },
          "404": { "description": "Proof not found" }
        }
      }
    },
    "/api/proofs/{proofId}/export": {
      "get": {
        "summary": "Get verification export package",
        "parameters": [
          {
            "name": "proofId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": { "description": "Verification export package JSON or HTML view" },
          "401": { "description": "Authentication required for private Proofs" },
          "403": { "description": "Forbidden" },
          "404": { "description": "Proof not found" }
        }
      }
    }
  }
}
