{
  "openapi": "3.1.1",
  "info": {
    "title": "Background Remover API",
    "version": "1.0.0",
    "summary": "Remove plain backgrounds from product photos and logos (colour-based, no AI) → transparent PNG.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://backgroundremover.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Remove plain backgrounds from product photos and logos (colour-based, no AI) → transparent PNG.",
        "description": "Makes the background of an image transparent by colour: it estimates the background colour from the image border and removes it with an adjustable tolerance, or removes one colour everywhere (chroma key / green screen). Works well for product photos, logos and scans on plain backgrounds; it does NOT understand people or complex scenes, because it uses no AI model.\n\nMethodology:\n- This is NOT an AI background remover. It decides per pixel by colour distance only, so it works for a subject on a plain, evenly coloured background (product shots, logos, scans, green screen) and fails on busy scenes, hair, or subjects with the same colour as the background.\n- Automatic mode shrinks the image to 200×200 px and takes the per-channel median of a 3-pixel border ring as the background colour. The share of border pixels within the tolerance (\"border uniformity\") predicts how well the method will work.\n- Edge-connected modes add a 1-pixel frame in the background colour and flood-fill from it with ImageMagick (-fuzz, -floodfill), so only background regions touching the edge are removed and same-coloured areas inside the subject stay. Chroma-key mode removes every pixel close to the colour, wherever it is.\n- The resulting mask is cleaned with a morphological open (removes specks) and close (fills pin holes) using a disk of the chosen radius, optionally blurred to feather the edge, and used as the alpha channel of a PNG.\n- Existing transparency is flattened onto white first. Colour tolerance is a root-mean-square distance over R, G and B relative to the full 0–255 range.\n\nColour-based removal is approximate. Check the edges in the preview; for portraits or complex scenes use an AI tool or manual masking.",
        "tags": [
          "media"
        ],
        "x-mcp-tool": "background_remover",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BackgroundRemoverInput"
              },
              "examples": {
                "example1": {
                  "summary": "Red square on white (automatic)",
                  "value": {
                    "file": {
                      "filename": "product.png",
                      "contentType": "image/png",
                      "contentBase64": "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQMAAABJtOi3AAAABlBMVEX/////AADrWueTAAAAEklEQVQI12NgIBb8/09dgjgAAPcnH+GApkH4AAAAAElFTkSuQmCC"
                    },
                    "mode": "auto",
                    "fuzz": 10,
                    "cleanup": 1,
                    "feather": 0
                  }
                },
                "example2": {
                  "summary": "Chroma key: remove white everywhere",
                  "value": {
                    "file": {
                      "filename": "logo.png",
                      "contentType": "image/png",
                      "contentBase64": "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQMAAABJtOi3AAAABlBMVEX/////AADrWueTAAAAEklEQVQI12NgIBb8/09dgjgAAPcnH+GApkH4AAAAAElFTkSuQmCC"
                    },
                    "mode": "chroma",
                    "color": "#ffffff",
                    "fuzz": 5,
                    "cleanup": 0,
                    "feather": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BackgroundRemoverResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "BackgroundRemoverInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "file": {
            "title": "Image",
            "description": "JPG, PNG, WebP, AVIF, GIF, TIFF or HEIC, max 50 MB. Best results: the subject on a plain, evenly lit background. Upload as {filename, contentType?, contentBase64}. Max 51200 KiB. Accepts .jpg,.jpeg,.png,.webp,.avif,.gif,.tif,.tiff,.heic,.heif,image/jpeg,image/png,image/webp,image/avif,image/gif,image/tiff,image/heic,image/heif.",
            "type": "object",
            "additionalProperties": false,
            "required": [
              "filename",
              "contentBase64"
            ],
            "properties": {
              "filename": {
                "type": "string"
              },
              "contentType": {
                "type": "string"
              },
              "contentBase64": {
                "type": "string"
              }
            }
          },
          "mode": {
            "title": "Method",
            "type": "string",
            "enum": [
              "auto",
              "color-connected",
              "chroma"
            ],
            "default": "auto"
          },
          "color": {
            "title": "Background colour",
            "description": "Hex colour, e.g. #ffffff or #00ff00. Required for the two colour methods; ignored by the automatic method.",
            "type": "string",
            "maxLength": 7
          },
          "fuzz": {
            "title": "Colour tolerance",
            "description": "How different a pixel may be from the background colour and still be removed. Raise it for shadows or JPEG noise; lower it if parts of the subject disappear.",
            "type": "number",
            "minimum": 0,
            "maximum": 60,
            "default": 12,
            "x-unit": "%"
          },
          "cleanup": {
            "title": "Edge clean-up",
            "description": "Removes isolated specks and fills small holes in the mask (morphological open/close). 0 = off.",
            "type": "integer",
            "minimum": 0,
            "maximum": 8,
            "default": 1,
            "x-unit": "px"
          },
          "feather": {
            "title": "Feather edges",
            "description": "Softens the cut-out edge. 0 = hard edge.",
            "type": "number",
            "minimum": 0,
            "maximum": 10,
            "default": 0.5,
            "x-unit": "px"
          }
        },
        "required": [
          "file"
        ]
      },
      "BackgroundRemoverResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "mode",
              "backgroundColor",
              "fuzzPercent",
              "borderUniformityPercent",
              "suitability",
              "foregroundPercent",
              "removedPercent",
              "width",
              "height",
              "method",
              "artifact",
              "preview"
            ],
            "properties": {
              "mode": {
                "type": "string",
                "enum": [
                  "auto",
                  "color-connected",
                  "chroma"
                ]
              },
              "backgroundColor": {
                "type": "string",
                "description": "Hex colour that was removed."
              },
              "fuzzPercent": {
                "type": "number"
              },
              "borderUniformityPercent": {
                "type": "number",
                "description": "Share of border pixels within the tolerance of the background colour."
              },
              "suitability": {
                "type": "string",
                "enum": [
                  "good",
                  "fair",
                  "poor"
                ]
              },
              "foregroundPercent": {
                "type": "number"
              },
              "removedPercent": {
                "type": "number"
              },
              "width": {
                "type": "integer"
              },
              "height": {
                "type": "integer"
              },
              "method": {
                "type": "string",
                "enum": [
                  "colour-distance (non-ML)"
                ]
              },
              "artifact": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "artifactId",
                  "filename",
                  "mime",
                  "bytes",
                  "sha256",
                  "path"
                ],
                "properties": {
                  "artifactId": {
                    "type": "string"
                  },
                  "filename": {
                    "type": "string"
                  },
                  "mime": {
                    "type": "string"
                  },
                  "bytes": {
                    "type": "integer"
                  },
                  "sha256": {
                    "type": "string"
                  },
                  "path": {
                    "type": "string",
                    "description": "Download path on the same site (valid for about 2 hours)."
                  }
                }
              },
              "preview": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "artifactId",
                  "filename",
                  "mime",
                  "bytes",
                  "sha256",
                  "path"
                ],
                "properties": {
                  "artifactId": {
                    "type": "string"
                  },
                  "filename": {
                    "type": "string"
                  },
                  "mime": {
                    "type": "string"
                  },
                  "bytes": {
                    "type": "integer"
                  },
                  "sha256": {
                    "type": "string"
                  },
                  "path": {
                    "type": "string",
                    "description": "Download path on the same site (valid for about 2 hours)."
                  }
                }
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}