{
    "openapi": "3.0.3",
    "info": {
        "title": "Compressia API",
        "version": "1.0.0",
        "description": "Image optimization over HTTP: resize, re-encode to WebP/JPEG/PNG, strip metadata. Send JPEG, PNG, WebP or GIF; receive optimized files as base64 JSON or as a single binary. Authenticate with `Authorization: Bearer cmp_live_...`.",
        "contact": {
            "email": "info@ininia.com",
            "url": "https://ininia.com"
        }
    },
    "servers": [
        {
            "url": "https://compressia.net/api/v1"
        }
    ],
    "security": [
        {
            "bearerAuth": []
        }
    ],
    "paths": {
        "/me": {
            "get": {
                "summary": "Account, limits and this month's usage",
                "operationId": "me",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/usage": {
            "get": {
                "summary": "Monthly usage history (last 12 months)",
                "operationId": "usage",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/optimize": {
            "post": {
                "summary": "Optimize one or more images",
                "operationId": "optimize",
                "description": "Multipart (`image` / `images[]` files) or JSON (`images:[{name,data}]`, base64 or data URI). Each successfully processed image uses 1 unit of the monthly quota; failed images are not charged. `output=binary` returns the single optimized file directly (one image, one format).",
                "requestBody": {
                    "required": true,
                    "content": {
                        "multipart/form-data": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "image": {
                                        "type": "string",
                                        "format": "binary"
                                    },
                                    "images[]": {
                                        "type": "array",
                                        "items": {
                                            "type": "string",
                                            "format": "binary"
                                        }
                                    },
                                    "formats": {
                                        "type": "string",
                                        "default": "webp,jpeg",
                                        "description": "Comma list of webp, jpeg, png"
                                    },
                                    "quality": {
                                        "type": "integer",
                                        "minimum": 1,
                                        "maximum": 100,
                                        "default": 82
                                    },
                                    "preset": {
                                        "type": "string",
                                        "enum": [
                                            "quality",
                                            "smaller"
                                        ],
                                        "default": "quality"
                                    },
                                    "width": {
                                        "type": "integer",
                                        "minimum": 1,
                                        "maximum": 10000,
                                        "description": "Optional. Target width. Resizing happens BEFORE re-encoding at the requested quality. Alone: scales proportionally. Never upscales."
                                    },
                                    "height": {
                                        "type": "integer",
                                        "minimum": 1,
                                        "maximum": 10000,
                                        "description": "Optional. Target height. Alone: scales proportionally. Never upscales."
                                    },
                                    "fit": {
                                        "type": "string",
                                        "enum": [
                                            "contain",
                                            "cover",
                                            "fill"
                                        ],
                                        "default": "contain",
                                        "description": "Used only when both width and height are sent. contain: keep aspect ratio inside the box. cover: exact aspect ratio, center-cropped. fill: stretch without cropping."
                                    },
                                    "max_width": {
                                        "type": "integer",
                                        "description": "Downscale to at most this width (never upscales)"
                                    },
                                    "max_height": {
                                        "type": "integer",
                                        "description": "Downscale to at most this height (never upscales)"
                                    },
                                    "output": {
                                        "type": "string",
                                        "enum": [
                                            "json",
                                            "binary"
                                        ],
                                        "default": "json"
                                    }
                                }
                            }
                        },
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "images": {
                                        "type": "array",
                                        "items": {
                                            "type": "object",
                                            "required": [
                                                "data"
                                            ],
                                            "properties": {
                                                "name": {
                                                    "type": "string"
                                                },
                                                "data": {
                                                    "type": "string",
                                                    "description": "base64 or data URI"
                                                }
                                            }
                                        }
                                    },
                                    "formats": {
                                        "type": "string",
                                        "default": "webp,jpeg",
                                        "description": "Comma list of webp, jpeg, png"
                                    },
                                    "quality": {
                                        "type": "integer",
                                        "minimum": 1,
                                        "maximum": 100,
                                        "default": 82
                                    },
                                    "preset": {
                                        "type": "string",
                                        "enum": [
                                            "quality",
                                            "smaller"
                                        ],
                                        "default": "quality"
                                    },
                                    "width": {
                                        "type": "integer",
                                        "minimum": 1,
                                        "maximum": 10000,
                                        "description": "Optional. Target width. Resizing happens BEFORE re-encoding at the requested quality. Alone: scales proportionally. Never upscales."
                                    },
                                    "height": {
                                        "type": "integer",
                                        "minimum": 1,
                                        "maximum": 10000,
                                        "description": "Optional. Target height. Alone: scales proportionally. Never upscales."
                                    },
                                    "fit": {
                                        "type": "string",
                                        "enum": [
                                            "contain",
                                            "cover",
                                            "fill"
                                        ],
                                        "default": "contain",
                                        "description": "Used only when both width and height are sent. contain: keep aspect ratio inside the box. cover: exact aspect ratio, center-cropped. fill: stretch without cropping."
                                    },
                                    "max_width": {
                                        "type": "integer",
                                        "description": "Downscale to at most this width (never upscales)"
                                    },
                                    "max_height": {
                                        "type": "integer",
                                        "description": "Downscale to at most this height (never upscales)"
                                    },
                                    "output": {
                                        "type": "string",
                                        "enum": [
                                            "json",
                                            "binary"
                                        ],
                                        "default": "json"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "JSON result (or the binary image when output=binary)",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/OptimizeResult"
                                }
                            },
                            "image/webp": {
                                "schema": {
                                    "type": "string",
                                    "format": "binary"
                                }
                            },
                            "image/jpeg": {
                                "schema": {
                                    "type": "string",
                                    "format": "binary"
                                }
                            },
                            "image/png": {
                                "schema": {
                                    "type": "string",
                                    "format": "binary"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "415": {
                        "description": "Error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "Error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/filename": {
            "post": {
                "summary": "Suggest an SEO-friendly filename",
                "operationId": "filename",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "filename"
                                ],
                                "properties": {
                                    "filename": {
                                        "type": "string"
                                    },
                                    "alt": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "422": {
                        "description": "Error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/snippet": {
            "post": {
                "summary": "Generate an <img> HTML snippet",
                "operationId": "snippet",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "src",
                                    "alt"
                                ],
                                "properties": {
                                    "src": {
                                        "type": "string"
                                    },
                                    "alt": {
                                        "type": "string"
                                    },
                                    "width": {
                                        "type": "integer"
                                    },
                                    "height": {
                                        "type": "integer"
                                    },
                                    "lazy": {
                                        "type": "boolean",
                                        "default": true
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "422": {
                        "description": "Error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "securitySchemes": {
            "bearerAuth": {
                "type": "http",
                "scheme": "bearer",
                "description": "API key, e.g. cmp_live_xxxxxxxx. `X-API-Key` header is also accepted."
            }
        },
        "schemas": {
            "Error": {
                "type": "object",
                "properties": {
                    "success": {
                        "type": "boolean",
                        "example": false
                    },
                    "error": {
                        "type": "string",
                        "example": "monthly_quota_exceeded"
                    },
                    "message": {
                        "type": "string"
                    }
                }
            },
            "OptimizeResult": {
                "type": "object",
                "properties": {
                    "success": {
                        "type": "boolean"
                    },
                    "results": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "index": {
                                    "type": "integer"
                                },
                                "name": {
                                    "type": "string"
                                },
                                "success": {
                                    "type": "boolean"
                                },
                                "original": {
                                    "type": "object",
                                    "properties": {
                                        "format": {
                                            "type": "string"
                                        },
                                        "width": {
                                            "type": "integer"
                                        },
                                        "height": {
                                            "type": "integer"
                                        },
                                        "size": {
                                            "type": "integer"
                                        }
                                    }
                                },
                                "formats": {
                                    "type": "object",
                                    "additionalProperties": {
                                        "type": "object",
                                        "properties": {
                                            "mime": {
                                                "type": "string"
                                            },
                                            "extension": {
                                                "type": "string"
                                            },
                                            "width": {
                                                "type": "integer"
                                            },
                                            "height": {
                                                "type": "integer"
                                            },
                                            "size": {
                                                "type": "integer"
                                            },
                                            "data_base64": {
                                                "type": "string"
                                            }
                                        }
                                    }
                                },
                                "best_format": {
                                    "type": "string"
                                },
                                "savings": {
                                    "type": "object",
                                    "properties": {
                                        "bytes": {
                                            "type": "integer"
                                        },
                                        "percentage": {
                                            "type": "number"
                                        }
                                    }
                                },
                                "error": {
                                    "type": "string"
                                },
                                "message": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "summary": {
                        "type": "object"
                    },
                    "usage": {
                        "type": "object",
                        "properties": {
                            "limit": {
                                "type": "integer"
                            },
                            "used": {
                                "type": "integer"
                            },
                            "remaining": {
                                "type": "integer"
                            }
                        }
                    }
                }
            }
        }
    }
}