{
  "openapi": "3.1.0",
  "info": {
    "title": "AI Act Copilot API",
    "version": "1.0.0",
    "description": "Workspace-scoped REST API. Authenticate with a workspace API key (Settings → API keys) as `Authorization: Bearer aac_live_…`. Every call is written to the audit log as `api:<key name>`. Lists use cursor pagination (`limit`, `cursor` → `next_cursor`)."
  },
  "servers": [
    {
      "url": "https://www.euact.co/api/v1"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "UseCase": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "purpose": {
            "type": "string"
          },
          "sector": {
            "type": "string"
          },
          "owner": {
            "type": "string"
          },
          "role": {
            "enum": [
              "PROVIDER",
              "DEPLOYER",
              "IMPORTER",
              "DISTRIBUTOR"
            ]
          },
          "systemType": {
            "enum": [
              "APPLICATION",
              "MODEL",
              "AGENT"
            ]
          },
          "deploymentStatus": {
            "enum": [
              "PLANNED",
              "PILOT",
              "PRODUCTION",
              "RETIRED"
            ]
          },
          "riskTier": {
            "enum": [
              "UNASSESSED",
              "PROHIBITED",
              "HIGH",
              "LIMITED",
              "MINIMAL"
            ]
          }
        }
      },
      "UseCaseCreate": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "purpose": {
            "type": "string"
          },
          "sector": {
            "type": "string"
          },
          "owner": {
            "type": "string"
          },
          "role": {
            "enum": [
              "PROVIDER",
              "DEPLOYER",
              "IMPORTER",
              "DISTRIBUTOR"
            ],
            "default": "DEPLOYER"
          },
          "systemType": {
            "enum": [
              "APPLICATION",
              "MODEL",
              "AGENT"
            ],
            "default": "APPLICATION"
          },
          "deploymentStatus": {
            "enum": [
              "PLANNED",
              "PILOT",
              "PRODUCTION",
              "RETIRED"
            ],
            "default": "PLANNED"
          }
        }
      },
      "Classification": {
        "type": "object",
        "properties": {
          "tier": {
            "type": "string"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "rationale": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "article": {
                  "type": "string"
                },
                "text": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "Page": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {}
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    }
  },
  "paths": {
    "/health": {
      "get": {
        "summary": "Liveness and database check",
        "security": [],
        "responses": {
          "200": {
            "description": "ok"
          },
          "503": {
            "description": "degraded"
          }
        }
      }
    },
    "/use-cases": {
      "get": {
        "summary": "List AI systems",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "maximum": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Page of use cases",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Page"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Register an AI system",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UseCaseCreate"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UseCase"
                }
              }
            }
          },
          "422": {
            "description": "Invalid",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/use-cases/{id}": {
      "get": {
        "summary": "AI system with obligations, controls and risks",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Use case"
          },
          "404": {
            "description": "Not found in this workspace"
          }
        }
      }
    },
    "/use-cases/{id}/assessments": {
      "get": {
        "summary": "Assessment history",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Assessments, newest first"
          }
        }
      },
      "post": {
        "summary": "Run the EU AI Act classification",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "answers"
                ],
                "properties": {
                  "answers": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "boolean"
                    },
                    "description": "Question id → true/false. Omitted ids count as false. See GET /questions."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Classification",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Classification"
                }
              }
            }
          }
        }
      }
    },
    "/use-cases/{id}/metrics": {
      "get": {
        "summary": "Latest monitoring metrics",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Metrics"
          }
        }
      },
      "post": {
        "summary": "Push monitoring metrics (breaches open incidents)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "metrics": {
                    "type": "array",
                    "maxItems": 100,
                    "items": {
                      "type": "object",
                      "required": [
                        "name",
                        "value"
                      ],
                      "properties": {
                        "name": {
                          "type": "string"
                        },
                        "value": {
                          "type": "number"
                        },
                        "threshold": {
                          "type": "number"
                        },
                        "direction": {
                          "enum": [
                            "BELOW",
                            "ABOVE"
                          ]
                        },
                        "recorded_at": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted"
          }
        }
      }
    },
    "/questions": {
      "get": {
        "summary": "Classification questionnaire",
        "responses": {
          "200": {
            "description": "Sections and question ids"
          }
        }
      }
    },
    "/controls": {
      "get": {
        "summary": "Policy packs, controls and cross-walk",
        "responses": {
          "200": {
            "description": "Packs"
          }
        }
      }
    },
    "/vendors": {
      "get": {
        "summary": "List vendors",
        "responses": {
          "200": {
            "description": "Page of vendors"
          }
        }
      },
      "post": {
        "summary": "Add a vendor",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "category": {
                    "type": "string"
                  },
                  "website": {
                    "type": "string",
                    "format": "uri"
                  },
                  "contactEmail": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          }
        }
      }
    },
    "/shadow-ai/events": {
      "post": {
        "summary": "Bulk-ingest AI usage events (≤500, idempotent per source + external_id)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "events": {
                    "type": "array",
                    "maxItems": 500,
                    "items": {
                      "type": "object",
                      "required": [
                        "tool",
                        "event_at"
                      ],
                      "properties": {
                        "tool": {
                          "type": "string"
                        },
                        "domain": {
                          "type": "string"
                        },
                        "user_ref": {
                          "type": "string"
                        },
                        "department": {
                          "type": "string"
                        },
                        "source": {
                          "type": "string"
                        },
                        "event_at": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "external_id": {
                          "type": "string",
                          "description": "Your event id; re-sending the same id (per source) is a no-op"
                        },
                        "data_class": {
                          "type": "string",
                          "enum": [
                            "PUBLIC",
                            "INTERNAL",
                            "PERSONAL",
                            "SPECIAL"
                          ]
                        },
                        "customer_facing": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted: { accepted, duplicates }"
          }
        }
      }
    },
    "/agent-governor/decide": {
      "post": {
        "summary": "Runtime decision before an agent uses a tool",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "use_case_id",
                  "tool"
                ],
                "properties": {
                  "use_case_id": {
                    "type": "string"
                  },
                  "tool": {
                    "type": "string"
                  },
                  "context": {
                    "type": "object"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Verdict",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "decision": {
                      "enum": [
                        "ALLOW",
                        "BLOCK",
                        "ESCALATE",
                        "ADVISE"
                      ]
                    },
                    "reason": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    },
                    "policy_id": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "event_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/audit-log": {
      "get": {
        "summary": "Audit trail export, newest first",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Page of audit entries"
          }
        }
      }
    },
    "/guard": {
      "post": {
        "summary": "Screen a prompt or model output (guardrails)",
        "description": "Checks text for prompt injection, jailbreak attempts, personal data, secrets and abusive language. Returns ALLOW, FLAG or BLOCK according to the workspace guardrail policy. Blocks everything while the system kill switch is on. The raw text is never stored.",
        "operationId": "guard",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "text"
                ],
                "properties": {
                  "text": {
                    "type": "string",
                    "maxLength": 100000
                  },
                  "direction": {
                    "type": "string",
                    "enum": [
                      "input",
                      "output"
                    ],
                    "default": "input"
                  },
                  "use_case_id": {
                    "type": "string"
                  },
                  "redact": {
                    "type": "boolean",
                    "default": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Decision",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "action": {
                      "type": "string",
                      "enum": [
                        "ALLOW",
                        "FLAG",
                        "BLOCK"
                      ]
                    },
                    "findings": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "category": {
                            "type": "string"
                          },
                          "label": {
                            "type": "string"
                          },
                          "type": {
                            "type": "string"
                          },
                          "detail": {
                            "type": "string"
                          },
                          "action": {
                            "type": "string"
                          }
                        }
                      }
                    },
                    "redacted_text": {
                      "type": "string"
                    },
                    "decided_action": {
                      "type": "string",
                      "enum": ["ALLOW", "FLAG", "BLOCK"],
                      "description": "What the policy decided. Equals `action` in ENFORCE mode; in MONITOR mode `action` is ALLOW."
                    },
                    "mode": {
                      "type": "string",
                      "enum": ["MONITOR", "ENFORCE"]
                    },
                    "policy_version": {
                      "type": "integer",
                      "description": "Guardrail policy version that made the decision (0 = defaults, never saved)."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "429": {
            "description": "Rate limited (600 requests per minute per key)"
          }
        }
      }
    },
    "/agent-traces": {
      "post": {
        "summary": "Analyse one recorded agent run; findings become control evidence",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "use_case_id",
                  "trace"
                ],
                "properties": {
                  "use_case_id": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string",
                    "maxLength": 120
                  },
                  "budget_usd": {
                    "type": "number",
                    "exclusiveMinimum": 0
                  },
                  "trace": {
                    "description": "Array of steps, or an object with spans, runs, steps or OpenTelemetry resourceSpans"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "{ id, rating, headline, metrics, findings }"
          },
          "404": {
            "description": "Use case not found"
          },
          "422": {
            "description": "Invalid trace"
          }
        }
      }
    }
  }
}
