openapi: 3.1.0
info:
  title: qsafe.sh API
  version: "1.0.0"
  summary: Check whether a website's HTTPS is ready for quantum computers.
  description: |
    A free JSON API over the same scanner as https://qsafe.sh. No key and no signup.

    **Limits.** New scans are limited to 5 a minute and 30 a day per IP, and the whole service
    runs at most 5,000 new scans a day. A result under one hour old is reused and doesn't count.
    Reading saved results, history, fixes and badges never scans and never counts.

    **Errors** use [RFC 9457 problem details](https://www.rfc-editor.org/rfc/rfc9457) with
    `content-type: application/problem+json`. A `429` carries a `Retry-After` header.
  contact:
    name: qsafe.sh
    url: https://qsafe.sh
  license:
    name: Results are free to use with attribution
    url: https://qsafe.sh
servers:
  - url: https://qsafe.sh
tags:
  - name: Scans
    description: Run a scan or read saved results.
  - name: Fixes
    description: Config changes for 18 stacks, per finding.
  - name: Reference
    description: Scoring rules, leaderboard, certificate checks.
paths:
  /api/v1/scan:
    get:
      tags: [Scans]
      operationId: scan
      summary: Scan a domain
      description: |
        Runs a TLS handshake against the domain from our scanner and returns the full report.
        If a public result under one hour old exists, it is returned instead (`cached: true`)
        unless you pass `fresh`. Fresh scans count against the rate limits.
      parameters:
        - name: domain
          in: query
          required: true
          description: Hostname to scan. A URL is accepted; the scheme, port and path are dropped.
          schema: { type: string, example: example.com }
        - name: fresh
          in: query
          description: Run a new scan even if a recent result exists.
          schema: { type: boolean, default: false }
        - name: private
          in: query
          description: |
            Don't publish the result. Private scans are never reused, are left out of history,
            badges, share images and verification, and always run fresh.
          schema: { type: boolean, default: false }
      responses:
        "200":
          description: The report.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/ScanResponse" }
        "422": { $ref: "#/components/responses/Unscannable" }
        "429": { $ref: "#/components/responses/RateLimited" }
        "502": { $ref: "#/components/responses/ScannerError" }
  /api/v1/result/{domain}:
    get:
      tags: [Scans]
      operationId: getResult
      summary: Latest saved result
      description: Returns the newest public result for the domain, or a specific scan with `scan`. Never scans.
      parameters:
        - $ref: "#/components/parameters/DomainPath"
        - name: scan
          in: query
          description: A scan id from an earlier response.
          schema: { type: string, example: m4k2x9c1a7 }
      responses:
        "200":
          description: The saved report.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/ScanResponse" }
        "404": { $ref: "#/components/responses/NotFound" }
        "422": { $ref: "#/components/responses/Unscannable" }
  /api/v1/history/{domain}:
    get:
      tags: [Scans]
      operationId: getHistory
      summary: Score history
      description: The last 30 public scans of the domain, newest first. Never scans.
      parameters:
        - $ref: "#/components/parameters/DomainPath"
      responses:
        "200":
          description: Score history.
          content:
            application/json:
              schema:
                type: object
                required: [domain, scans]
                properties:
                  domain: { type: string, example: example.com }
                  scans:
                    type: array
                    items:
                      type: object
                      required: [id, created_at, score, band]
                      properties:
                        id: { type: string, description: Scan id. }
                        created_at: { type: integer, description: Unix time in milliseconds. }
                        score: { type: integer, minimum: 0, maximum: 100 }
                        band: { $ref: "#/components/schemas/Band" }
        "422": { $ref: "#/components/responses/Unscannable" }
  /api/v1/bulk:
    post:
      tags: [Scans]
      operationId: bulkLookup
      summary: Saved results for many domains
      description: |
        Looks up saved results for up to 50 domains in one call. It never scans: for each
        domain with `status: not_scanned`, call the `scan` URL it gives you (rate limits apply
        per scan). This is how the /bulk page works.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [domains]
              properties:
                domains:
                  description: An array of domains, or one string separated by spaces, commas or new lines.
                  oneOf:
                    - type: array
                      maxItems: 50
                      items: { type: string }
                    - type: string
              example: { domains: [example.com, cloudflare.com] }
      responses:
        "200":
          description: One entry per input, duplicates removed.
          content:
            application/json:
              schema:
                type: object
                required: [count, results]
                properties:
                  count: { type: integer }
                  results:
                    type: array
                    items: { $ref: "#/components/schemas/BulkItem" }
        "400": { $ref: "#/components/responses/BadRequest" }
        "422": { $ref: "#/components/responses/Unscannable" }
  /api/v1/fixes:
    get:
      tags: [Fixes]
      operationId: listFixes
      summary: List fix guides, or get one fix
      description: |
        Without parameters: every supported stack and the finding-to-topic map.
        With `finding` (and optionally `stack`): the one fix for that finding on that stack.
      parameters:
        - name: finding
          in: query
          description: A finding id from a report.
          schema: { $ref: "#/components/schemas/FindingId" }
        - name: stack
          in: query
          description: A stack id, e.g. `nginx` or `cloudflare`.
          schema: { $ref: "#/components/schemas/StackId" }
      responses:
        "200":
          description: The guide list, or one fix.
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    title: Guide list
                    required: [guides, findings]
                    properties:
                      guides:
                        type: array
                        items:
                          type: object
                          properties:
                            id: { type: string }
                            name: { type: string }
                            kind: { type: string, enum: [cdn, platform, server, generic] }
                            status: { type: string }
                      findings:
                        type: object
                        additionalProperties: { type: string }
                        description: Finding id to fix topic.
                  - type: object
                    title: One fix
                    required: [finding, topic, fix]
                    properties:
                      finding: { type: string }
                      topic: { type: string }
                      fix: { type: string }
                      snippet: { type: string }
                      snippet_where: { type: string }
                      fix_guide: { type: string }
        "404": { $ref: "#/components/responses/NotFound" }
  /api/v1/fixes/{stack}:
    get:
      tags: [Fixes]
      operationId: getFixGuide
      summary: Full fix guide for a stack
      parameters:
        - name: stack
          in: path
          required: true
          schema: { $ref: "#/components/schemas/StackId" }
      responses:
        "200":
          description: The guide.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/FixGuide" }
        "404": { $ref: "#/components/responses/NotFound" }
  /api/v1/methodology:
    get:
      tags: [Reference]
      operationId: getMethodology
      summary: How the score is computed
      responses:
        "200":
          description: Points per area, caps and bands.
          content:
            application/json:
              schema:
                type: object
                properties:
                  version: { type: string, example: "1" }
                  points:
                    type: object
                    properties:
                      key_exchange: { type: integer, example: 45 }
                      protocol: { type: integer, example: 20 }
                      certificate: { type: integer, example: 20 }
                      transport: { type: integer, example: 15 }
                  caps:
                    type: object
                    properties:
                      no_post_quantum_key_exchange: { type: integer, example: 64 }
                      broken_basics: { type: integer, example: 39 }
                  bands:
                    type: array
                    items:
                      type: object
                      properties:
                        band: { $ref: "#/components/schemas/Band" }
                        min: { type: integer }
                        label: { type: string }
                  docs: { type: string, format: uri }
  /api/v1/leaderboard:
    get:
      tags: [Reference]
      operationId: getLeaderboard
      summary: Leaderboard
      description: The listed domains with their latest score and 30-day trend. Only domains in the public list are included.
      responses:
        "200":
          description: Leaderboard rows.
          content:
            application/json:
              schema:
                type: object
                properties:
                  domains:
                    type: array
                    items:
                      type: object
                      properties:
                        name: { type: string }
                        domain: { type: string }
                        category: { type: string }
                        score: { type: [integer, "null"] }
                        band: { oneOf: [{ $ref: "#/components/schemas/Band" }, { type: "null" }] }
                        label: { type: [string, "null"] }
                        ready: { type: boolean, description: True when the band is green. }
                        scanned_at: { type: [string, "null"], format: date-time }
                        trend_30d: { type: [integer, "null"], description: Score change over 30 days. }
                        scan_id: { type: [string, "null"] }
  /verify/{code}:
    get:
      tags: [Reference]
      operationId: verifyCertificate
      summary: Check a certificate
      description: |
        Checks the verification code printed on a qsafe.sh certificate. Add `?json` for JSON;
        without it you get the HTML page.
      parameters:
        - name: code
          in: path
          required: true
          description: The scan id printed on the certificate.
          schema: { type: string }
        - name: json
          in: query
          required: true
          allowEmptyValue: true
          schema: { type: string }
      responses:
        "200":
          description: Certificate status.
          content:
            application/json:
              schema:
                type: object
                properties:
                  code: { type: string }
                  domain: { type: string }
                  status: { type: string, enum: [valid, expired, revoked, not_issued] }
                  detail: { type: string }
                  score: { type: integer }
                  scanned_at: { type: string, format: date-time }
        "404":
          description: Unknown code (HTML page).
  /badge/{domain}.svg:
    get:
      tags: [Reference]
      operationId: getBadge
      summary: README badge
      description: An SVG badge with the latest public score. Never scans; shows "not scanned" until someone scans the domain. Cached for an hour.
      parameters:
        - $ref: "#/components/parameters/DomainPath"
      responses:
        "200":
          description: The badge.
          content:
            image/svg+xml:
              schema: { type: string }
components:
  parameters:
    DomainPath:
      name: domain
      in: path
      required: true
      description: Hostname, e.g. example.com.
      schema: { type: string, example: example.com }
  responses:
    BadRequest:
      description: The request body isn't valid.
      content:
        application/problem+json:
          schema: { $ref: "#/components/schemas/Problem" }
    NotFound:
      description: Nothing saved for that domain or scan.
      content:
        application/problem+json:
          schema: { $ref: "#/components/schemas/Problem" }
    Unscannable:
      description: Not a valid public hostname, or it can't be scanned (e.g. private IP, no HTTPS).
      content:
        application/problem+json:
          schema: { $ref: "#/components/schemas/Problem" }
    RateLimited:
      description: A rate limit was hit. See `Retry-After`.
      headers:
        Retry-After:
          description: Seconds to wait.
          schema: { type: integer }
      content:
        application/problem+json:
          schema: { $ref: "#/components/schemas/Problem" }
    ScannerError:
      description: The scan didn't finish (timeout or scanner unavailable).
      content:
        application/problem+json:
          schema: { $ref: "#/components/schemas/Problem" }
  schemas:
    Problem:
      type: object
      required: [type, title, status, detail]
      properties:
        type: { type: string, example: about:blank }
        title: { type: string, example: rate_limited }
        status: { type: integer, example: 429 }
        detail: { type: string, example: Too many scans from your network. Try again in a minute. }
    Band:
      type: string
      enum: [green, yellow, orange, red]
      description: "green 85-100 (Quantum-ready), yellow 65-84 (Almost ready), orange 40-64 (Not yet), red 0-39 (Not yet, at risk)."
    Severity:
      type: string
      enum: [high, medium, low, info, pass]
    FindingId:
      type: string
      examples: [KEX_CLASSICAL_ONLY, KEX_PQ_NOT_PREFERRED, TLS13_MISSING, TLS10_11_ENABLED, TLS12_WEAK_SUITE, HTTP_NO_REDIRECT, HSTS_MISSING, HSTS_SHORT]
    StackId:
      type: string
      enum: [generic, cloudflare, aws-cloudfront, aws-alb, azure-front-door, google-cloud, fastly, akamai, vercel, netlify, github-pages, nginx, apache, haproxy, caddy, traefik, iis, nodejs, go]
    Finding:
      type: object
      required: [id, severity, title, saw, why, fix]
      properties:
        id: { $ref: "#/components/schemas/FindingId" }
        severity: { $ref: "#/components/schemas/Severity" }
        title: { type: string }
        saw: { type: string, description: What we saw in this scan. }
        why: { type: string, description: Why it matters. }
        fix: { type: string, description: What to do next. }
        snippet: { type: string, description: Copy-paste config for the detected stack. }
        snippet_where: { type: string, description: Where the snippet goes. }
        fix_guide: { type: string, description: The stack guide the advice came from. }
    Stack:
      type: object
      properties:
        id: { type: string }
        name: { type: string }
        kind: { type: string, enum: [cdn, platform, server] }
        evidence: { type: array, items: { type: string } }
    FixGuide:
      type: object
      properties:
        id: { type: string }
        name: { type: string }
        kind: { type: string, enum: [cdn, platform, server, generic] }
        status: { type: string, description: Post-quantum status of this stack in one line. }
        docs: { type: string, format: uri }
        checked: { type: string, description: When the guide was last checked. }
        topics:
          type: object
          description: One step per topic (kex, kex_prefer, tls13, tls_min, tls12_suites, redirect, hsts).
          additionalProperties:
            type: object
            properties:
              text: { type: string }
              snippet: { type: string }
              where: { type: string }
    Report:
      type: object
      required: [domain, score, band, label, key_exchange, findings]
      properties:
        domain: { type: string, example: example.com }
        methodology_version: { type: string, example: "1" }
        scanned_at: { type: string, format: date-time }
        score: { type: integer, minimum: 0, maximum: 100, example: 92 }
        band: { $ref: "#/components/schemas/Band" }
        label: { type: string, example: Quantum-ready }
        verdict: { type: string, description: One-sentence summary. }
        breakdown:
          type: object
          properties:
            key_exchange: { type: integer, maximum: 45 }
            protocol: { type: integer, maximum: 20 }
            certificate: { type: integer, maximum: 20 }
            transport: { type: integer, maximum: 15 }
        caps_applied: { type: array, items: { type: string } }
        key_exchange:
          type: object
          properties:
            negotiated: { type: [string, "null"], example: X25519MLKEM768 }
            post_quantum: { type: boolean }
            pq_groups_supported: { type: array, items: { type: string } }
            prefers_pq: { type: boolean }
        tls_versions:
          type: object
          additionalProperties: { type: boolean }
          example: { "TLS 1.0": false, "TLS 1.1": false, "TLS 1.2": true, "TLS 1.3": true }
        certificate:
          type: [object, "null"]
          properties:
            subject: { type: string }
            issuer: { type: string }
            sans: { type: array, items: { type: string } }
            not_before: { type: string, format: date-time }
            not_after: { type: string, format: date-time }
            days_left: { type: integer }
            key_type: { type: string }
            key_bits: { type: integer }
            signature_algorithm: { type: string }
            chain_length: { type: integer }
            valid: { type: boolean }
            validate_error: { type: string }
        hsts:
          type: object
          properties:
            present: { type: boolean }
            max_age: { type: [integer, "null"] }
            include_subdomains: { type: boolean }
            preload: { type: boolean }
        http_redirects_to_https: { type: [boolean, "null"] }
        stack:
          type: array
          description: What terminates TLS, edge first.
          items: { $ref: "#/components/schemas/Stack" }
        findings:
          type: array
          items: { $ref: "#/components/schemas/Finding" }
        dns:
          type: object
          properties:
            ip: { type: string }
            ipv4: { type: array, items: { type: string } }
            ipv6: { type: array, items: { type: string } }
            cnames: { type: array, items: { type: string } }
        scan_ms: { type: integer }
    ScanResponse:
      allOf:
        - type: object
          required: [scan_id, permalink, cached, private]
          properties:
            scan_id: { type: string, example: m4k2x9c1a7 }
            permalink: { type: string, format: uri, example: "https://qsafe.sh/r/example.com?scan=m4k2x9c1a7" }
            cached: { type: boolean, description: True when a saved result was returned. }
            private: { type: boolean }
        - $ref: "#/components/schemas/Report"
    BulkItem:
      oneOf:
        - type: object
          title: Saved
          properties:
            domain: { type: string }
            status: { const: saved }
            score: { type: integer }
            band: { $ref: "#/components/schemas/Band" }
            label: { type: string }
            kex: { type: [string, "null"] }
            scanned_at: { type: string, format: date-time }
            scan_id: { type: string }
            permalink: { type: string, format: uri }
        - type: object
          title: Not scanned
          properties:
            domain: { type: string }
            status: { const: not_scanned }
            scan: { type: string, format: uri, description: Call this to scan it. }
        - type: object
          title: Invalid
          properties:
            input: { type: string }
            status: { const: invalid }
            error: { type: string }
