{
  "openapi": "3.0.3",
  "info": {
    "title": "LaunchLabs API",
    "description": "AI-powered pre-flight testing for SaaS applications. Run comprehensive assessments across security, performance, accessibility, SEO, and more.",
    "version": "1.0.0",
    "contact": {
      "name": "LaunchLabs Support",
      "url": "https://getlaunchlabs.com/contact",
      "email": "support@getlaunchlabs.com"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://getlaunchlabs.com/terms"
    }
  },
  "servers": [
    {
      "url": "https://getlaunchlabs.com",
      "description": "Production API"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "paths": {
    "/api/health": {
      "get": {
        "summary": "Health Check",
        "description": "Check if the API is operational",
        "operationId": "healthCheck",
        "tags": ["System"],
        "security": [],
        "responses": {
          "200": {
            "description": "API is healthy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "string", "example": "ok" },
                    "timestamp": { "type": "string", "format": "date-time" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/agents": {
      "get": {
        "summary": "List Available Agents",
        "description": "Get a list of all available AI testing agents and their capabilities",
        "operationId": "listAgents",
        "tags": ["Agents"],
        "security": [],
        "responses": {
          "200": {
            "description": "List of available agents",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "agents": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Agent"
                      }
                    },
                    "bundles": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Bundle"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/scan": {
      "post": {
        "summary": "Run Assessment",
        "description": "Run an AI-powered assessment on a target URL using specified agents",
        "operationId": "runScan",
        "tags": ["Scanning"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ScanRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Assessment completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScanResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request parameters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Insufficient credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/key/status": {
      "get": {
        "summary": "Check API Key Status",
        "description": "Get the status and remaining credits for an API key",
        "operationId": "getKeyStatus",
        "tags": ["Account"],
        "responses": {
          "200": {
            "description": "API key status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "valid": { "type": "boolean" },
                    "credits": { "type": "integer" },
                    "plan": { "type": "string" }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid API key"
          }
        }
      }
    },
    "/api/pricing": {
      "get": {
        "summary": "Get Pricing Information",
        "description": "Get current pricing for credits and subscriptions",
        "operationId": "getPricing",
        "tags": ["Billing"],
        "security": [],
        "responses": {
          "200": {
            "description": "Pricing information",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "credits": {
                      "type": "object",
                      "properties": {
                        "pricePerCredit": { "type": "number" },
                        "packages": { "type": "array", "items": { "type": "object" } }
                      }
                    },
                    "subscription": {
                      "type": "object",
                      "properties": {
                        "monthly": { "type": "number" },
                        "creditsIncluded": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/report/pdf": {
      "post": {
        "summary": "Generate PDF Report",
        "description": "Generate a PDF version of an assessment report",
        "operationId": "generatePdf",
        "tags": ["Reports"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["reportId"],
                "properties": {
                  "reportId": { "type": "string", "description": "The ID of the report to convert" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "PDF generated successfully",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          }
        }
      }
    },
    "/api/ci/scan": {
      "post": {
        "summary": "CI/CD Scan",
        "description": "Run an assessment as part of a CI/CD pipeline. Returns structured results for automated processing.",
        "operationId": "ciScan",
        "tags": ["CI/CD"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ScanRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "CI scan completed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CIScanResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "API key for authentication. Get yours at https://getlaunchlabs.com/account/api-keys"
      }
    },
    "schemas": {
      "Agent": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "security" },
          "name": { "type": "string", "example": "Noah (Security)" },
          "description": { "type": "string" },
          "credits": { "type": "integer", "example": 1 },
          "category": { "type": "string", "example": "Technical" }
        }
      },
      "Bundle": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "quick-scan" },
          "name": { "type": "string", "example": "Quick Scan" },
          "agents": { "type": "array", "items": { "type": "string" } },
          "credits": { "type": "integer" }
        }
      },
      "ScanRequest": {
        "type": "object",
        "required": ["url", "agents"],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "description": "The URL to scan",
            "example": "https://example.com"
          },
          "agents": {
            "type": "array",
            "items": { "type": "string" },
            "description": "List of agent IDs to run",
            "example": ["security", "performance", "seo"]
          },
          "auth": {
            "type": "object",
            "description": "Authentication credentials for testing authenticated pages",
            "properties": {
              "email": { "type": "string" },
              "password": { "type": "string" },
              "cookie": { "type": "string" }
            }
          }
        }
      },
      "ScanResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" },
          "reportId": { "type": "string" },
          "grade": { "type": "string", "enum": ["A", "B", "C", "D", "F"] },
          "score": { "type": "integer", "minimum": 0, "maximum": 100 },
          "issues": {
            "type": "object",
            "properties": {
              "critical": { "type": "integer" },
              "high": { "type": "integer" },
              "medium": { "type": "integer" },
              "low": { "type": "integer" }
            }
          },
          "results": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AgentResult"
            }
          }
        }
      },
      "AgentResult": {
        "type": "object",
        "properties": {
          "agent": { "type": "string" },
          "grade": { "type": "string" },
          "score": { "type": "integer" },
          "findings": { "type": "array", "items": { "type": "object" } }
        }
      },
      "CIScanResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" },
          "passed": { "type": "boolean", "description": "Whether the scan passed CI thresholds" },
          "grade": { "type": "string" },
          "score": { "type": "integer" },
          "failureReasons": {
            "type": "array",
            "items": { "type": "string" }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": { "type": "string" },
          "message": { "type": "string" },
          "code": { "type": "string" }
        }
      }
    }
  },
  "tags": [
    { "name": "System", "description": "System health and status endpoints" },
    { "name": "Agents", "description": "AI testing agents information" },
    { "name": "Scanning", "description": "Run assessments on target URLs" },
    { "name": "Account", "description": "Account and API key management" },
    { "name": "Billing", "description": "Pricing and payment endpoints" },
    { "name": "Reports", "description": "Report generation and retrieval" },
    { "name": "CI/CD", "description": "Continuous integration endpoints" }
  ]
}
