{
  "openapi": "3.0.3",
  "info": {
    "title": "redirects.pro API",
    "version": "0.3.0",
    "description": "Paid API-first redirect checking for Agency and Enterprise workflow automation. API usage is counted by URL check unit; monthly URL units are shared with sitemap and CSV background audits in the web app."
  },
  "servers": [
    {
      "url": "https://redirects.pro"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      },
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Token"
      }
    },
    "schemas": {
      "ApiError": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": false
          },
          "error": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "feature": {
            "type": "string"
          },
          "api_usage": {
            "$ref": "#/components/schemas/ApiUsage"
          }
        },
        "required": ["success", "error"]
      },
      "ApiUsageWindow": {
        "type": "object",
        "properties": {
          "window": {
            "type": "string",
            "enum": ["minute", "hour", "day", "month"]
          },
          "limit": {
            "type": "integer"
          },
          "used": {
            "type": "integer"
          },
          "remaining": {
            "type": "integer"
          },
          "reset_at": {
            "type": "string",
            "format": "date-time"
          },
          "retry_after": {
            "type": "integer"
          }
        }
      },
      "ApiUsage": {
        "type": "object",
        "properties": {
          "allowed": {
            "type": "boolean"
          },
          "units": {
            "type": "integer",
            "description": "URL check units consumed or requested."
          },
          "window": {
            "type": "string"
          },
          "limit": {
            "type": "integer"
          },
          "remaining": {
            "type": "integer"
          },
          "reset_at": {
            "type": "string",
            "format": "date-time"
          },
          "retry_after": {
            "type": "integer"
          },
          "limits": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/ApiUsageWindow"
            }
          }
        }
      },
      "RedirectCheckResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "input_url": {
            "type": "string",
            "format": "uri"
          },
          "final_url": {
            "type": "string",
            "format": "uri"
          },
          "hop_count": {
            "type": "integer",
            "minimum": 0
          },
          "loop_detected": {
            "type": "boolean"
          },
          "chain": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "api_usage": {
            "$ref": "#/components/schemas/ApiUsage"
          }
        },
        "required": ["success"]
      },
      "BulkResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "total": {
            "type": "integer"
          },
          "results": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "url": {
                  "type": "string",
                  "format": "uri"
                },
                "result": {
                  "$ref": "#/components/schemas/RedirectCheckResponse"
                }
              }
            }
          },
          "api_usage": {
            "$ref": "#/components/schemas/ApiUsage"
          }
        },
        "required": ["success", "total", "results"]
      }
    }
  },
  "paths": {
    "/api.php": {
      "get": {
        "summary": "Check one redirect chain",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "action",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": ["check"]
            }
          },
          {
            "name": "url",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uri"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Redirect check completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RedirectCheckResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request or URL.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "403": {
            "description": "The active plan does not include API access.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "429": {
            "description": "API usage window exceeded.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "schema": {
                  "type": "string"
                }
              },
              "X-RateLimit-Window": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "502": {
            "description": "Target connection failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Check a small batch of redirect chains",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "action",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": ["bulk"]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "urls": {
                    "type": "array",
                    "maxItems": 100,
                    "items": {
                      "type": "string",
                      "format": "uri"
                    }
                  }
                },
                "required": ["urls"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Bulk API check completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BulkResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "403": {
            "description": "The active plan does not include bulk API access.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "429": {
            "description": "API usage window exceeded.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "schema": {
                  "type": "string"
                }
              },
              "X-RateLimit-Window": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    }
  }
}
