{
  "openapi": "3.1.0",
  "info": {
    "title": "KertaFlow DOCX-to-PDF Conversion API",
    "version": "1.0.0",
    "description": "Fast, synchronous DOCX-to-PDF conversion API with zero default document retention, dual monthly quotas (500 conversions or 500 MB PDF output free), and per-stage timing headers."
  },
  "servers": [
    {
      "url": "https://kertaflow.com",
      "description": "Production"
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyBearer": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "kf_live_...",
        "description": "KertaFlow API key generated in the dashboard (Authorization: Bearer kf_live_...)"
      }
    },
    "schemas": {
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": { "type": "string" },
              "message": { "type": "string" }
            },
            "required": ["code", "message"]
          }
        },
        "required": ["error"]
      }
    }
  },
  "paths": {
    "/api/v1/convert": {
      "post": {
        "summary": "Convert a DOCX document to PDF",
        "description": "Streams a .docx file (max 10 MB) through memory and returns the rendered PDF bytes (max 10 MB) directly in the response body.",
        "security": [{ "ApiKeyBearer": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "Input .docx document (max 10 MB)"
                  }
                },
                "required": ["file"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Rendered PDF document",
            "headers": {
              "X-Engine-Time-Ms": { "schema": { "type": "string" }, "description": "Conversion engine time in ms" },
              "X-Queue-Wait-Ms": { "schema": { "type": "string" }, "description": "Fair queue wait time in ms" },
              "X-Total-Time-Ms": { "schema": { "type": "string" }, "description": "End-to-end duration in ms" },
              "X-Upstream-Region": { "schema": { "type": "string" }, "description": "Selected conversion region" },
              "X-Page-Count": { "schema": { "type": "integer" }, "description": "Rendered PDF page count" },
              "X-Quota-Remaining": { "schema": { "type": "integer" }, "description": "Remaining monthly conversion count" },
              "X-Bandwidth-Remaining": { "schema": { "type": "integer" }, "description": "Remaining monthly PDF output bytes" },
              "X-RateLimit-Remaining": { "schema": { "type": "integer" }, "description": "Remaining burst tokens" }
            },
            "content": {
              "application/pdf": {
                "schema": { "type": "string", "format": "binary" }
              }
            }
          },
          "400": { "description": "Invalid multipart upload or unsupported file", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
          "401": { "description": "Missing or invalid API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
          "413": { "description": "Input DOCX or generated PDF exceeds 10 MB limit (no quota deducted)", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
          "429": { "description": "Monthly conversion/bandwidth quota or rate limit exceeded", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      }
    },
    "/api/v1/me": {
      "get": {
        "summary": "Check current plan limits and remaining monthly quotas",
        "security": [{ "ApiKeyBearer": [] }],
        "responses": {
          "200": {
            "description": "Account limits and live monthly usage",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          },
          "401": { "description": "Unauthorized" }
        }
      }
    },
    "/api/v1/health": {
      "get": {
        "summary": "Service status and public free-plan limits",
        "responses": {
          "200": {
            "description": "Health and limits payload",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    }
  }
}
