{
  "openapi": "3.0.3",
  "info": {
    "title": "HD Background Removal API",
    "version": "1.0.0",
    "description": "Independent remove.bg alternative. An API-enabled plan is required. All sizes use the configured integer credit charge; failed processing is refunded."
  },
  "servers": [
    {
      "url": "/",
      "description": "Use the configured API origin, preserving /v1.0 paths."
    }
  ],
  "security": [
    {
      "ApiKey": []
    }
  ],
  "paths": {
    "/v1.0/removebg": {
      "post": {
        "operationId": "removeBackground",
        "summary": "Remove an image background, synchronously",
        "description": "Exactly one image source. JPG/PNG/WebP; maximum 22 MiB, 50 MP; dimensions 33\u20139999 px. HTTPS URL on port 443; no redirects. preview/small/regular: 0.25 MP; medium: 1.5 MP; hd: 4 MP; full/4k/auto: 25 MP; 50MP: 50 MP. PNG and auto format capped at 10 MP. No upscaling. ZIP, shadows, ROI, background images, classification and OAuth are not supported.",
        "parameters": [
          {
            "in": "header",
            "name": "Idempotency-Key",
            "schema": {
              "type": "string",
              "maxLength": 128
            },
            "description": "Optional. Same key/image/options replays success for 10 minutes without charging again. Failed or expired keys stay reserved."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "image_url": {
                    "type": "string"
                  },
                  "image_file_b64": {
                    "type": "string"
                  },
                  "bg_color": {
                    "type": "string"
                  },
                  "image_file": {
                    "type": "string",
                    "format": "binary"
                  },
                  "size": {
                    "type": "string",
                    "default": "preview",
                    "enum": [
                      "preview",
                      "small",
                      "regular",
                      "medium",
                      "hd",
                      "full",
                      "4k",
                      "auto",
                      "50MP"
                    ]
                  },
                  "format": {
                    "type": "string",
                    "default": "auto",
                    "enum": [
                      "auto",
                      "png",
                      "jpg",
                      "webp"
                    ]
                  },
                  "crop": {
                    "type": "boolean",
                    "default": false
                  },
                  "type": {
                    "type": "string",
                    "enum": [
                      "auto"
                    ]
                  },
                  "type_level": {
                    "type": "string",
                    "enum": [
                      "none"
                    ]
                  },
                  "channels": {
                    "type": "string",
                    "enum": [
                      "rgba"
                    ]
                  }
                },
                "oneOf": [
                  {
                    "required": [
                      "image_file"
                    ]
                  },
                  {
                    "required": [
                      "image_url"
                    ]
                  },
                  {
                    "required": [
                      "image_file_b64"
                    ]
                  }
                ]
              }
            },
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "image_url": {
                    "type": "string"
                  },
                  "image_file_b64": {
                    "type": "string"
                  },
                  "bg_color": {
                    "type": "string"
                  },
                  "size": {
                    "type": "string",
                    "default": "preview",
                    "enum": [
                      "preview",
                      "small",
                      "regular",
                      "medium",
                      "hd",
                      "full",
                      "4k",
                      "auto",
                      "50MP"
                    ]
                  },
                  "format": {
                    "type": "string",
                    "default": "auto",
                    "enum": [
                      "auto",
                      "png",
                      "jpg",
                      "webp"
                    ]
                  },
                  "crop": {
                    "type": "boolean",
                    "default": false
                  },
                  "type": {
                    "type": "string",
                    "enum": [
                      "auto"
                    ]
                  },
                  "type_level": {
                    "type": "string",
                    "enum": [
                      "none"
                    ]
                  },
                  "channels": {
                    "type": "string",
                    "enum": [
                      "rgba"
                    ]
                  }
                },
                "oneOf": [
                  {
                    "required": [
                      "image_url"
                    ]
                  },
                  {
                    "required": [
                      "image_file_b64"
                    ]
                  }
                ]
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "image_url": {
                    "type": "string"
                  },
                  "image_file_b64": {
                    "type": "string"
                  },
                  "bg_color": {
                    "type": "string"
                  },
                  "size": {
                    "type": "string",
                    "default": "preview",
                    "enum": [
                      "preview",
                      "small",
                      "regular",
                      "medium",
                      "hd",
                      "full",
                      "4k",
                      "auto",
                      "50MP"
                    ]
                  },
                  "format": {
                    "type": "string",
                    "default": "auto",
                    "enum": [
                      "auto",
                      "png",
                      "jpg",
                      "webp"
                    ]
                  },
                  "crop": {
                    "type": "boolean",
                    "default": false
                  },
                  "type": {
                    "type": "string",
                    "enum": [
                      "auto"
                    ]
                  },
                  "type_level": {
                    "type": "string",
                    "enum": [
                      "none"
                    ]
                  },
                  "channels": {
                    "type": "string",
                    "enum": [
                      "rgba"
                    ]
                  }
                },
                "oneOf": [
                  {
                    "required": [
                      "image_url"
                    ]
                  },
                  {
                    "required": [
                      "image_file_b64"
                    ]
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Processed image. Accept: application/json returns base64. Replays repeat the original credit header and add X-Idempotent-Replayed: true.",
            "headers": {
              "X-Width": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Height": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Credits-Charged": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Foreground-Top": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Foreground-Left": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Foreground-Width": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Foreground-Height": {
                "schema": {
                  "type": "string"
                }
              },
              "X-RateLimit-Limit": {
                "schema": {
                  "type": "string"
                }
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "string"
                }
              },
              "X-RateLimit-Reset": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Idempotent-Replayed": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "image/png": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/jpeg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/webp": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "result_width": {
                          "type": "integer"
                        },
                        "result_height": {
                          "type": "integer"
                        },
                        "credits_charged": {
                          "type": "integer"
                        },
                        "foreground_top": {
                          "type": "integer"
                        },
                        "foreground_left": {
                          "type": "integer"
                        },
                        "foreground_width": {
                          "type": "integer"
                        },
                        "foreground_height": {
                          "type": "integer"
                        },
                        "result_b64": {
                          "type": "string",
                          "format": "byte"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or unsupported parameter",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Insufficient credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid key or plan",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "408": {
            "description": "Request body timeout",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Idempotency conflict, in progress or expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Unsupported content type",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Processing failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable or busy",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "504": {
            "description": "Processing timeout",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1.0/account": {
      "get": {
        "operationId": "getAccount",
        "summary": "Available credit balance",
        "responses": {
          "200": {
            "description": "data.attributes.credits: total, subscription, payg, enterprise (0); data.attributes.api: free_calls (0), sizes (all). Non-subscription credits are grouped as payg."
          },
          "403": {
            "description": "Invalid key or plan",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable or busy",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "errors"
        ],
        "properties": {
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "title",
                "code"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "code": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  }
}
