openapi: 3.0.3
info:
  title: Ipasis GeoAPI
  description: Real-time IP Intelligence & Reputation API for fraud prevention.
  version: 1.0.0
  contact:
    url: https://ipasis.com

servers:
  - url: https://api.ipasis.com
    description: Production

security:
  - BearerAuth: []
  - ApiKeyHeader: []
  - ApiKeyQuery: []

paths:
  /healthz:
    get:
      summary: Health check
      security: []
      responses:
        "200":
          description: Service healthy
          content:
            text/plain:
              schema:
                type: string
                example: ok
        "503":
          description: Service unhealthy (MMDB not loaded)

  /v1/lookup:
    get:
      summary: IP lookup
      description: |
        Returns geolocation, ASN, privacy flags (VPN/proxy/Tor/hosting),
        abuse contacts, and company info for the given IP address.
        This is the primary hot-path endpoint — sub-20ms p99 target.
      parameters:
        - name: ip
          in: query
          required: true
          schema:
            type: string
          example: "8.8.8.8"
        - name: details
          in: query
          required: false
          schema:
            type: string
            enum: ["true", "false"]
          description: Include raw provider/feed details
      responses:
        "200":
          description: IP lookup result
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/IPLookupResponse"
        "400":
          description: Missing or invalid IP
        "401":
          description: Missing or invalid API key
        "429":
          description: Rate limit exceeded

  /v1/validate-email:
    get:
      summary: Validate email (GET)
      parameters:
        - name: email
          in: query
          required: true
          schema:
            type: string
          example: "user@example.com"
        - name: ip
          in: query
          required: false
          schema:
            type: string
          description: Optional IP for combined risk scoring
      responses:
        "200":
          description: Email validation result
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/EmailValidationResponse"
        "400":
          description: Missing email
        "401":
          description: Missing or invalid API key
    post:
      summary: Validate email (POST)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [email]
              properties:
                email:
                  type: string
                ip:
                  type: string
      responses:
        "200":
          description: Email validation result
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/EmailValidationResponse"

components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
    ApiKeyHeader:
      type: apiKey
      in: header
      name: X-API-Key
    ApiKeyQuery:
      type: apiKey
      in: query
      name: key

  schemas:
    IPLookupResponse:
      type: object
      properties:
        ip:
          type: string
          example: "8.8.8.8"
        city:
          type: string
          example: "Mountain View"
        region:
          type: string
          example: "California"
        country:
          type: string
          example: "US"
        loc:
          type: string
          example: "37.386,-122.0838"
        postal:
          type: string
        timezone:
          type: string
          example: "America/Los_Angeles"
        asn:
          type: object
          properties:
            asn:
              type: string
              example: "AS15169"
            name:
              type: string
              example: "Google LLC"
            domain:
              type: string
            route:
              type: string
            type:
              type: string
              enum: [hosting, isp, education, business, ""]
        company:
          type: object
          properties:
            name:
              type: string
            domain:
              type: string
            type:
              type: string
        privacy:
          type: object
          properties:
            vpn:
              type: boolean
            proxy:
              type: boolean
            tor:
              type: boolean
            relay:
              type: boolean
              description: Privacy relay egress (iCloud Private Relay). Relay addresses are not reported as vpn.
            hosting:
              type: boolean
            abuse:
              type: boolean
            ai:
              type: boolean
            crawler:
              type: boolean
            service:
              type: string
            type:
              type: string
              description: Where a VPN exit sits - DataCenter (hosting network) or Residential (ISP network); empty otherwise.
        abuse:
          type: object
          properties:
            address:
              type: string
            country:
              type: string
            email:
              type: string
            name:
              type: string
            network:
              type: string
            phone:
              type: string
        domains:
          type: object
          properties:
            page:
              type: integer
            total:
              type: integer
            domains:
              type: array
              items:
                type: string
        connection_type:
          type: string
          enum: [hosting, mobile, isp, business, education, ""]
          description: Access network. hosting wins over the ASN type; mobile = predominantly cellular carrier (shared carrier-NAT addresses).
        threat:
          type: object
          description: Abuse-list recency. Lists are counted only while an entry is within three half-lives of its feed.
          properties:
            lists:
              type: integer
              description: Number of abuse/malicious lists that currently carry this address or its network
            sources:
              type: array
              items:
                type: string
            first_seen:
              type: string
              description: RFC 3339 time of the earliest current listing ("" when not listed)
            last_seen:
              type: string
              description: RFC 3339 time of the latest listing ("" when not listed)
        risk:
          type: object
          description: "0-100 IP risk score. Bands as /v1/validate-email: LOW < 31, MEDIUM 31-60, HIGH 61-85, CRITICAL >= 86."
          properties:
            score:
              type: integer
            level:
              type: string
              enum: [LOW, MEDIUM, HIGH, CRITICAL, UNKNOWN]
              description: UNKNOWN only for private/reserved addresses (reason non_public_ip; recommendation REVIEW), which usually mean the caller sent its own proxy address instead of the client's.
            recommendation:
              type: string
              enum: [ALLOW, REVIEW, BLOCK]
            reasons:
              type: array
              items:
                type: string
                enum: [tor_exit, open_proxy, residential_proxy, datacenter_proxy, proxy_activity_past, vpn, privacy_relay, known_crawler, ai_bot, hosting, abuse_listed, abuse_recent, abuse_multiple_lists, non_public_ip]
        proxy_activity:
          type: object
          description: >-
            Present only when the address was seen relaying proxy traffic (residential proxy
            networks for the most part) within the last 14 days. It does not change privacy.proxy,
            which stays "open/public proxy": residential exits are ordinary home connections,
            reassigned and shared, that may also carry their owner's traffic. High confidence
            (seen within the last day, or on 2+ of the last 4 days) scores residential_proxy or
            datacenter_proxy (35-45, never above an open proxy; halved on mobile and other
            carrier-NAT networks); low confidence scores proxy_activity_past (15). In a backtest,
            high confidence matched ~0.5% of home connections (RIPE Atlas home probes).
            Source: Avastel proxy bot IP lists (MIT). IPv6 matches by /64.
          properties:
            last_seen:
              type: string
              format: date
              description: Last day (UTC) the address was seen acting as a proxy.
            days_seen:
              type: integer
              description: Days within the last 14 on which it was seen.
            confidence:
              type: string
              enum: [high, low]
        bogon:
          type: boolean
          description: Present and true for private, reserved or special-use addresses; such addresses never carry flags.
        details:
          type: object
          description: Raw provider/feed details (only when details=true)

    EmailValidationResponse:
      type: object
      description: Top-level `risk` is the combined email + IP score to act on; `ip.risk` (when present) is the IP-only score from /v1/lookup, with different weights.
      properties:
        request_id:
          type: string
        success:
          type: boolean
        processed_at:
          type: string
          format: date-time
        risk:
          type: object
          description: Combined email + IP risk. The reasons email_domain_young, email_domain_recent and email_domain_no_auth (and their points) are only added when domain_age_days / has_spf / has_dmarc were available for this call; those lookups are best-effort and cached per server instance, so the same address can score slightly differently between calls, and bulk lookups (cached values only) may omit them.
          properties:
            score:
              type: integer
              minimum: 0
              maximum: 100
            level:
              type: string
              enum: [LOW, MEDIUM, HIGH, CRITICAL]
            recommendation:
              type: string
              enum: [ALLOW, REVIEW, BLOCK]
            primary_reasons:
              type: array
              items:
                type: string
        email:
          type: object
          properties:
            address:
              type: string
            status:
              type: string
              enum: [valid, invalid]
            deliverability:
              type: string
              enum: [deliverable, risky, undeliverable]
            type:
              type: string
              enum: [personal, disposable, role, business, unknown]
            domain_age_days:
              type: integer
              nullable: true
              description: Best-effort. Days since the registrable domain (eTLD+1) was registered, from RDAP. Null when unknown, not checked (common free-mail and relay domains, TLDs without RDAP) or the lookup did not finish in time (1.5 s budget, registry busy or rate limiting). Bulk lookups use cached values only, so this is often null there.
            normalized_email:
              type: string
              description: Canonical mailbox for de-duplication. Lowercase, provider subaddress removed (Gmail also drops dots and maps googlemail.com to gmail.com; Yahoo drops the "-keyword"; Fastmail maps user subdomains). Empty when the syntax is invalid.
              example: johndoe@gmail.com
            relay_provider:
              type: string
              description: Forwarding/alias service the address belongs to, or empty.
              enum: ["", apple_hide_my_email, firefox_relay, duckduckgo, simplelogin, proton_pass, addy]
            mx_provider:
              type: string
              description: Who receives mail for the domain, from its primary MX host. Empty when the MX lookup did not complete.
              enum: ["", google, microsoft, yahoo, apple, zoho, proton, fastmail, yandex, mailru, gmx, other_hosted, self_hosted, none]
            did_you_mean:
              type: string
              description: Suggested common mail domain when the domain looks like a typo of one (e.g. gmial.com -> gmail.com), or empty.
              example: gmail.com
            checks:
              type: object
              properties:
                is_valid_syntax:
                  type: boolean
                is_disposable:
                  type: boolean
                is_gibberish:
                  type: boolean
                is_newborn_domain:
                  type: boolean
                is_catch_all:
                  type: boolean
                  nullable: true
                is_role_account:
                  type: boolean
                mx_records_found:
                  type: boolean
                  nullable: true
                smtp_connect:
                  type: boolean
                  nullable: true
                is_subaddress:
                  type: boolean
                  description: The address carried a provider subaddress (+tag, Yahoo -keyword, Fastmail user subdomain).
                is_relay_alias:
                  type: boolean
                  description: The domain is an email forwarding/alias service (see relay_provider).
                has_spf:
                  type: boolean
                  nullable: true
                  description: Best-effort. The domain publishes an SPF record. Null when not checked (common free-mail/relay domains) or the lookup did not finish in time (1 s). Bulk lookups use cached values only.
                has_dmarc:
                  type: boolean
                  nullable: true
                  description: Best-effort. _dmarc.<domain> publishes a DMARC record. Null when not checked (common free-mail/relay domains) or the lookup did not finish in time (1 s). Bulk lookups use cached values only.
        ip:
          $ref: "#/components/schemas/IPLookupResponse"
          nullable: true
