@lap v0.3
# Machine-readable API spec. Each @endpoint block is one API call.
@api Background Removal API
@base https://api.remove.bg/v1.0
@version 1.0.0
@auth ApiKey X-API-Key in header
@endpoints 3
@toc removebg(1), improve(1), account(1)

@group removebg
@endpoint POST /removebg
@desc Remove the background of an image
@optional {image_file_b64: str # Source image file (base64-encoded string). (If this parameter is present, the other image source parameters must be empty.), image_url: str # Source image URL. (If this parameter is present, the other image source parameters must be empty.), size: str(preview/full/auto)=preview # Maximum output image resolution:  - **"preview"** (default) = Resize image to 0.25 megapixels (e.g., 625×400 pixels) – 0.25 credits per image - **"full"** = Use original image resolution, up to 25 megapixels (e.g., 6250×4000) with formats ZIP / JPG / WebP, or up to 10 megapixels (e.g., 4000×2500) with PNG – 1 credit per image - **"50MP"** = Use original image resolution, up to 50 megapixels (e.g., 8000×6250) with formats ZIP / JPG / WebP, or up to 10 megapixels (e.g., 4000×2500) with PNG – 1 credit per image - **"auto"** = Use highest available resolution, up to 25 megapixels (e.g. 6250×4000) (based on image size and available credits).  For backwards-compatibility this parameter also accepts the values "medium" (up to 1.5 megapixels) and "hd" (up to 4 megapixels) for 1 credit per image. The value "full" is also available under the name "4k" and the value "preview" is aliased as "small" and "regular"., type: str(auto/car/product/person/animal/graphic/transportation)=auto # Detect or set a foreground **type**.  We recommend using  **type = auto** to automatically detect the **type** of foreground.  To specify only one type of foreground, set **type** to one of these values: **car,  product, person, animal, graphic, transportation**., type_level: str(none/1/2/latest)=1 # Classification level of the detected foreground type:  - **"none"** = No classification (X-Type Header won't bet set on the response) - **"1"** = Use coarse classification classes: [person, product, animal, car, other] - **"2"** = Use more specific classification classes: [person, product, animal, car, car_interior, car_part, transportation, graphics, other] - **"latest"** = Always use the latest classification classes available, format: str(auto/png/jpg/zip/webp)=auto # Result image format:  - **"auto"** = Use PNG format if transparent regions exist, otherwise use JPG format (default), - **"png"** = PNG format with alpha transparency, - **"webp"** = WebP format with alpha transparency, - **"jpg"** = JPG format, no transparency, - **"zip"** = ZIP format, contains color image and alpha matte image, supports transparency (recommended for fastest processing)., roi: str=0% 0% 100% 100% # Region of interest: Only contents of this rectangular region can be detected as foreground. Everything outside is considered background and will be removed. The rectangle is defined as two x/y coordinates in the format "x1 y1 x2 y2". The coordinates can be in absolute pixels (suffix 'px') or relative to the width/height of the image (suffix '%'). By default, the whole image is the region of interest ("0% 0% 100% 100%")., crop: bool=false # Whether to crop off all empty regions (default: false). _Note_: Cropping has no effect on the amount of charged credits., crop_margin: str=0 # Adds a margin around the cropped subject (default: 0). Can be an absolute value (e.g. "30px") or relative to the subject size (e.g. "10%"). Can be a single value (all sides), two values (top/bottom and left/right) or four values (top, right, bottom, left). This parameter only has an effect when "crop=true". The maximum margin that can be added on each side is 50% of the subject dimensions or 500 pixels., scale: str=original # Scales the subject relative to the total image size. Can be any value from "10%" to "100%", or "original" (default). Scaling the subject implies "position=center" (unless specified otherwise)., position: str=original # Positions the subject within the image canvas. Can be "original" (default unless "scale" is given), "center" (default when "scale" is given) or a value from "0%" to "100%" (both horizontal and vertical) or two values (horizontal, vertical)., channels: str(rgba/alpha)=rgba # Request either the finalized image ("rgba", default) or an alpha mask ("alpha"). _Note_: Since remove.bg also applies RGB color corrections on edges, using only the alpha mask often leads to a lower final image quality. Therefore "rgba" is recommended., add_shadow: bool # Warning: **add_shadow** is deprecated and will be removed in the next major release, version 2.0. Please use **shadow_type** instead.  Setting **add_shadow = true** will set the **shadow_type** parameter to **shadow_type [car] = car**. A **car** shadow will only be generated if the foreground type is detected or specified as **car**., shadow_type: str # Generate shadows based on your foreground **type**. remove.bg supports four different shadow types: [**car, 3D, drop, none**](/help/a/enhance-your-images-with-the-ai-shadow-feature).  Use **shadow_type = auto** to automatically assign the most suitable **shadow_type** for each foreground **type**. See the default assignments below. Use **shadow_type = $shadow_type** to specify a single type of shadow for all foreground types.  Replace **shadow_type = auto** with **shadow_type [$type] = $shadow_type** to assign specific shadow types per foreground **type**. Unmentioned foreground **type(s)** will return no shadow.  Default assignments: **shadow_type [car] = car,** **shadow_type [product] = drop,** **shadow_type [person] = 3D,** **shadow_type [animal] = drop,** **shadow_type [transportation] = 3D,** **shadow_type [graphic] = drop,** **shadow_type [other] = drop**, shadow_opacity: str # Set a shadow's opacity, i.e. darkness. Can be set to any value from **0** (lightest) to **100** (darkest) or auto for default values, shown below.  **shadow_opacity = n (0 - 100), auto**  Replace **shadow_opacity = auto** with **shadow_opacity [$type] = $n** to assign specific opacity values per foreground **type**. Unmentioned foreground type(s) with set shadows will fall back on default opacity assignments.  Default values: **shadow_opacity [car] = 90** **shadow_opacity [product] = 50** **shadow_opacity [person] = 50** **shadow_opacity [animal] = 50** **shadow_opacity[transportation] = 50** **shadow_opacity [graphic] = 50** **shadow_opacity [other] = 50**, semitransparency: bool=true # Whether to have semi-transparent regions in the result (default: true). _Note_: Semitransparency is currently only supported for car windows (this might change in the future). Other objects are returned without semitransparency, even if set to true., bg_color: str # Adds a solid color background. Can be a hex color code (e.g. 81d4fa, fff) or a color name (e.g. green). For semi-transparency, 4-/8-digit hex codes are also supported (e.g. 81d4fa77). (If this parameter is present, the other bg_ parameters must be empty.), bg_image_url: str # Adds a background image from a URL. The image is centered and resized to fill the canvas while preserving the aspect ratio, unless it already has the exact same dimensions as the foreground image. (If this parameter is present, the other bg_ parameters must be empty.)}
@returns(200) {data: map{result_b64: str, foreground_top: int, foreground_left: int, foreground_width: int, foreground_height: int}} # Image background removed
@errors {400: Error: Invalid parameters or input file unprocessable (no credits charged), 402: Error: Insufficient credits (no credits charged), 403: Error: Authentication failed (no credits charged), 429: Error: Rate limit exceeded (no credits charged)}

@endgroup

@group improve
@endpoint POST /improve
@desc Submit an image to the remove.bg Improvement program
@optional {image_file_b64: str # Source image file (base64-encoded string). (If this parameter is present, the other image source parameters must be empty.), image_url: str # Source image URL. (If this parameter is present, the other image source parameters must be empty.), image_filename: str # Filename of the image, if not provided it will be autodetected form the submitted data., tag: str # Images with the same tag are grouped together.}
@returns(200) Image submitted
@errors {400: Error: Invalid parameters or input file unprocessable, 403: Error: Authentication failed, 429: Error: Rate limit exceeded}

@endgroup

@group account
@endpoint GET /account
@desc Fetch credit balance and free API calls.
@returns(200)
@errors {403: Error: Authentication failed, 429: Error: Rate limit exceeded}

@endgroup

@end
