> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fapihub.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Background Color

Replace the background with a solid color.

```text theme={null}
https://fapihub.com/v2/rembg/color/
```

#### Result

<Columns cols={2}>
  <Column>
    <Frame>
      <img src="https://mintcdn.com/fapihub/11lDxxSYrpxAeUsM/images/image-1.png?fit=max&auto=format&n=11lDxxSYrpxAeUsM&q=85&s=e11fcf581b3b2c74239940f3d0c47077" alt="Image" width="640" height="848" data-path="images/image-1.png" />
    </Frame>
  </Column>

  <Column>
    <Frame>
      <img src="https://mintcdn.com/fapihub/ggtSdkXNyH6DjEoV/images/output3.png?fit=max&auto=format&n=ggtSdkXNyH6DjEoV&q=85&s=fb5c4ab9739367883cf473517caddd79" alt="Image" width="640" height="848" data-path="images/output3.png" />
    </Frame>
  </Column>
</Columns>

#### Headers

<ParamField header="ApiKey" type="string" required>
  Your API token.
</ParamField>

#### Body

<ParamField body="image" type="file" required>
  The image file to process. Send as multipart form data.
</ParamField>

<ParamField body="bgcolor" type="string" required>
  Background color in RGB format. Example: (255, 140, 0, 255)
</ParamField>

#### Code Samples

<CodeGroup>
  ```shellscript cURL theme={null}
  curl -X POST "https://fapihub.com/v2/rembg/color/" \
    -H "ApiKey: API_TOKEN" \
    -F "image=@image.jpg" \
    -F "bgcolor=(255, 140, 0, 255)"
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://fapihub.com/v2/rembg/color/",
      headers={"ApiKey": "your_api_token"},
      files={"image": open("image.jpg", "rb")},
      data={"bgcolor": "(255, 140, 0, 255)"}
  )

  if response.status_code == 200:
      with open("colored.png", "wb") as f:
          f.write(response.content)
  ```

  ```javascript JavaScript theme={null}
  const formData = new FormData();
  formData.append("image", fileInput.files[0]);
  formData.append("bgcolor", "(255, 140, 0, 255)");

  fetch("https://fapihub.com/v2/rembg/color/", {
    method: "POST",
    headers: { "ApiKey": "your_api_token" },
    body: formData
  })
  .then(response => response.blob())
  .then(blob => {
    const url = window.URL.createObjectURL(blob);
    const a = document.createElement("a");
    a.href = url;
    a.download = "colored.png";
    a.click();
  });
  ```

  ```php PHP theme={null}
  <?php
  $curl = curl_init();
  curl_setopt_array($curl, [
    CURLOPT_URL => "https://fapihub.com/v2/rembg/color/",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ["ApiKey: your_api_token"],
    CURLOPT_POSTFIELDS => [
      "image" => new CURLFile("image.jpg"),
      "bgcolor" => "(255, 140, 0, 255)"
    ]
  ]);
  $response = curl_exec($curl);
  file_put_contents("colored.png", $response);
  curl_close($curl);
  ?>
  ```
</CodeGroup>

#### Responses

<CodeGroup>
  ```text 200 theme={null}
  Binary image data (the processed image with background removed)
  ```

  ```json 400 theme={null}
  {
    "error": {
      "code": "invalid_image",
      "message": "The uploaded file is not a valid image format",
      "request_id": "req_abc123"
    }
  }
  ```

  ```json 401 theme={null}
  {
    "error": {
      "code": "invalid_api_key",
      "message": "The provided API key is invalid or expired",
      "request_id": "req_abc123"
    }
  }
  ```

  ```json 402 theme={null}
  {
    "error": {
      "code": "insufficient_credits",
      "message": "Your account has insufficient credits. Please upgrade your plan.",
      "request_id": "req_abc123"
    }
  }
  ```

  ```json 429 theme={null}
  {
    "error": {
      "code": "rate_limit_exceeded",
      "message": "Too many requests. Please wait before making more requests.",
      "request_id": "req_abc123",
      "retry_after": 60
    }
  }
  ```
</CodeGroup>
