{
  "openapi": "3.0.3",
  "info": {
    "title": "Text Stats & Readability API",
    "description": "Analyze text readability, word statistics, and keywords.\nUses Flesch Reading Ease and Flesch-Kincaid Grade formulas — no ML required.\nSupports English and German texts.\n",
    "version": "1.0.0",
    "contact": {
      "name": "RevenueLab"
    }
  },
  "servers": [
    {
      "url": "https://api.sprytools.com/v1/text",
      "description": "Production (SpryTools API Gateway)"
    }
  ],
  "security": [
    {
      "ApiKeyHeader": []
    },
    {
      "RapidApiProxy": []
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      },
      "RapidApiProxy": {
        "type": "apiKey",
        "in": "header",
        "name": "x-rapidapi-proxy-secret",
        "description": "RapidAPI proxy secret (set automatically by RapidAPI)"
      }
    },
    "schemas": {
      "TextRequest": {
        "type": "object",
        "required": [
          "text"
        ],
        "properties": {
          "text": {
            "type": "string",
            "description": "Text to analyze (any language)",
            "example": "The quick brown fox jumps over the lazy dog."
          },
          "topN": {
            "type": "integer",
            "description": "Maximum number of keywords to return (default 10, max 50)",
            "default": 10,
            "minimum": 1,
            "maximum": 50
          }
        }
      },
      "AnalyzeResponse": {
        "type": "object",
        "properties": {
          "wordCount": {
            "type": "integer",
            "example": 9
          },
          "sentenceCount": {
            "type": "integer",
            "example": 1
          },
          "paragraphCount": {
            "type": "integer",
            "example": 1
          },
          "charCount": {
            "type": "integer",
            "example": 44
          },
          "avgWordsPerSentence": {
            "type": "number",
            "example": 9
          },
          "avgSyllablesPerWord": {
            "type": "number",
            "example": 1.22
          },
          "fleschReadingEase": {
            "type": "number",
            "description": "0–100 score. Higher = easier to read.",
            "example": 79.1
          },
          "fleschKincaidGrade": {
            "type": "number",
            "description": "US grade level. Lower = more accessible.",
            "example": 4.3
          },
          "estimatedReadingTimeSeconds": {
            "type": "integer",
            "example": 3
          },
          "topKeywords": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Keyword"
            }
          },
          "languageDetected": {
            "type": "string",
            "enum": [
              "en",
              "de",
              "unknown"
            ],
            "example": "en"
          }
        }
      },
      "Keyword": {
        "type": "object",
        "properties": {
          "word": {
            "type": "string",
            "example": "fox"
          },
          "count": {
            "type": "integer",
            "example": 1
          },
          "density": {
            "type": "number",
            "description": "Percentage of non-stopword occurrences",
            "example": 14.29
          }
        }
      },
      "ReadabilityResponse": {
        "type": "object",
        "properties": {
          "fleschReadingEase": {
            "type": "number",
            "example": 79.1
          },
          "fleschKincaidGrade": {
            "type": "number",
            "example": 4.3
          },
          "avgWordsPerSentence": {
            "type": "number",
            "example": 9
          },
          "avgSyllablesPerWord": {
            "type": "number",
            "example": 1.22
          },
          "interpretation": {
            "type": "string",
            "example": "Fairly Easy"
          }
        }
      },
      "StatsResponse": {
        "type": "object",
        "properties": {
          "wordCount": {
            "type": "integer"
          },
          "sentenceCount": {
            "type": "integer"
          },
          "paragraphCount": {
            "type": "integer"
          },
          "charCount": {
            "type": "integer"
          },
          "charCountNoSpaces": {
            "type": "integer"
          },
          "avgWordsPerSentence": {
            "type": "number"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        }
      }
    }
  },
  "paths": {
    "/health": {
      "get": {
        "summary": "Health check",
        "security": [],
        "responses": {
          "200": {
            "description": "Service is healthy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "ok"
                    },
                    "service": {
                      "type": "string",
                      "example": "text-api"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/analyze": {
      "post": {
        "summary": "Full text analysis",
        "description": "Returns all statistics including readability scores, keyword extraction, and language detection.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TextRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Analysis result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnalyzeResponse"
                }
              }
            }
          },
          "400": {
            "description": "Missing or empty text",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key"
          },
          "429": {
            "description": "Rate limit exceeded"
          }
        }
      }
    },
    "/api/v1/readability": {
      "post": {
        "summary": "Readability scores only",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TextRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Readability scores",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReadabilityResponse"
                }
              }
            }
          },
          "400": {
            "description": "Missing or empty text"
          },
          "401": {
            "description": "Missing API key"
          }
        }
      }
    },
    "/api/v1/keywords": {
      "post": {
        "summary": "Top keyword extraction",
        "description": "Extracts most frequent meaningful words, filtered by stop words.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TextRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Top keywords",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "topKeywords": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Keyword"
                      }
                    },
                    "count": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Missing or empty text"
          },
          "401": {
            "description": "Missing API key"
          }
        }
      }
    },
    "/api/v1/summary/stats": {
      "post": {
        "summary": "Word, sentence, and character counts",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TextRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Text statistics",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StatsResponse"
                }
              }
            }
          },
          "400": {
            "description": "Missing or empty text"
          },
          "401": {
            "description": "Missing API key"
          }
        }
      }
    }
  }
}