{
  "openapi": "3.1.0",
  "info": {
    "title": "CleanMyPrompt API",
    "version": "1.0.0",
    "description": "Free API for cleaning, compressing, and analyzing text before sending to AI models. Removes PII, API keys, and secrets. Reduces token count by up to 40%. No API key required.",
    "contact": {
      "name": "CleanMyPrompt",
      "url": "https://cleanmyprompt.io"
    },
    "license": {
      "name": "MIT"
    }
  },
  "servers": [
    {
      "url": "https://cleanmyprompt.io",
      "description": "Production"
    }
  ],
  "paths": {
    "/api/v1/clean": {
      "post": {
        "operationId": "cleanText",
        "summary": "Clean, compress, or format text",
        "description": "Full text cleaning pipeline. Optionally redacts PII and secrets, cleans formatting, compresses tokens, or converts to JSON.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CleanRequest"
              },
              "example": {
                "text": "Dear Dr. Sarah Johnson, here is the API key: sk-proj-abc123. My SSN is 123-45-6789.",
                "mode": "standard",
                "redact": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully cleaned text",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CleanResponse"
                }
              }
            },
            "headers": {
              "X-RateLimit-Remaining": {
                "schema": { "type": "integer" },
                "description": "Remaining requests in current window"
              },
              "X-RateLimit-Limit": {
                "schema": { "type": "integer" },
                "description": "Maximum requests per minute"
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": { "type": "integer" },
                "description": "Seconds to wait before retrying"
              }
            }
          }
        }
      },
      "options": {
        "operationId": "cleanTextOptions",
        "summary": "CORS preflight",
        "responses": {
          "204": { "description": "CORS headers returned" }
        }
      }
    },
    "/api/v1/analyze": {
      "post": {
        "operationId": "analyzeText",
        "summary": "Scan text for secrets and PII without modifying it",
        "description": "Performs a read-only analysis of the input text, detecting API keys, PII patterns, and external links. Does not modify the text.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AnalyzeRequest"
              },
              "example": {
                "text": "Contact sarah@example.com or call +1-555-867-5309. AWS key: AKIAIOSFODNN7EXAMPLE"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Analysis complete",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnalyzeResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "CleanRequest": {
        "type": "object",
        "required": ["text"],
        "properties": {
          "text": {
            "type": "string",
            "maxLength": 100000,
            "description": "The text to clean"
          },
          "mode": {
            "type": "string",
            "enum": ["standard", "squeeze", "json"],
            "default": "standard",
            "description": "Cleaning mode: standard (fix formatting), squeeze (compress tokens), json (convert to JSON)"
          },
          "redact": {
            "type": "boolean",
            "default": true,
            "description": "Whether to redact PII and secrets"
          },
          "aggressive": {
            "type": "boolean",
            "default": false,
            "description": "Enable aggressive compression (squeeze mode only)"
          },
          "lang": {
            "type": "string",
            "enum": ["en", "de", "fr", "es"],
            "default": "en",
            "description": "Language of the input text"
          }
        }
      },
      "CleanResponse": {
        "type": "object",
        "properties": {
          "cleaned": {
            "type": "string",
            "description": "The cleaned/processed text"
          },
          "stats": {
            "type": "object",
            "properties": {
              "originalChars": { "type": "integer" },
              "cleanedChars": { "type": "integer" },
              "originalTokens": { "type": "integer" },
              "cleanedTokens": { "type": "integer" },
              "tokensSaved": { "type": "integer" },
              "reductionPercent": { "type": "integer" },
              "piiFound": { "type": "integer" },
              "secretsFound": { "type": "integer" },
              "linksFound": { "type": "integer" }
            }
          }
        }
      },
      "AnalyzeRequest": {
        "type": "object",
        "required": ["text"],
        "properties": {
          "text": {
            "type": "string",
            "maxLength": 100000,
            "description": "The text to analyze"
          }
        }
      },
      "AnalyzeResponse": {
        "type": "object",
        "properties": {
          "isClean": {
            "type": "boolean",
            "description": "True if no threats were detected"
          },
          "findings": {
            "type": "object",
            "properties": {
              "secrets": { "type": "integer", "description": "Number of API keys / secrets found" },
              "pii": { "type": "integer", "description": "Number of PII items found (emails, phones, SSNs)" },
              "links": { "type": "integer", "description": "Number of external links found" }
            }
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Error message"
          }
        }
      }
    }
  }
}
