{
  "openapi": "3.1.0",
  "info": {
    "title": "MiCompress API",
    "version": "1.0.0",
    "summary": "Compress images, PDFs, video, audio, Office documents and archives.",
    "description": "Upload a file to the compressor for its category, then download the smaller copy from the returned `downloadUrl` (kept for 24 hours). Anonymous use works within per-format size limits; a personal API key from https://micompress.com/account raises them. Call `GET /api/v1/capabilities` first to find the right endpoint and size limit for a file extension. Files larger than 100 MB must use the chunked upload endpoints listed in the capabilities response. AI agents can use the hosted MCP server at https://micompress.com/mcp instead (docs: https://micompress.com/mcp-server).",
    "contact": { "name": "MiCompress support", "email": "support@micompress.com", "url": "https://micompress.com/contact" },
    "termsOfService": "https://micompress.com/terms",
    "license": { "name": "Proprietary service" }
  },
  "servers": [{ "url": "https://micompress.com" }],
  "externalDocs": { "description": "MCP server and agent integration", "url": "https://micompress.com/mcp-server" },
  "security": [{}, { "apiKey": [] }],
  "tags": [
    { "name": "Discovery" },
    { "name": "Compression" }
  ],
  "paths": {
    "/api/v1/capabilities": {
      "get": {
        "tags": ["Discovery"],
        "operationId": "getCapabilities",
        "summary": "Supported formats, endpoints and size limits for the caller",
        "description": "Every `maxBytes` is already resolved for whoever is asking (anonymous, or the plan behind the API key), so a client only has to look up the file's extension in `formats`.",
        "responses": {
          "200": {
            "description": "Capabilities",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Capabilities" }
              }
            }
          },
          "401": { "$ref": "#/components/responses/InvalidApiKey" }
        }
      }
    },
    "/{category}-compressors/compress": {
      "post": {
        "tags": ["Compression"],
        "operationId": "compressFile",
        "summary": "Compress one file",
        "description": "Use the endpoint that `GET /api/v1/capabilities` gives for the file's extension (`formats[ext].endpoint`). PDFs use `/pdf-compressors/compress`. The response arrives when compression is done; large videos can take minutes. Send a `jobId` to read the result back from `GET /api/v1/jobs/{jobId}` if the connection drops.",
        "parameters": [
          {
            "name": "category",
            "in": "path",
            "required": true,
            "schema": { "type": "string", "enum": ["image", "video", "audio", "document", "pdf", "archive"] }
          },
          {
            "name": "X-MiCompress-Client",
            "in": "header",
            "required": false,
            "description": "Optional `name/version` of the integration calling the API, for attribution.",
            "schema": { "type": "string", "example": "my-app/1.0.0" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": ["file"],
                "properties": {
                  "file": { "type": "string", "format": "binary", "description": "The file, with a filename whose extension matches its format." },
                  "preset": { "type": "string", "enum": ["lossless", "recommended", "extreme"], "default": "recommended" },
                  "maxWidth": { "type": "integer", "minimum": 1, "description": "Images only: resize down to this width in pixels." },
                  "jobId": { "type": "string", "pattern": "^[a-f0-9]{32,64}$", "description": "Client-generated random hex id for reading the result back later." }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Compressed",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/CompressResult" } }
            }
          },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/InvalidApiKey" },
          "413": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/Error" },
          "503": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/api/v1/jobs/{jobId}": {
      "get": {
        "tags": ["Compression"],
        "operationId": "getJob",
        "summary": "Read back the result of a compression sent with a jobId",
        "description": "Records are kept for 2 hours. Knowing the id is the authorization.",
        "parameters": [
          { "name": "jobId", "in": "path", "required": true, "schema": { "type": "string", "pattern": "^[a-f0-9]{32,64}$" } }
        ],
        "responses": {
          "200": {
            "description": "Job status",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Job" } } }
          },
          "404": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/downloads/{filename}": {
      "get": {
        "tags": ["Compression"],
        "operationId": "downloadResult",
        "summary": "Download a compressed file",
        "description": "The path comes from `downloadUrl` in the compress response. Files are deleted after 24 hours.",
        "security": [{}],
        "parameters": [
          { "name": "filename", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "The compressed file", "content": { "application/octet-stream": { "schema": { "type": "string", "format": "binary" } } } },
          "404": { "description": "Not found or expired" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Optional personal key (`mc_…`) from https://micompress.com/account. `Authorization: Bearer mc_…` also works."
      }
    },
    "responses": {
      "Error": {
        "description": "Error",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "InvalidApiKey": {
        "description": "The API key is not valid",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": { "type": "string", "description": "Human-readable explanation." },
          "code": {
            "type": "string",
            "description": "Machine-readable code when one applies.",
            "examples": ["LOGIN_REQUIRED", "INVALID_API_KEY", "API_QUOTA_REACHED", "USAGE_LIMIT_REACHED", "SERVER_BUSY", "UNSUPPORTED_FORMAT"]
          },
          "retryAfter": { "type": "integer", "description": "Seconds to wait, on 503." }
        }
      },
      "CompressResult": {
        "type": "object",
        "required": ["success", "downloadUrl", "inputSize", "outputSize"],
        "properties": {
          "success": { "type": "boolean", "const": true },
          "downloadUrl": { "type": "string", "description": "Path relative to https://micompress.com, e.g. /downloads/compressed-….jpg" },
          "inputSize": { "type": "integer" },
          "outputSize": { "type": "integer" },
          "savedBytes": { "type": "integer" },
          "savedPercent": { "type": "number" },
          "format": { "type": ["string", "null"] },
          "originalName": { "type": "string" },
          "note": { "type": ["string", "null"] },
          "alternative": {
            "type": ["object", "null"],
            "description": "A second, smaller variant when one exists (for example a ZIP of a text file).",
            "properties": { "downloadUrl": { "type": "string" } }
          }
        }
      },
      "Job": {
        "type": "object",
        "required": ["status"],
        "properties": {
          "status": { "type": "string", "enum": ["processing", "done", "failed", "unknown"] },
          "filename": { "type": ["string", "null"] },
          "downloadUrl": { "type": "string", "description": "Absolute URL when status is done." },
          "inputSize": { "type": "integer" },
          "outputSize": { "type": "integer" },
          "savedPercent": { "type": "number" },
          "error": { "type": "string" },
          "retryAfterMs": { "type": "integer" }
        }
      },
      "Capabilities": {
        "type": "object",
        "properties": {
          "version": { "type": "integer" },
          "presets": { "type": "array", "items": { "type": "string" } },
          "you": { "type": "object", "description": "Who the caller is: authenticated, plan, maxUploadBytes, quotas." },
          "transport": { "type": "object", "description": "maxDirectBytes (100 MB), chunk sizes and request timeout." },
          "endpoints": { "type": "object", "description": "Paths for compress, precheck and chunked upload." },
          "formats": {
            "type": "object",
            "description": "Keyed by file extension.",
            "additionalProperties": {
              "type": "object",
              "properties": {
                "group": { "type": "string" },
                "limitGroup": { "type": "string" },
                "endpoint": { "type": "string" },
                "maxBytes": { "type": "integer" }
              }
            }
          }
        }
      }
    }
  }
}
