{
  "openapi": "3.1.0",
  "info": {
    "title": "Compile-Anything — Polymorphic Commercial Micro-Product Compiler API",
    "version": "1.0.0",
    "summary": "Compile natural-language briefs, competitor pricing specs, OpenAPI 3.x schemas, CSV/JSON lookup tables, or deterministic Python specs into runnable, verified, monetized HTTP/MCP micro-product bundles in 60 seconds.",
    "description": "Compile-Anything (`compile.fastmesh.dev`, task `ANY-A06`) compiles 5 heterogeneous input types (`brief`, `competitor`, `openapi`, `table`, `python_spec`) into complete commercial micro-product bundles containing a runnable pure-stdlib HTTP/MCP server, `gateway_route.json`, Creem prepaid SKU manifest, 4-file QuickJS `treg_hub` package, Causal Bazaar paid card, responsive Try-Now HTML portal, SEO/GEO launch pack, and automated live smoke verification. Zero Prompt & Trace Resale Guarantee: customer specs and execution outputs are never resold or used for model training. HTTP 422 validation or safety rejections strictly bill `$0` (`billed_micros: 0`).",
    "contact": {
      "name": "Compile-Anything Support",
      "url": "https://compile.fastmesh.dev/"
    },
    "license": {
      "name": "Commercial Prepaid API — Zero Prompt & Trace Resale",
      "url": "https://compile.fastmesh.dev/skill.md"
    },
    "x-task-id": "ANY-A06",
    "x-hand-id": "hand_any_a06_compile_anything_v1",
    "x-trust-policy": {
      "zero_prompt_or_trace_resale": true,
      "zero_model_training_on_customer_payloads": true,
      "zero_charge_on_422_or_failed_compile": true,
      "external_spend_cap_usd": 2.0,
      "cross_tenant_cache_isolation": true
    }
  },
  "servers": [
    {
      "url": "https://compile.fastmesh.dev",
      "description": "Production HTTPS Gateway"
    },
    {
      "url": "http://127.0.0.1:8806",
      "description": "Local Upstream Development Server"
    }
  ],
  "tags": [
    {
      "name": "Health",
      "description": "Service liveness, supported input modes, and content-addressed cache statistics"
    },
    {
      "name": "Compiler",
      "description": "Polymorphic 5-mode compilation into verified runnable commercial micro-products"
    },
    {
      "name": "Billing",
      "description": "Creem prepaid credit packs and HMAC-SHA256 verified webhook fulfillment"
    },
    {
      "name": "MCP",
      "description": "Native JSON-RPC 2.0 Model Context Protocol endpoint"
    },
    {
      "name": "AgentDiscovery",
      "description": "Machine-readable discovery manifests for coding agents and portals"
    }
  ],
  "paths": {
    "/": {
      "get": {
        "operationId": "getPortalHtml",
        "tags": [
          "AgentDiscovery"
        ],
        "summary": "Serve the 5-second Try-Now commercial compiler portal",
        "responses": {
          "200": {
            "description": "Self-contained Try-Now HTML workbench",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/health": {
      "get": {
        "operationId": "getHealth",
        "tags": [
          "Health"
        ],
        "summary": "Return service health, supported input types, and cache metrics",
        "responses": {
          "200": {
            "description": "Service is healthy and ready to compile",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/compile": {
      "post": {
        "operationId": "compileSpec",
        "tags": [
          "Compiler"
        ],
        "summary": "Compile any of 5 heterogeneous specs into a verified monetized micro-product bundle",
        "description": "Compiles `brief`, `competitor`, `openapi`, `table`, or `python_spec` inputs into a runnable pure-stdlib HTTP/MCP service, `gateway_route.json`, Creem SKUs, `treg_hub` QuickJS bundle, Causal Bazaar card, Try-Now HTML UI, and SEO/GEO kit. Malformed, unsafe AST, path-traversal, or SSRF inputs return HTTP 422 with `billed_micros: 0`.",
        "parameters": [
          {
            "name": "X-Tenant-Id",
            "in": "header",
            "required": false,
            "description": "Caller tenant identifier for prepaid credit metering and cross-tenant cache isolation.",
            "schema": {
              "type": "string",
              "default": "anon_sandbox"
            }
          },
          {
            "name": "X-Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Optional client idempotency key preventing duplicate credit debits on retries.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CompileRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Compilation succeeded and produced a verified micro-product bundle",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompileResponse"
                }
              }
            }
          },
          "402": {
            "description": "Insufficient prepaid credits for metered tenant request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompileErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation, AST safety, path-traversal, or SSRF rejection — strictly $0 billed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompileErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/skus": {
      "get": {
        "operationId": "getSkus",
        "tags": [
          "Billing"
        ],
        "summary": "Retrieve Creem prepaid credit packs and SHA-256 manifest checksum",
        "responses": {
          "200": {
            "description": "Creem prepaid credit SKU catalog",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SkusManifestResponse"
                }
              }
            }
          }
        }
      }
    },
    "/webhooks/creem": {
      "post": {
        "operationId": "receiveCreemWebhook",
        "tags": [
          "Billing"
        ],
        "summary": "Process HMAC-SHA256 signed Creem payment webhooks idempotently",
        "description": "Verifies the `creem-signature` header via HMAC-SHA256 (`hmac.compare_digest`), enforces `event_id` replay protection, and atomically grants prepaid credits on `checkout.completed` or `order.paid` events.",
        "parameters": [
          {
            "name": "creem-signature",
            "in": "header",
            "required": true,
            "description": "HMAC-SHA256 hex digest (bare or `sha256=<hex>`) computed over raw request bytes using `CREEM_WEBHOOK_SECRET`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreemWebhookEvent"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Webhook accepted (credits granted or idempotent replay acknowledged)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreemWebhookResponse"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON or missing event_id",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreemWebhookResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid Creem HMAC-SHA256 signature",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreemWebhookResponse"
                }
              }
            }
          },
          "422": {
            "description": "Signed event references an unknown SKU or product ID",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreemWebhookResponse"
                }
              }
            }
          }
        }
      }
    },
    "/mcp": {
      "post": {
        "operationId": "handleMcpJsonRpc",
        "tags": [
          "MCP"
        ],
        "summary": "Native JSON-RPC 2.0 Model Context Protocol endpoint",
        "description": "Supports `initialize`, `tools/list`, and `tools/call` for `compile_spec`, `preview_bundle`, `verify_bundle`, `list_input_types`, and `get_cache_stats`.",
        "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": [
          "AgentDiscovery"
        ],
        "summary": "Return this OpenAPI 3.1.0 specification document",
        "responses": {
          "200": {
            "description": "OpenAPI 3.1.0 JSON schema",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/llms.txt": {
      "get": {
        "operationId": "getLlmsTxt",
        "tags": [
          "AgentDiscovery"
        ],
        "summary": "Return agent-readable llms.txt discovery index",
        "responses": {
          "200": {
            "description": "Plain-text llms.txt discovery manifest",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/skill.md": {
      "get": {
        "operationId": "getSkillMd",
        "tags": [
          "AgentDiscovery"
        ],
        "summary": "Return 10-second coding-agent onboarding guide in Markdown",
        "responses": {
          "200": {
            "description": "Markdown integration skill guide",
            "content": {
              "text/markdown": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "CreemPrepaidBearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Optional Creem prepaid API key for metered production workloads."
      },
      "CreemWebhookHmac": {
        "type": "apiKey",
        "in": "header",
        "name": "creem-signature",
        "description": "HMAC-SHA256 digest verified with CREEM_WEBHOOK_SECRET."
      }
    },
    "schemas": {
      "HealthResponse": {
        "type": "object",
        "required": [
          "status",
          "service",
          "task_id",
          "domain",
          "supported_inputs"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "ok"
            ]
          },
          "service": {
            "type": "string",
            "example": "compile-anything"
          },
          "task_id": {
            "type": "string",
            "example": "ANY-A06"
          },
          "domain": {
            "type": "string",
            "example": "compile.fastmesh.dev"
          },
          "supported_inputs": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "brief",
                "competitor",
                "openapi",
                "table",
                "python_spec"
              ]
            }
          },
          "cache_stats": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "CompileRequest": {
        "type": "object",
        "required": [
          "input_type",
          "spec"
        ],
        "properties": {
          "input_type": {
            "type": "string",
            "enum": [
              "brief",
              "competitor",
              "openapi",
              "table",
              "python_spec"
            ]
          },
          "spec": {
            "oneOf": [
              {
                "type": "object",
                "additionalProperties": true
              },
              {
                "type": "string",
                "minLength": 1
              }
            ]
          },
          "slug": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_-]{1,39}$"
          },
          "dry_run": {
            "type": "boolean",
            "default": false
          },
          "verify_live": {
            "type": "boolean",
            "default": true
          },
          "output_dir": {
            "type": "string"
          }
        }
      },
      "CompileResponse": {
        "type": "object",
        "required": [
          "ok",
          "status_code",
          "task_id",
          "input_type",
          "slug",
          "domain",
          "bundle_sha256",
          "cache_hit",
          "billed_micros",
          "file_tree"
        ],
        "properties": {
          "ok": {
            "type": "boolean",
            "const": true
          },
          "status_code": {
            "type": "integer",
            "const": 200
          },
          "task_id": {
            "type": "string",
            "example": "ANY-A06"
          },
          "hand_id": {
            "type": "string",
            "example": "hand_any_a06_compile_anything_v1"
          },
          "input_type": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "domain": {
            "type": "string"
          },
          "bundle_sha256": {
            "type": "string"
          },
          "receipt_sha256": {
            "type": "string"
          },
          "cache_hit": {
            "type": "boolean"
          },
          "cache_status": {
            "type": "string"
          },
          "billed_micros": {
            "type": "integer",
            "minimum": 0
          },
          "file_tree": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "files": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "gateway_route": {
            "type": "object",
            "additionalProperties": true
          },
          "skus": {
            "type": "object",
            "additionalProperties": true
          },
          "mcp_tools": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "treg_hub": {
            "type": "object",
            "additionalProperties": true
          },
          "bazaar_card": {
            "type": "object",
            "additionalProperties": true
          },
          "try_now_html": {
            "type": "string"
          },
          "verification": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "CompileErrorResponse": {
        "type": "object",
        "required": [
          "ok",
          "status_code",
          "error_code",
          "error",
          "billed_micros"
        ],
        "properties": {
          "ok": {
            "type": "boolean",
            "const": false
          },
          "status_code": {
            "type": "integer",
            "example": 422
          },
          "error_code": {
            "type": "string"
          },
          "error": {
            "type": "string"
          },
          "error_detail": {
            "type": "string"
          },
          "billed_micros": {
            "type": "integer",
            "const": 0
          }
        }
      },
      "SkuItem": {
        "type": "object",
        "required": [
          "sku_id",
          "creem_product_id",
          "name",
          "price_usd",
          "credits",
          "unit_price_micros",
          "checkout_url"
        ],
        "properties": {
          "sku_id": {
            "type": "string"
          },
          "creem_product_id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "tier": {
            "type": "string"
          },
          "price_usd": {
            "type": "number"
          },
          "price_cents": {
            "type": "integer"
          },
          "credits": {
            "type": "integer"
          },
          "unit_price_micros": {
            "type": "integer"
          },
          "billing_type": {
            "type": "string"
          },
          "highlight": {
            "type": "boolean"
          },
          "checkout_url": {
            "type": "string",
            "format": "uri"
          },
          "description": {
            "type": "string"
          }
        }
      },
      "SkusManifestResponse": {
        "type": "object",
        "required": [
          "schema_version",
          "task_id",
          "domain",
          "currency",
          "manifest_checksum_sha256",
          "skus"
        ],
        "properties": {
          "schema_version": {
            "type": "string"
          },
          "task_id": {
            "type": "string"
          },
          "service": {
            "type": "string"
          },
          "domain": {
            "type": "string"
          },
          "currency": {
            "type": "string"
          },
          "default_compile_price_micros": {
            "type": "integer"
          },
          "cache_repeat_price_micros": {
            "type": "integer"
          },
          "zero_charge_on_422": {
            "type": "boolean"
          },
          "external_spend_cap_usd": {
            "type": "number"
          },
          "manifest_checksum_sha256": {
            "type": "string"
          },
          "skus": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SkuItem"
            }
          }
        }
      },
      "CreemWebhookEvent": {
        "type": "object",
        "required": [
          "id",
          "eventType"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique Creem event identifier used for idempotent replay protection."
          },
          "eventType": {
            "type": "string",
            "enum": [
              "checkout.completed",
              "order.paid",
              "subscription.paid",
              "refund.created",
              "subscription.canceled"
            ]
          },
          "object": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "CreemWebhookResponse": {
        "type": "object",
        "required": [
          "ok",
          "status_code",
          "credits_granted",
          "idempotent_replay"
        ],
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "status_code": {
            "type": "integer"
          },
          "event_id": {
            "type": "string"
          },
          "event_type": {
            "type": "string"
          },
          "tenant_id": {
            "type": "string"
          },
          "sku_id": {
            "type": "string"
          },
          "creem_product_id": {
            "type": "string"
          },
          "credits_granted": {
            "type": "integer"
          },
          "balance_credits": {
            "type": "integer"
          },
          "idempotent_replay": {
            "type": "boolean"
          },
          "error": {
            "type": "string"
          }
        }
      },
      "McpJsonRpcRequest": {
        "type": "object",
        "required": [
          "jsonrpc",
          "method"
        ],
        "properties": {
          "jsonrpc": {
            "type": "string",
            "const": "2.0"
          },
          "id": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ]
          },
          "method": {
            "type": "string",
            "enum": [
              "initialize",
              "tools/list",
              "tools/call"
            ]
          },
          "params": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "McpJsonRpcResponse": {
        "type": "object",
        "required": [
          "jsonrpc"
        ],
        "properties": {
          "jsonrpc": {
            "type": "string",
            "const": "2.0"
          },
          "id": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ]
          },
          "result": {
            "type": "object",
            "additionalProperties": true
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "integer"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
