{
    "openapi": "3.1.0",
    "info": {
        "title": "bgcut.net API",
        "version": "1.0.0",
        "description": "Remove image backgrounds with AI. Authenticate with an API key created at https://bgcut.net/api-keys.",
        "contact": {
            "email": "support@bgcut.net",
            "url": "https://bgcut.net/contact"
        },
        "termsOfService": "https://bgcut.net/terms"
    },
    "servers": [
        {
            "url": "https://bgcut.net/api/v1"
        }
    ],
    "components": {
        "securitySchemes": {
            "ApiKey": {
                "type": "apiKey",
                "in": "header",
                "name": "X-Api-Key"
            }
        },
        "schemas": {
            "Error": {
                "type": "object",
                "properties": {
                    "ok": {
                        "type": "boolean",
                        "const": false
                    },
                    "error": {
                        "type": "string"
                    },
                    "message": {
                        "type": "string"
                    }
                }
            },
            "Account": {
                "type": "object",
                "properties": {
                    "ok": {
                        "type": "boolean"
                    },
                    "email": {
                        "type": "string"
                    },
                    "credits": {
                        "type": "integer"
                    },
                    "free_remaining": {
                        "type": "integer"
                    },
                    "free_per_month": {
                        "type": "integer"
                    },
                    "free_max_width": {
                        "type": "integer"
                    },
                    "rate_limit_per_minute": {
                        "type": "integer"
                    }
                }
            }
        }
    },
    "security": [
        {
            "ApiKey": []
        }
    ],
    "paths": {
        "/remove": {
            "post": {
                "summary": "Remove the background of an image",
                "operationId": "removeBackground",
                "requestBody": {
                    "required": true,
                    "content": {
                        "multipart/form-data": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "image_file": {
                                        "type": "string",
                                        "format": "binary",
                                        "description": "Image file (JPG, PNG, WebP, GIF, BMP, TIFF; max 25 MB)."
                                    },
                                    "image_url": {
                                        "type": "string",
                                        "format": "uri"
                                    },
                                    "image_file_b64": {
                                        "type": "string"
                                    },
                                    "size": {
                                        "type": "string",
                                        "enum": [
                                            "auto",
                                            "preview",
                                            "full"
                                        ],
                                        "default": "auto",
                                        "description": "preview = up to 640 px (free quota), full = original resolution (1 credit), auto = full when credits are available."
                                    },
                                    "format": {
                                        "type": "string",
                                        "enum": [
                                            "png",
                                            "jpg",
                                            "webp"
                                        ],
                                        "default": "png"
                                    },
                                    "model": {
                                        "type": "string",
                                        "enum": [
                                            "fast",
                                            "lite",
                                            "hq",
                                            "portrait"
                                        ],
                                        "default": "lite",
                                        "description": "fast ≈0.5 s, lite (default) ≈6 s best balance, hq ≈15 s highest quality, portrait ≈0.3 s people only"
                                    },
                                    "bg_color": {
                                        "type": "string",
                                        "description": "Hex colour, e.g. #ffffff. Omit for transparent."
                                    },
                                    "bg_blur": {
                                        "type": "number",
                                        "description": "Keep the original background but blur it with this radius in pixels (1–200). Overrides bg_color."
                                    },
                                    "crop": {
                                        "type": "boolean",
                                        "default": false
                                    },
                                    "crop_margin": {
                                        "type": "integer",
                                        "default": 0
                                    },
                                    "roi": {
                                        "type": "string",
                                        "description": "Region of interest x,y,w,h as fractions 0..1 of the image, e.g. 0.1,0.1,0.8,0.8"
                                    },
                                    "feather": {
                                        "type": "number",
                                        "description": "Edge softening radius 0–5 px"
                                    },
                                    "quality": {
                                        "type": "integer",
                                        "default": 92
                                    },
                                    "response": {
                                        "type": "string",
                                        "enum": [
                                            "binary",
                                            "json"
                                        ],
                                        "default": "binary"
                                    }
                                }
                            }
                        },
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "image_url": {
                                        "type": "string"
                                    },
                                    "image_file_b64": {
                                        "type": "string"
                                    },
                                    "size": {
                                        "type": "string"
                                    },
                                    "format": {
                                        "type": "string"
                                    },
                                    "model": {
                                        "type": "string"
                                    },
                                    "bg_color": {
                                        "type": "string"
                                    },
                                    "crop": {
                                        "type": "boolean"
                                    },
                                    "roi": {
                                        "type": "string"
                                    },
                                    "response": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Image binary (or JSON when response=json). Headers: X-Credits-Charged, X-Credits-Remaining, X-Free-Remaining, X-Width, X-Height, X-Image-Id, X-Type.",
                        "content": {
                            "image/png": [],
                            "image/jpeg": [],
                            "image/webp": [],
                            "application/json": []
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Invalid API key"
                    },
                    "402": {
                        "description": "Insufficient credits / free quota"
                    },
                    "422": {
                        "description": "Unprocessable image"
                    },
                    "429": {
                        "description": "Rate limited"
                    }
                }
            }
        },
        "/account": {
            "get": {
                "summary": "Account balance and limits",
                "operationId": "getAccount",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Account"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/images": {
            "get": {
                "summary": "List recent images processed via the API",
                "operationId": "listImages",
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    }
}