{
  "openapi": "3.0.3",
  "info": {
    "title": "CleanPage Edge API — Web-to-Markdown, Metadata & Tech-Stack Inspector",
    "version": "1.0.0",
    "description": "Zero-proxy edge API for AI Agents, RAG pipelines, n8n/Make workflows, and SEO/Lead enrichment. Converts any public webpage into clean LLM-ready Markdown, extracts OpenGraph & JSON-LD Schema.org metadata, fingerprints tech stacks, and discovers public contact/social signals in milliseconds.",
    "contact": {
      "name": "CleanPage Edge Support",
      "url": "https://github.com/bugkerb/cleanpage-edge-api"
    },
    "license": {
      "name": "MIT"
    }
  },
  "servers": [
    {
      "url": "https://cleanpage-edge-api.jiratthapol.workers.dev",
      "description": "Production Edge Endpoint"
    }
  ],
  "security": [
    {
      "RapidAPIKey": []
    },
    {
      "DirectApiKey": []
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "summary": "Health Check",
        "operationId": "getHealth",
        "security": [],
        "responses": {
          "200": {
            "description": "Service healthy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "example": true
                    },
                    "service": {
                      "type": "string",
                      "example": "cleanpage-edge-api"
                    },
                    "version": {
                      "type": "string",
                      "example": "1.0.0"
                    },
                    "runtime": {
                      "type": "string",
                      "example": "cloudflare-workers"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/markdown": {
      "get": {
        "summary": "Convert URL to Clean LLM-Ready Markdown",
        "description": "Fetches a public URL, removes navigation/footer/script/cookie clutter, resolves relative URLs, and returns clean Markdown with headings, word/token stats, reading time, and links.",
        "operationId": "getMarkdown",
        "parameters": [
          {
            "name": "url",
            "in": "query",
            "required": true,
            "description": "Public HTTP or HTTPS URL to fetch and analyze.",
            "schema": {
              "type": "string",
              "format": "uri",
              "example": "https://example.com"
            }
          },
          {
            "name": "mainOnly",
            "in": "query",
            "required": false,
            "description": "Focus on <main> or primary <article> content and strip nav/footer boilerplate.",
            "schema": {
              "type": "boolean",
              "default": true
            }
          },
          {
            "name": "includeLinks",
            "in": "query",
            "required": false,
            "description": "Preserve hyperlinks as [text](url) in Markdown output.",
            "schema": {
              "type": "boolean",
              "default": true
            }
          },
          {
            "name": "includeImages",
            "in": "query",
            "required": false,
            "description": "Include ![alt](src) images in Markdown output.",
            "schema": {
              "type": "boolean",
              "default": true
            }
          },
          {
            "name": "maxLength",
            "in": "query",
            "required": false,
            "description": "Optional character cap on Markdown output (ideal for strict LLM context budgets).",
            "schema": {
              "type": "integer",
              "minimum": 100,
              "maximum": 500000
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "description": "Response format: json (default) or markdown (raw text/markdown).",
            "schema": {
              "type": "string",
              "enum": [
                "json",
                "markdown"
              ],
              "default": "json"
            }
          },
          {
            "name": "refresh",
            "in": "query",
            "required": false,
            "description": "Set true to bypass edge cache and force a fresh fetch.",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Extracted Markdown payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MarkdownEnvelope"
                }
              },
              "text/markdown": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "415": {
            "$ref": "#/components/responses/UnsupportedType"
          },
          "422": {
            "$ref": "#/components/responses/BotProtected"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "502": {
            "$ref": "#/components/responses/UpstreamError"
          }
        }
      },
      "post": {
        "summary": "Convert URL to Clean Markdown (POST JSON)",
        "operationId": "postMarkdown",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExtractRequestBody"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Extracted Markdown payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MarkdownEnvelope"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "415": {
            "$ref": "#/components/responses/UnsupportedType"
          },
          "422": {
            "$ref": "#/components/responses/BotProtected"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "502": {
            "$ref": "#/components/responses/UpstreamError"
          }
        }
      }
    },
    "/v1/metadata": {
      "get": {
        "summary": "Extract OpenGraph, Twitter Cards & Schema.org JSON-LD",
        "description": "Extracts title, description, canonical URL, language, favicon, OpenGraph, Twitter Card tags, RSS/Atom feeds, hreflang links, and parsed JSON-LD Schema.org blocks.",
        "operationId": "getMetadata",
        "parameters": [
          {
            "name": "url",
            "in": "query",
            "required": true,
            "description": "Public HTTP or HTTPS URL to fetch and analyze.",
            "schema": {
              "type": "string",
              "format": "uri",
              "example": "https://example.com"
            }
          },
          {
            "name": "refresh",
            "in": "query",
            "required": false,
            "description": "Set true to bypass edge cache and force a fresh fetch.",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Structured page metadata",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GenericSuccessEnvelope"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "415": {
            "$ref": "#/components/responses/UnsupportedType"
          },
          "422": {
            "$ref": "#/components/responses/BotProtected"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "502": {
            "$ref": "#/components/responses/UpstreamError"
          }
        }
      }
    },
    "/v1/inspect": {
      "get": {
        "summary": "Inspect Website Tech Stack, Contact Signals & Security Headers",
        "description": "Fingerprints frameworks, CMS/ecommerce platforms, CDNs, analytics, payment providers, public contact emails, phone numbers, social profiles, key pages (/pricing, /docs, /careers), and HTTP security headers.",
        "operationId": "inspectWebsite",
        "parameters": [
          {
            "name": "url",
            "in": "query",
            "required": true,
            "description": "Public HTTP or HTTPS URL to fetch and analyze.",
            "schema": {
              "type": "string",
              "format": "uri",
              "example": "https://example.com"
            }
          },
          {
            "name": "refresh",
            "in": "query",
            "required": false,
            "description": "Set true to bypass edge cache and force a fresh fetch.",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Website intelligence report",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GenericSuccessEnvelope"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "415": {
            "$ref": "#/components/responses/UnsupportedType"
          },
          "422": {
            "$ref": "#/components/responses/BotProtected"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "502": {
            "$ref": "#/components/responses/UpstreamError"
          }
        }
      }
    },
    "/v1/extract": {
      "get": {
        "summary": "All-in-One Extraction (Markdown + Metadata + Tech Stack + Signals)",
        "description": "Single-call unified endpoint returning clean Markdown, OpenGraph/JSON-LD metadata, tech stack, and contact/social signals for AI agents and automation pipelines.",
        "operationId": "extractAll",
        "parameters": [
          {
            "name": "url",
            "in": "query",
            "required": true,
            "description": "Public HTTP or HTTPS URL to fetch and analyze.",
            "schema": {
              "type": "string",
              "format": "uri",
              "example": "https://example.com"
            }
          },
          {
            "name": "mainOnly",
            "in": "query",
            "required": false,
            "description": "Focus on <main> or primary <article> content and strip nav/footer boilerplate.",
            "schema": {
              "type": "boolean",
              "default": true
            }
          },
          {
            "name": "includeLinks",
            "in": "query",
            "required": false,
            "description": "Preserve hyperlinks as [text](url) in Markdown output.",
            "schema": {
              "type": "boolean",
              "default": true
            }
          },
          {
            "name": "includeImages",
            "in": "query",
            "required": false,
            "description": "Include ![alt](src) images in Markdown output.",
            "schema": {
              "type": "boolean",
              "default": true
            }
          },
          {
            "name": "maxLength",
            "in": "query",
            "required": false,
            "description": "Optional character cap on Markdown output (ideal for strict LLM context budgets).",
            "schema": {
              "type": "integer",
              "minimum": 100,
              "maximum": 500000
            }
          },
          {
            "name": "refresh",
            "in": "query",
            "required": false,
            "description": "Set true to bypass edge cache and force a fresh fetch.",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Complete unified webpage intelligence payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GenericSuccessEnvelope"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "415": {
            "$ref": "#/components/responses/UnsupportedType"
          },
          "422": {
            "$ref": "#/components/responses/BotProtected"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "502": {
            "$ref": "#/components/responses/UpstreamError"
          }
        }
      },
      "post": {
        "summary": "All-in-One Extraction (POST JSON)",
        "operationId": "postExtractAll",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExtractRequestBody"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Complete unified webpage intelligence payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GenericSuccessEnvelope"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "415": {
            "$ref": "#/components/responses/UnsupportedType"
          },
          "422": {
            "$ref": "#/components/responses/BotProtected"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "502": {
            "$ref": "#/components/responses/UpstreamError"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "RapidAPIKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-RapidAPI-Key",
        "description": "RapidAPI subscription key"
      },
      "DirectApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Direct edge API key (or Authorization: Bearer <key>)"
      }
    },
    "schemas": {
      "ExtractRequestBody": {
        "type": "object",
        "required": [
          "url"
        ],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "example": "https://example.com"
          },
          "mainOnly": {
            "type": "boolean",
            "default": true
          },
          "includeLinks": {
            "type": "boolean",
            "default": true
          },
          "includeImages": {
            "type": "boolean",
            "default": true
          },
          "maxLength": {
            "type": "integer",
            "minimum": 100,
            "maximum": 500000
          },
          "format": {
            "type": "string",
            "enum": [
              "json",
              "markdown"
            ],
            "default": "json"
          },
          "refresh": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "MarkdownEnvelope": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "example": true
          },
          "data": {
            "type": "object",
            "properties": {
              "url": {
                "type": "string"
              },
              "finalUrl": {
                "type": "string"
              },
              "title": {
                "type": "string",
                "nullable": true
              },
              "description": {
                "type": "string",
                "nullable": true
              },
              "excerpt": {
                "type": "string",
                "nullable": true
              },
              "markdown": {
                "type": "string"
              },
              "truncated": {
                "type": "boolean"
              },
              "stats": {
                "type": "object",
                "properties": {
                  "wordCount": {
                    "type": "integer"
                  },
                  "charCount": {
                    "type": "integer"
                  },
                  "estimatedTokens": {
                    "type": "integer"
                  },
                  "readingTimeMinutes": {
                    "type": "integer"
                  }
                }
              },
              "headings": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "level": {
                      "type": "integer"
                    },
                    "text": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "meta": {
            "type": "object",
            "properties": {
              "requestId": {
                "type": "string"
              },
              "cached": {
                "type": "boolean"
              },
              "fetchDurationMs": {
                "type": "integer"
              },
              "processingDurationMs": {
                "type": "integer"
              }
            }
          }
        }
      },
      "GenericSuccessEnvelope": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "example": true
          },
          "data": {
            "type": "object"
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "meta": {
            "type": "object"
          }
        }
      },
      "ErrorEnvelope": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "example": false
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "details": {
                "type": "object"
              }
            }
          },
          "meta": {
            "type": "object"
          }
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Invalid URL or query parameter",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing or invalid API key / RapidAPI proxy secret",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      },
      "UnsupportedType": {
        "description": "Target URL returned binary/non-text content",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      },
      "BotProtected": {
        "description": "Target site is gated by an automated anti-bot challenge",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Per-minute rate limit exceeded",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      },
      "UpstreamError": {
        "description": "Target server failed or timed out",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      }
    }
  }
}
