{
  "openapi": "3.1.0",
  "info": {
    "title": "ShieldSignup API",
    "version": "1.0.0",
    "description": "Signup-time risk assessment API. Evaluate signup attempts and receive a verdict (allow, challenge, block), numeric score, and machine-readable reason codes.\n\nHuman-readable docs: https://www.shieldsignup.com/docs",
    "contact": {
      "name": "ShieldSignup Support",
      "email": "support@shieldsignup.com"
    },
    "license": {
      "name": "Proprietary"
    }
  },
  "servers": [
    {
      "url": "https://api.shieldsignup.com",
      "description": "Production API"
    }
  ],
  "tags": [
    {
      "name": "Assessments",
      "description": "Core signup risk assessment endpoints"
    },
    {
      "name": "Account",
      "description": "Usage and feedback for authenticated API keys"
    }
  ],
  "paths": {
    "/v1/assess": {
      "post": {
        "operationId": "assessSignup",
        "summary": "Assess a signup attempt",
        "description": "Evaluates an email address and optional client IP at signup time. Returns a verdict, score, reason codes, and underlying signals. Each call consumes one assessment credit.",
        "tags": ["Assessments"],
        "security": [{ "BearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/AssessRequest" },
              "example": {
                "email": "user@mailinator.com",
                "ip": "185.220.101.45",
                "session_id": "sess_abc123"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Assessment completed",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AssessResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "429": { "$ref": "#/components/responses/RateLimited" },
          "500": { "$ref": "#/components/responses/InternalError" }
        }
      }
    },
    "/v1/assess/{request_id}": {
      "get": {
        "operationId": "getAssessment",
        "summary": "Retrieve a previous assessment",
        "description": "Fetch a stored assessment by its request_id without consuming a new credit.",
        "tags": ["Assessments"],
        "security": [{ "BearerAuth": [] }],
        "parameters": [
          {
            "name": "request_id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "Assessment ID from a prior POST /v1/assess response (prefix req_)"
          }
        ],
        "responses": {
          "200": {
            "description": "Assessment found",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AssessResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "500": { "$ref": "#/components/responses/InternalError" }
        }
      }
    },
    "/v1/feedback": {
      "post": {
        "operationId": "submitFeedback",
        "summary": "Report a false positive or false negative",
        "description": "Submit feedback on an assessment outcome to improve detection.",
        "tags": ["Account"],
        "security": [{ "BearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/FeedbackRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Feedback accepted",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/FeedbackResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "500": { "$ref": "#/components/responses/InternalError" }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "operationId": "getUsage",
        "summary": "Get current billing period usage",
        "description": "Returns assessment usage and limits for the authenticated API key.",
        "tags": ["Account"],
        "security": [{ "BearerAuth": [] }],
        "responses": {
          "200": {
            "description": "Usage snapshot",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/UsageResponse" }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "500": { "$ref": "#/components/responses/InternalError" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key from the ShieldSignup dashboard (sk_live_… or sk_test_…)"
      }
    },
    "schemas": {
      "AssessRequest": {
        "type": "object",
        "required": ["email"],
        "properties": {
          "email": {
            "type": "string",
            "format": "email",
            "description": "Email address submitted at signup"
          },
          "ip": {
            "type": "string",
            "description": "End user's public IPv4 or IPv6 address (strongly recommended)"
          },
          "session_id": {
            "type": "string",
            "description": "Your internal session or request ID for correlation"
          }
        }
      },
      "Reason": {
        "type": "object",
        "required": ["code", "signal"],
        "properties": {
          "code": {
            "type": "string",
            "enum": [
              "email_disposable",
              "email_deliverability",
              "email_role_account",
              "email_alias",
              "email_consumer_provider",
              "ip_anonymizer",
              "ip_reputation",
              "ip_hosting",
              "velocity_ip",
              "velocity_domain"
            ]
          },
          "signal": {
            "type": "string",
            "enum": ["email", "ip", "velocity"]
          }
        }
      },
      "AssessResponse": {
        "type": "object",
        "required": [
          "request_id",
          "verdict",
          "score",
          "reasons",
          "signals",
          "ip_provided",
          "ip_status",
          "processed_ms",
          "assessed_at"
        ],
        "properties": {
          "request_id": { "type": "string" },
          "session_id": { "type": "string" },
          "verdict": {
            "type": "string",
            "enum": ["allow", "challenge", "block"]
          },
          "score": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          },
          "reasons": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/Reason" }
          },
          "signals": {
            "type": "object",
            "additionalProperties": true
          },
          "ip_provided": { "type": "boolean" },
          "ip_status": {
            "type": "string",
            "enum": [
              "ok",
              "missing",
              "ignored_loopback",
              "ignored_private",
              "ignored_localhost"
            ]
          },
          "processed_ms": { "type": "integer" },
          "assessed_at": { "type": "string", "format": "date-time" }
        }
      },
      "FeedbackRequest": {
        "type": "object",
        "required": ["request_id", "outcome"],
        "properties": {
          "request_id": { "type": "string" },
          "outcome": {
            "type": "string",
            "enum": ["false_positive", "false_negative"]
          },
          "note": { "type": "string" }
        }
      },
      "FeedbackResponse": {
        "type": "object",
        "required": ["accepted", "message"],
        "properties": {
          "accepted": { "type": "boolean" },
          "message": { "type": "string" }
        }
      },
      "UsageResponse": {
        "type": "object",
        "required": [
          "plan",
          "period_start",
          "period_end",
          "assessments_used",
          "assessments_limit",
          "overage_rate_per_1k",
          "reset_at"
        ],
        "properties": {
          "plan": { "type": "string" },
          "period_start": { "type": "string", "format": "date-time" },
          "period_end": { "type": "string", "format": "date-time" },
          "assessments_used": { "type": "integer" },
          "assessments_limit": { "type": "integer" },
          "overage_rate_per_1k": { "type": "number" },
          "reset_at": { "type": "string", "format": "date-time" }
        }
      },
      "ErrorEnvelope": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message"],
            "properties": {
              "code": { "type": "string" },
              "message": { "type": "string" },
              "param": { "type": "string" },
              "resolution": {
                "type": "string",
                "description": "Actionable hint for fixing the error"
              }
            }
          }
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Invalid request",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/ErrorEnvelope" }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing or invalid bearer token",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/ErrorEnvelope" }
          }
        }
      },
      "RateLimited": {
        "description": "Quota or rate limit exceeded",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/ErrorEnvelope" }
          }
        }
      },
      "InternalError": {
        "description": "Unexpected server error",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/ErrorEnvelope" }
          }
        }
      }
    }
  }
}
