{
  "openapi": "3.1.0",
  "info": {
    "title": "SignalCompact API",
    "version": "1.0.0",
    "description": "Deterministic log and command-output condensation with free signed quotes and optional x402 v2 upto settlement."
  },
  "servers": [{ "url": "https://signalcompact.nfshost.com" }],
  "paths": {
    "/v1/quote": {
      "post": {
        "summary": "Get a free five-minute exact price quote",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": ["inputCharacters"],
                "properties": {
                  "inputCharacters": { "type": "integer", "minimum": 0 },
                  "maxPriceAtomic": { "type": "string", "pattern": "^[0-9]+$" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed quote",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Quote" } } }
          },
          "422": { "$ref": "#/components/responses/Problem" },
          "429": { "$ref": "#/components/responses/Problem" }
        }
      }
    },
    "/v1/condense": {
      "post": {
        "summary": "Condense submitted output",
        "parameters": [
          { "in": "header", "name": "Idempotency-Key", "required": true, "schema": { "type": "string", "format": "uuid" } },
          { "in": "header", "name": "PAYMENT-SIGNATURE", "required": false, "description": "Required only when payments are enabled.", "schema": { "type": "string" } },
          { "in": "header", "name": "X-SignalCompact-Mode", "schema": { "$ref": "#/components/schemas/Mode" } },
          { "in": "header", "name": "X-SignalCompact-Max-Output-Characters", "schema": { "type": "integer", "minimum": 2000, "maximum": 32000 } },
          { "in": "header", "name": "X-SignalCompact-Quote", "schema": { "type": "string" } },
          { "in": "header", "name": "X-SignalCompact-Max-Price-Atomic", "schema": { "type": "string", "pattern": "^[0-9]+$" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/CondenseRequest" } },
            "text/plain": { "schema": { "type": "string", "maxLength": 10000000 } }
          }
        },
        "responses": {
          "200": {
            "description": "Condensed result",
            "headers": {
              "X-Input-SHA256": { "schema": { "type": "string" } },
              "X-Billed-Atomic": { "schema": { "type": "string" } },
              "PAYMENT-RESPONSE": { "schema": { "type": "string" } }
            },
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/CondenseResult" } },
              "text/markdown": { "schema": { "type": "string" } }
            }
          },
          "400": { "$ref": "#/components/responses/Problem" },
          "402": { "$ref": "#/components/responses/Problem" },
          "409": { "$ref": "#/components/responses/Problem" },
          "410": { "$ref": "#/components/responses/Problem" },
          "413": { "$ref": "#/components/responses/Problem" },
          "422": { "$ref": "#/components/responses/Problem" },
          "429": { "$ref": "#/components/responses/Problem" },
          "503": { "$ref": "#/components/responses/Problem" }
        }
      }
    },
    "/v1/capabilities": {
      "get": { "summary": "Discover modes, limits, pricing, and payment status", "responses": { "200": { "description": "Capabilities" } } }
    },
    "/health/live": {
      "get": { "summary": "Process liveness", "responses": { "200": { "description": "Live" } } }
    },
    "/health/ready": {
      "get": { "summary": "Readiness and queue state", "responses": { "200": { "description": "Ready" }, "503": { "description": "Not ready" } } }
    }
  },
  "components": {
    "schemas": {
      "Mode": { "type": "string", "enum": ["auto", "log", "test", "build", "command"] },
      "Quote": {
        "type": "object",
        "required": ["quoteId", "inputCharacters", "baseFeeAtomic", "variableFeeAtomic", "totalAtomic", "totalUsdc", "currency", "network", "withinBudget", "expiresAt"],
        "properties": {
          "quoteId": { "type": "string" },
          "inputCharacters": { "type": "integer" },
          "baseFeeAtomic": { "type": "string" },
          "variableFeeAtomic": { "type": "string" },
          "totalAtomic": { "type": "string" },
          "totalUsdc": { "type": "string" },
          "currency": { "const": "USDC" },
          "network": { "type": "string" },
          "withinBudget": { "type": "boolean" },
          "expiresAt": { "type": "string", "format": "date-time" }
        }
      },
      "CondenseRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": ["content"],
        "properties": {
          "content": { "type": "string", "maxLength": 10000000 },
          "mode": { "$ref": "#/components/schemas/Mode" },
          "maxOutputCharacters": { "type": "integer", "minimum": 2000, "maximum": 32000 },
          "quoteId": { "type": "string" },
          "maxPriceAtomic": { "type": "string", "pattern": "^[0-9]+$" }
        }
      },
      "CondenseResult": {
        "type": "object",
        "required": ["requestedMode", "detectedMode", "detectionConfidence", "input", "output", "counts", "groups", "notices", "billing"],
        "properties": {
          "requestedMode": { "$ref": "#/components/schemas/Mode" },
          "detectedMode": { "type": "string", "enum": ["log", "test", "build", "command"] },
          "detectionConfidence": { "type": "number", "minimum": 0, "maximum": 1 },
          "input": { "type": "object" },
          "output": { "type": "object" },
          "counts": { "type": "object" },
          "groups": { "type": "array", "items": { "$ref": "#/components/schemas/EventGroup" } },
          "notices": { "type": "array", "items": { "type": "string" } },
          "billing": { "type": "object" }
        }
      },
      "OccurrenceRange": {
        "type": "object",
        "additionalProperties": false,
        "required": ["firstLine", "lastLine"],
        "properties": {
          "firstLine": { "type": "integer", "minimum": 1 },
          "lastLine": { "type": "integer", "minimum": 1 }
        }
      },
      "EventGroup": {
        "type": "object",
        "additionalProperties": false,
        "required": ["rank", "severity", "frequency", "firstLine", "lastLine", "occurrences", "occurrenceLocationsOmitted", "groupingMethod", "representative"],
        "properties": {
          "rank": { "type": "integer", "minimum": 1 },
          "severity": { "type": "string", "enum": ["failure", "error", "warning", "unknown", "info", "debug"] },
          "frequency": { "type": "integer", "minimum": 1 },
          "firstLine": { "type": "integer", "minimum": 1, "description": "First line of the earliest occurrence; not a continuous span through lastLine." },
          "lastLine": { "type": "integer", "minimum": 1, "description": "Last line of the latest occurrence; not a continuous span from firstLine." },
          "occurrences": {
            "type": "array",
            "maxItems": 60,
            "description": "Every exact occurrence range when frequency is at most 60; otherwise the first 50 and last 10 ranges.",
            "items": { "$ref": "#/components/schemas/OccurrenceRange" }
          },
          "occurrenceLocationsOmitted": { "type": "integer", "minimum": 0 },
          "groupingMethod": { "type": "string", "enum": ["exact", "structured-normalization"] },
          "representative": { "type": "string", "description": "Exact redacted representative, visibly clipped when pathological." }
        }
      },
      "Problem": {
        "type": "object",
        "required": ["type", "title", "status", "detail"],
        "properties": {
          "type": { "type": "string", "format": "uri" },
          "title": { "type": "string" },
          "status": { "type": "integer" },
          "detail": { "type": "string" },
          "instance": { "type": "string" }
        }
      }
    },
    "responses": {
      "Problem": {
        "description": "Problem detail",
        "content": { "application/problem+json": { "schema": { "$ref": "#/components/schemas/Problem" } } }
      }
    }
  }
}
