{
  "openapi": "3.1.0",
  "info": {
    "title": "Evolve-Anything API",
    "version": "1.0.0",
    "summary": "Deterministic product, API catalog, and portfolio evolution engine with SHA-256 receipts and $0-on-miss billing.",
    "description": "Polymorphic deterministic evolution across 5 operations: gap_discovery, combo_synthesizer, zombie_auditor, sibling_mutator, and portfolio_allocator. Every call emits a tamper-evident EvolutionReceipt with strict $0 billing on misses, cyclic/zero-margin rejections, and HTTP 422 invalid inputs. Zero prompt or telemetry resale guarantee.",
    "contact": {
      "name": "Evolve-Anything Operations",
      "email": "ops@fastmesh.dev",
      "url": "https://evolve.fastmesh.dev"
    }
  },
  "servers": [
    {
      "url": "https://evolve.fastmesh.dev",
      "description": "Public HTTPS Gateway Mount"
    },
    {
      "url": "http://127.0.0.1:8807",
      "description": "Local Runtime Server"
    }
  ],
  "tags": [
    { "name": "Health", "description": "Service liveness and readiness probes" },
    { "name": "Evolution", "description": "5-operation polymorphic product & portfolio evolution endpoints" },
    { "name": "Discovery", "description": "Machine-readable discovery docs and technical guides" },
    { "name": "MCP", "description": "Native flat Streamable JSON-RPC 2.0 Model Context Protocol endpoint" },
    { "name": "Billing", "description": "Creem HMAC-SHA256 prepaid credit webhook settlement" }
  ],
  "paths": {
    "/": {
      "get": {
        "operationId": "getConsole",
        "tags": ["Discovery"],
        "summary": "Serve 5-second zero-signup Try-Now web console",
        "responses": {
          "200": {
            "description": "HTML single-page interactive console",
            "content": { "text/html": { "schema": { "type": "string" } } }
          }
        }
      }
    },
    "/health": {
      "get": {
        "operationId": "getHealth",
        "tags": ["Health"],
        "summary": "Check Evolve-Anything service health, operations, cache, and ledger stats",
        "responses": {
          "200": {
            "description": "Service is healthy and ready",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/HealthResponse" },
                "example": {
                  "status": "ok",
                  "service": "evolve-anything",
                  "version": "1.0.0",
                  "public_host": "evolve.fastmesh.dev",
                  "port": 8807,
                  "operations": [
                    "gap_discovery",
                    "combo_synthesizer",
                    "zombie_auditor",
                    "sibling_mutator",
                    "portfolio_allocator"
                  ],
                  "ledger_enabled": true,
                  "mcp_enabled": true,
                  "timestamp_utc": "2026-12-01T20:10:00+00:00"
                }
              }
            }
          }
        }
      }
    },
    "/try": {
      "post": {
        "operationId": "tryEvolutionPreview",
        "tags": ["Evolution"],
        "summary": "5-second zero-signup Try-Now preview executing any of the 5 evolution operations",
        "description": "Unauthenticated rate-limited Try-Now sandbox returning a full EvolutionReceipt with deterministic results.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/EvolveRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Preview EvolutionReceipt",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/EvolutionReceipt" }
              }
            }
          },
          "422": {
            "description": "Invalid or empty input ($0 billed)",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ZeroBillErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/evolve": {
      "post": {
        "operationId": "evolveSingle",
        "tags": ["Evolution"],
        "summary": "Run metered polymorphic evolution across 5 operations",
        "description": "Executes gap_discovery, combo_synthesizer, zombie_auditor, sibling_mutator, or portfolio_allocator and returns a SHA-256 tamper-evident EvolutionReceipt. Strictly bills $0 on misses, rejected cycles/zombies, and HTTP 422 invalid inputs.",
        "parameters": [
          {
            "name": "X-Tenant-Id",
            "in": "header",
            "required": false,
            "schema": { "type": "string" },
            "description": "Optional tenant identifier for prepaid ledger accounting and 10% repeat recheck pricing."
          },
          {
            "name": "X-API-Key",
            "in": "header",
            "required": false,
            "schema": { "type": "string" },
            "description": "Optional prepaid API key."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/EvolveRequest" },
              "examples": {
                "gap_discovery": {
                  "summary": "1. Gap Discovery over fleet snapshot & miss logs",
                  "value": {
                    "operation": "gap_discovery",
                    "payload": {
                      "use_default_snapshot": true,
                      "miss_logs": [
                        { "query": "automated vendor kyb dossier api", "hits": 42, "willingness_usd": 29.0 }
                      ]
                    }
                  }
                },
                "combo_synthesizer": {
                  "summary": "2. Acyclic 2-to-3-step Combo Synthesis",
                  "value": {
                    "operation": "combo_synthesizer",
                    "payload": {
                      "catalog": [
                        { "capability_id": "web_extract", "input_types": ["url"], "output_types": ["company_profile"], "unit_cogs_usd": 0.0008, "price_usd": 0.015 },
                        { "capability_id": "kyb_verify", "input_types": ["company_profile"], "output_types": ["verified_dossier"], "unit_cogs_usd": 0.001, "price_usd": 0.025 },
                        { "capability_id": "sha256_seal", "input_types": ["verified_dossier"], "output_types": ["attestation"], "unit_cogs_usd": 0.0003, "price_usd": 0.018 }
                      ]
                    }
                  }
                },
                "zombie_auditor": {
                  "summary": "3. 72h Launch Gate & 14d $0 Zombie Audit",
                  "value": {
                    "operation": "zombie_auditor",
                    "payload": {
                      "products": [
                        { "product_id": "stale_tool", "days_live": 16, "revenue_usd": 0.0, "qualified_visits": 240, "public_deployed": true },
                        { "product_id": "unlaunched_draft", "hours_since_created": 84, "revenue_usd": 0.0, "public_deployed": false },
                        { "product_id": "healthy_api", "days_live": 21, "revenue_usd": 420.0, "cost_usd": 12.0, "public_deployed": true }
                      ]
                    }
                  }
                },
                "sibling_mutator": {
                  "summary": "4. 3x Profitable Sibling Blueprint Expansion",
                  "value": {
                    "operation": "sibling_mutator",
                    "payload": {
                      "product": {
                        "product_id": "verify_anything",
                        "name": "Verify-Anything",
                        "domain": "verification",
                        "revenue_usd": 380.0,
                        "price_usd": 29.0,
                        "unit_cogs_usd": 0.003
                      }
                    }
                  }
                },
                "portfolio_allocator": {
                  "summary": "5. Profit-per-Compute Portfolio Allocation & Bottom-30% Prune",
                  "value": {
                    "operation": "portfolio_allocator",
                    "payload": {
                      "products": [
                        { "product_id": "alpha_kyb", "net_profit_usd": 280.0, "token_cost_usd": 8.0, "infra_cost_usd": 4.0, "current_price_usd": 29.0 },
                        { "product_id": "beta_audit", "net_profit_usd": 140.0, "token_cost_usd": 10.0, "infra_cost_usd": 6.0, "current_price_usd": 19.0 },
                        { "product_id": "gamma_wrapper", "net_profit_usd": 2.0, "token_cost_usd": 15.0, "infra_cost_usd": 5.0, "current_price_usd": 9.0 }
                      ]
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Evolution completed with tamper-evident EvolutionReceipt",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/EvolutionReceipt" }
              }
            }
          },
          "422": {
            "description": "Invalid, empty, cyclic, or zero-margin input strictly billed $0",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ZeroBillErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/v1/evolve": {
      "post": {
        "operationId": "evolveSingleV1",
        "tags": ["Evolution"],
        "summary": "Versioned alias for POST /evolve",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/EvolveRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Evolution completed with tamper-evident EvolutionReceipt",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/EvolutionReceipt" }
              }
            }
          },
          "422": {
            "description": "Invalid or rejected input ($0 billed)",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ZeroBillErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/evolve/batch": {
      "post": {
        "operationId": "evolveBatch",
        "tags": ["Evolution"],
        "summary": "Concurrent heterogeneous evolution batch with hard max_budget_micros cap",
        "description": "Executes multiple evolution items concurrently and halts cleanly before exceeding max_budget_micros. Rejected/422 rows bill $0.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/BatchEvolveRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Batch execution summary with per-item EvolutionReceipts",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/BatchEvolveResponse" }
              }
            }
          },
          "422": {
            "description": "Invalid or empty batch request ($0 billed)",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ZeroBillErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/mcp": {
      "post": {
        "operationId": "mcpJsonRpc",
        "tags": ["MCP"],
        "summary": "Native flat Streamable JSON-RPC 2.0 MCP endpoint",
        "description": "Supports initialize, notifications/initialized, ping, tools/list, and tools/call for evolve_gap_discovery, evolve_combo_synthesizer, evolve_zombie_auditor, evolve_sibling_mutator, evolve_portfolio_allocator, and evolve_batch.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/McpJsonRpcRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON-RPC 2.0 response envelope",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/McpJsonRpcResponse" }
              }
            }
          }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "operationId": "getOpenApiSpec",
        "tags": ["Discovery"],
        "summary": "Retrieve this OpenAPI 3.1.0 machine-readable specification",
        "responses": {
          "200": { "description": "OpenAPI JSON document" }
        }
      }
    },
    "/llms.txt": {
      "get": {
        "operationId": "getLlmsTxt",
        "tags": ["Discovery"],
        "summary": "AI agent discovery summary for evolve.fastmesh.dev",
        "responses": {
          "200": { "description": "Plain text AI discovery index" }
        }
      }
    },
    "/skill.md": {
      "get": {
        "operationId": "getSkillMd",
        "tags": ["Discovery"],
        "summary": "Agent skill contract for MCP, REST, and Treg Hub",
        "responses": {
          "200": { "description": "Markdown skill instructions" }
        }
      }
    },
    "/guides": {
      "get": {
        "operationId": "getGuidesIndex",
        "tags": ["Discovery"],
        "summary": "Technical product evolution guides index",
        "responses": {
          "200": { "description": "HTML guides directory" }
        }
      }
    },
    "/guides/{slug}": {
      "get": {
        "operationId": "getGuideBySlug",
        "tags": ["Discovery"],
        "summary": "Technical product evolution landing page",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": { "description": "HTML landing guide" },
          "404": { "description": "Guide not found" }
        }
      }
    },
    "/webhooks/creem": {
      "post": {
        "operationId": "handleCreemWebhook",
        "tags": ["Billing"],
        "summary": "Creem HMAC-SHA256 prepaid credit webhook ingress",
        "description": "Verifies creem-signature against CREEM_WEBHOOK_SECRET in constant time, deduplicates event_id, and atomically credits tenant balances inside SQLite WAL BEGIN IMMEDIATE transactions.",
        "parameters": [
          {
            "name": "creem-signature",
            "in": "header",
            "required": true,
            "schema": { "type": "string" },
            "description": "HMAC-SHA256 hex digest of raw request body."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/CreemWebhookPayload" }
            }
          }
        },
        "responses": {
          "200": { "description": "Webhook settled or deduplicated idempotently" },
          "401": { "description": "Invalid or missing creem-signature" },
          "503": { "description": "CREEM_WEBHOOK_SECRET not configured" }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "HealthResponse": {
        "type": "object",
        "required": ["status", "service"],
        "properties": {
          "status": { "type": "string", "enum": ["ok"] },
          "service": { "type": "string" },
          "version": { "type": "string" },
          "public_host": { "type": "string" },
          "port": { "type": "integer" },
          "operations": { "type": "array", "items": { "type": "string" } },
          "pricing": { "type": "object" },
          "cache_stats": { "type": "object" },
          "ledger_enabled": { "type": "boolean" },
          "mcp_enabled": { "type": "boolean" },
          "timestamp_utc": { "type": "string", "format": "date-time" }
        }
      },
      "EvolveRequest": {
        "type": "object",
        "required": ["operation"],
        "properties": {
          "operation": {
            "type": "string",
            "enum": [
              "gap_discovery",
              "combo_synthesizer",
              "zombie_auditor",
              "sibling_mutator",
              "portfolio_allocator"
            ]
          },
          "payload": { "type": "object" },
          "tenant_id": { "type": "string" },
          "recheck": { "type": "boolean", "default": false },
          "no_cache": { "type": "boolean", "default": false },
          "max_age_s": { "type": "integer", "minimum": 0 }
        }
      },
      "EvolutionReceipt": {
        "type": "object",
        "required": [
          "receipt_id",
          "operation",
          "ok",
          "verdict",
          "http_status",
          "payload_sha256",
          "result_sha256",
          "attestation_sha256",
          "billed_micros",
          "base_price_micros",
          "cache_status",
          "cache_hit",
          "cache_tier",
          "zero_bill_reason",
          "timestamp_utc",
          "result"
        ],
        "properties": {
          "receipt_id": { "type": "string" },
          "operation": {
            "type": "string",
            "enum": [
              "gap_discovery",
              "combo_synthesizer",
              "zombie_auditor",
              "sibling_mutator",
              "portfolio_allocator"
            ]
          },
          "ok": { "type": "boolean" },
          "verdict": { "type": "string", "enum": ["EVOLVED", "REJECTED", "INCONCLUSIVE"] },
          "http_status": { "type": "integer", "enum": [200, 422] },
          "payload_sha256": { "type": "string" },
          "result_sha256": { "type": "string" },
          "attestation_sha256": { "type": "string" },
          "billed_micros": { "type": "integer", "minimum": 0 },
          "base_price_micros": { "type": "integer", "minimum": 0 },
          "cache_status": {
            "type": "string",
            "enum": [
              "hit_new_tenant",
              "hit_repeat_tenant",
              "live",
              "unbilled_error",
              "unbilled_miss",
              "unbilled_422"
            ]
          },
          "cache_hit": { "type": "boolean" },
          "cache_tier": { "type": "string", "enum": ["live", "shared_cache", "recheck_10pct"] },
          "zero_bill_reason": { "type": "string" },
          "timestamp_utc": { "type": "string", "format": "date-time" },
          "result": { "type": "object" },
          "trace_redaction": { "type": "object" },
          "zero_trace_resale_attestation": { "type": "object" },
          "details": { "type": "object" }
        }
      },
      "BatchEvolveRequest": {
        "type": "object",
        "required": ["items"],
        "properties": {
          "items": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/EvolveRequest" }
          },
          "tenant_id": { "type": "string" },
          "max_budget_micros": { "type": "integer", "minimum": 0 },
          "max_workers": { "type": "integer", "minimum": 1, "maximum": 16 },
          "recheck": { "type": "boolean", "default": false }
        }
      },
      "BatchEvolveResponse": {
        "type": "object",
        "properties": {
          "batch_id": { "type": "string" },
          "tenant_id": { "type": "string" },
          "total_items": { "type": "integer" },
          "processed_items": { "type": "integer" },
          "stopped_by_budget": { "type": "boolean" },
          "total_billed_micros": { "type": "integer" },
          "zero_billed_rows": { "type": "integer" },
          "results": { "type": "array", "items": { "$ref": "#/components/schemas/EvolutionReceipt" } }
        }
      },
      "ZeroBillErrorResponse": {
        "type": "object",
        "required": ["ok", "billed_micros"],
        "properties": {
          "ok": { "type": "boolean", "enum": [false] },
          "verdict": { "type": "string", "enum": ["REJECTED", "INCONCLUSIVE"] },
          "http_status": { "type": "integer", "enum": [422] },
          "billed_micros": { "type": "integer", "enum": [0] },
          "zero_bill_reason": { "type": "string" },
          "error": { "type": "string" }
        }
      },
      "McpJsonRpcRequest": {
        "type": "object",
        "required": ["jsonrpc", "method"],
        "properties": {
          "jsonrpc": { "type": "string", "enum": ["2.0"] },
          "id": { "type": ["string", "integer", "null"] },
          "method": { "type": "string" },
          "params": { "type": "object" }
        }
      },
      "McpJsonRpcResponse": {
        "type": "object",
        "required": ["jsonrpc"],
        "properties": {
          "jsonrpc": { "type": "string", "enum": ["2.0"] },
          "id": { "type": ["string", "integer", "null"] },
          "result": { "type": "object" },
          "error": { "type": "object" }
        }
      },
      "CreemWebhookPayload": {
        "type": "object",
        "required": ["id", "eventType", "object"],
        "properties": {
          "id": { "type": "string" },
          "eventType": { "type": "string" },
          "object": { "type": "object" }
        }
      }
    }
  }
}
