{
  "openapi": "3.1.0",
  "info": {
    "title": "KinetixSEO API",
    "version": "v1",
    "description": "URL in, SEO result document out. All routes require a KinetixSEO personal access token (create one at https://kinetixseo.com/tokens) sent as a Bearer token, scoped to the ability each route needs. PLAN_095 §6.1 — published for machine/agent discovery; kept hand-written and in sync with routes/api.php rather than generated, so update this file whenever that route file changes.",
    "contact": {
      "email": "infra@aevonix.nl"
    }
  },
  "servers": [
    {
      "url": "https://kinetixseo.com/api/v1",
      "description": "Production"
    }
  ],
  "security": [
    { "bearerAuth": [] }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Personal access token created at /tokens. Each token is scoped to one or more abilities (process:url, results:read, tokens:manage, pages:read); a route rejects a token that lacks the ability it requires."
      }
    },
    "schemas": {
      "QueuedJob": {
        "type": "object",
        "properties": {
          "status": { "type": "string", "enum": ["queued"] },
          "job_id": { "type": "string", "description": "ULID of the created result/job record." }
        },
        "required": ["status", "job_id"]
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "status": { "type": "string", "enum": ["error"] },
          "message": { "type": "string" }
        },
        "required": ["status", "message"]
      },
      "ValidationErrorResponse": {
        "type": "object",
        "description": "Standard Laravel 422 validation error shape.",
        "properties": {
          "message": { "type": "string" },
          "errors": {
            "type": "object",
            "additionalProperties": { "type": "array", "items": { "type": "string" } }
          }
        }
      }
    },
    "requestBodies": {
      "ProcessUrlRequest": {
        "required": true,
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "url": {
                  "type": "string",
                  "format": "uri",
                  "maxLength": 2048,
                  "description": "http(s) URL to fetch and analyze. A scheme-less input is coerced to https:// before validation. Must resolve to a public (non-private/loopback) address."
                },
                "fields": {
                  "type": "array",
                  "description": "Optional subset of result segments to compute. Omit to compute all.",
                  "items": {
                    "type": "string",
                    "enum": [
                      "identity", "fetch", "content", "open_graph", "structured_data", "hreflang", "secrets",
                      "headings", "meta_seo", "links", "images", "video", "geo_signals", "quality",
                      "content.markdown", "content.plain_text", "content.html",
                      "content.word_count", "content.reading_time_minutes", "content.readability_score"
                    ]
                  }
                }
              },
              "required": ["url"]
            }
          }
        }
      }
    }
  },
  "paths": {
    "/process": {
      "post": {
        "summary": "Submit a URL for processing (alias of /process/async)",
        "description": "Kept as a distinct route from /process/async for backwards-compatible URLs; both are asynchronous and return the same 202 payload.",
        "operationId": "processUrl",
        "security": [{ "bearerAuth": ["process:url"] }],
        "requestBody": { "$ref": "#/components/requestBodies/ProcessUrlRequest" },
        "responses": {
          "202": { "description": "Job queued.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/QueuedJob" } } } },
          "402": { "description": "Insufficient credit balance.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
          "422": { "description": "Validation failed.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ValidationErrorResponse" } } } }
        }
      }
    },
    "/process/async": {
      "post": {
        "summary": "Submit a URL for processing",
        "operationId": "processUrlAsync",
        "security": [{ "bearerAuth": ["process:url"] }],
        "requestBody": { "$ref": "#/components/requestBodies/ProcessUrlRequest" },
        "responses": {
          "202": { "description": "Job queued.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/QueuedJob" } } } },
          "402": { "description": "Insufficient credit balance.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
          "422": { "description": "Validation failed.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ValidationErrorResponse" } } } }
        }
      }
    },
    "/process/{jobId}": {
      "get": {
        "summary": "Fetch a processing job's status/result",
        "operationId": "getProcessStatus",
        "security": [{ "bearerAuth": ["results:read"] }],
        "parameters": [
          { "name": "jobId", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Job status (shape depends on the job's `status` — pending/done/failed).", "content": { "application/json": { "schema": { "type": "object" } } } },
          "404": { "description": "No job with that ID belongs to this user.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      }
    },
    "/seo/audit": {
      "post": {
        "summary": "Run an SEO audit on a URL (spends one page_fix credit)",
        "operationId": "seoAudit",
        "security": [{ "bearerAuth": ["process:url"] }],
        "requestBody": { "$ref": "#/components/requestBodies/ProcessUrlRequest" },
        "responses": {
          "202": { "description": "Job queued.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/QueuedJob" } } } },
          "402": { "description": "No credits remaining.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
          "422": { "description": "Validation failed.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ValidationErrorResponse" } } } }
        }
      }
    },
    "/seo/optimize": {
      "post": {
        "summary": "Run SEO audit + fix suggestions on a URL (spends one page_fix credit)",
        "operationId": "seoOptimize",
        "security": [{ "bearerAuth": ["process:url"] }],
        "requestBody": { "$ref": "#/components/requestBodies/ProcessUrlRequest" },
        "responses": {
          "202": { "description": "Job queued.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/QueuedJob" } } } },
          "402": { "description": "No credits remaining.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
          "422": { "description": "Validation failed.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ValidationErrorResponse" } } } }
        }
      }
    },
    "/seo/{jobId}": {
      "get": {
        "summary": "Fetch an SEO audit/optimize job's status/result",
        "operationId": "getSeoStatus",
        "security": [{ "bearerAuth": ["process:url"] }],
        "parameters": [
          { "name": "jobId", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Job status. `data` and `completed_at` are present once `status` is `done`; `error` and `completed_at` once `status` is `failed`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "string", "enum": ["pending", "done", "failed"] },
                    "job_id": { "type": "string" },
                    "url": { "type": "string", "format": "uri" },
                    "data": { "type": ["object", "null"] },
                    "error": { "type": ["string", "null"] },
                    "completed_at": { "type": ["string", "null"], "format": "date-time" }
                  },
                  "required": ["status", "job_id", "url"]
                }
              }
            }
          },
          "404": { "description": "No job with that ID belongs to this user.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      }
    },
    "/tokens": {
      "get": {
        "summary": "List your personal access tokens",
        "operationId": "listTokens",
        "security": [{ "bearerAuth": ["tokens:manage"] }],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": { "type": "string" },
                          "name": { "type": "string" },
                          "abilities": { "type": "array", "items": { "type": "string" } },
                          "last_used_at": { "type": "null", "description": "Always null — Passport does not track last-used time." },
                          "expires_at": { "type": ["string", "null"], "format": "date-time" },
                          "created_at": { "type": "string", "format": "date-time" }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a personal access token",
        "operationId": "createToken",
        "security": [{ "bearerAuth": ["tokens:manage"] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": { "type": "string", "maxLength": 100 },
                  "abilities": {
                    "type": "array",
                    "items": { "type": "string", "enum": ["process:url", "tokens:manage", "results:read", "pages:read"] },
                    "minItems": 1,
                    "description": "A token can only grant abilities it holds itself; naming one the calling token lacks is a 422. Defaults to [\"process:url\", \"results:read\"] narrowed to the abilities the calling token holds when omitted (422 if that leaves none)."
                  }
                },
                "required": ["name"]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Token created. `token` (the bearer secret) is returned exactly once — it is not retrievable again.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "name": { "type": "string" },
                        "abilities": { "type": "array", "items": { "type": "string" } },
                        "token": { "type": "string" },
                        "expires_at": { "type": ["string", "null"], "format": "date-time" }
                      }
                    }
                  }
                }
              }
            }
          },
          "422": { "description": "Validation failed.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ValidationErrorResponse" } } } }
        }
      }
    },
    "/tokens/{tokenId}": {
      "delete": {
        "summary": "Revoke a personal access token",
        "operationId": "revokeToken",
        "security": [{ "bearerAuth": ["tokens:manage"] }],
        "parameters": [
          { "name": "tokenId", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Token revoked.", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": { "type": "string", "enum": ["revoked"] } } } } } },
          "404": { "description": "Token not found or does not belong to you.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      }
    },
    "/landing-pages": {
      "get": {
        "summary": "List your landing page generations (paginated)",
        "operationId": "listLandingPages",
        "security": [{ "bearerAuth": ["pages:read"] }],
        "responses": {
          "200": {
            "description": "Laravel's default paginator envelope (data/links/meta) wrapping LandingPageGeneration records.",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "status": { "type": "string", "enum": ["success"] }, "data": { "type": "object" } } } } }
          }
        }
      }
    },
    "/landing-pages/{landingPage}": {
      "get": {
        "summary": "Fetch one generated landing page",
        "operationId": "getLandingPage",
        "security": [{ "bearerAuth": ["pages:read"] }],
        "parameters": [
          { "name": "landingPage", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "string", "enum": ["success"] },
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "html": { "type": "string" },
                        "markdown": { "type": "string" },
                        "seo_meta": { "type": "object" },
                        "schema_json": { "type": "object" },
                        "word_count": { "type": "integer" },
                        "quality_score": { "type": ["number", "null"] },
                        "created_at": { "type": "string", "format": "date-time" },
                        "generation": { "type": "object" }
                      }
                    }
                  }
                }
              }
            }
          },
          "403": { "description": "This landing page does not belong to you." }
        }
      }
    }
  }
}
