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

# Background Change

<Warning>This API has been deprecated and is no longer available.</Warning>

<Warning>The resources (image, video, voice) generated by our API are valid for 7 days. Please save the relevant resources as soon as possible to prevent expiration.</Warning>

### Background Change

```
POST https://openapi.akool.com/api/open/v3/content/image/bg/replace
```

**Request Headers**

| **Parameter** | **Value**        | **Description**                                                                                                                                                 |
| ------------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| x-api-key     | API Key          | Your API Key used for request authorization. If both Authorization and x-api-key have values, Authorization will be used first and x-api-key will be discarded. |
| Authorization | Bearer `{token}` | Your API Key used for request authorization.[Get Token](/authentication/usage#get-the-token)                                                                    |

**Body Attributes**

| **Parameter**             | **isRequired** | **Type** | **Value**                     | **Description**                                                             |
| ------------------------- | -------------- | -------- | ----------------------------- | --------------------------------------------------------------------------- |
| color\_code               | false          | String   | eg:  #aafbe3                  | background color。 Use hexadecimal to represent colors                       |
| template\_url             | false          | String   |                               | resource address of the background image                                    |
| origin\_img               | true           | String   |                               | Foreground image address                                                    |
| modify\_template\_size    | false          | String   | eg:"3031x3372"                | The size of the template image after expansion                              |
| modify\_origin\_img\_size | true           | String   | eg: "3031x2894"               | The size of the foreground image after scaling                              |
| overlay\_origin\_x        | true           | int      | eg: 205                       | The position of the upper left corner of the foreground image in the canvas |
| overlay\_origin\_y        | true           | int      | eg: 497                       | The position of the upper left corner of the foreground image in the canvas |
| overlay\_template\_x      | false          | int      | eg: 10                        | The position of the upper left corner of the template image in the canvas   |
| overlay\_template\_y      | false          | int      | eg: 497                       | The position of the upper left corner of the template image in the canvas   |
| canvas\_size              | true           | String   | eg:"3840x3840"                | Canvas size                                                                 |
| webhookUrl                | true           | String   |                               | Callback url address based on HTTP request                                  |
| removeBg                  | false          | Boolean  | true or false   default false | Whether to remove the background image                                      |

<Note>In addition to using the required parameters,you can also use one or both of the color\_code or template\_url parameters(but this is not required). Once you use template\_url, you can carry three additional parameters: modify\_template\_size, overlay\_template\_x, and overlay\_template\_y.</Note>

**Response Attributes**

| **Parameter** | **Type** | **Value**                      | **Description**                                                                                                    |
| ------------- | -------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------ |
| code          | int      | 1000                           | Interface returns business status code(1000:success)                                                               |
| msg           | String   |                                | Interface returns status information                                                                               |
| data          | Object   | `{ _id: "", image_status: 1 }` | \_id: Interface returns data, image\_status: the status of image: 【1:queueing, 2:processing, 3:completed,4:failed】 |

**Example**

**Body**
<Note>You have 4 combination parameters to choose from</Note>
<Tip>The first combination of parameters: use template\_url</Tip>

```json theme={null}
{
    "canvas_size": "3840x3840",
    "template_url": "https://d3c24lvfmudc1v.cloudfront.net/public/background_change/ROne.png",
    "modify_template_size": "3830x3830",
    "overlay_template_x": 5,
    "overlay_template_y": 5,
    "origin_img": "https://drz0f01yeq1cx.cloudfront.net/1711939252580-7e40bd1a-e480-42ed-8585-3f9ffccf6bdb-5822.png",
    "modify_origin_img_size": "3830x2145",
    "overlay_origin_x": 5,
    "overlay_origin_y": 849
}
```

<Tip>The second combination of parameters:use color\_code</Tip>

```json theme={null}
{
    "color_code": "#c9aafb",
    "canvas_size": "3840x3840",
    "origin_img": "https://drz0f01yeq1cx.cloudfront.net/1712132369637-69a946c0-b2a7-4fe6-92c8-2729b36cc13e-0183.png",
    "modify_origin_img_size": "3060x3824",
    "overlay_origin_x": 388,
    "overlay_origin_y": 8
}
```

<Tip>The third combination of parameters: use template\_url and color\_code </Tip>

```json theme={null}
{
    "color_code": "#aafbe3",
    "canvas_size": "3840x3840",
    "template_url": "https://d3c24lvfmudc1v.cloudfront.net/public/background_change/ROne.png",
    "modify_template_size": "3828x3828",
    "overlay_template_x": 2049,
    "overlay_template_y": -6,
    "origin_img": "https://drz0f01yeq1cx.cloudfront.net/1712132369637-69a946c0-b2a7-4fe6-92c8-2729b36cc13e-0183.png",
    "modify_origin_img_size": "3062x3828",
    "overlay_origin_x": -72,
    "overlay_origin_y": -84
}
```

<Tip>The fourth combination of parameters:</Tip>

```json theme={null}
{
    "canvas_size": "3840x3840",
    "origin_img": "https://drz0f01yeq1cx.cloudfront.net/1712132369637-69a946c0-b2a7-4fe6-92c8-2729b36cc13e-0183.png",
    "modify_origin_img_size": "3060x3824",
    "overlay_origin_x": 388,
    "overlay_origin_y": 8
}
```

**Request**

<CodeGroup>
  ```bash cURL theme={null}
  curl --location 'https://openapi.akool.com/api/open/v3/content/image/bg/replace' \
  --header "x-api-key: {{API Key}}" \
  --header 'Content-Type: application/json' \
  --data '{
      "canvas_size": "3840x3840",
      "template_url": "https://d3c24lvfmudc1v.cloudfront.net/public/background_change/ROne.png",
      "modify_template_size": "3830x3830",
      "overlay_template_x": 5,
      "overlay_template_y": 5,
      "origin_img": "https://drz0f01yeq1cx.cloudfront.net/1711939252580-7e40bd1a-e480-42ed-8585-3f9ffccf6bdb-5822.png",
      "modify_origin_img_size": "3830x2145",
      "overlay_origin_x": 5,
      "overlay_origin_y": 849
  }
  '
  ```

  ```java Java theme={null}
  OkHttpClient client = new OkHttpClient().newBuilder()
    .build();
  MediaType mediaType = MediaType.parse("application/json");
  RequestBody body = RequestBody.create(mediaType, "{\n    \"canvas_size\": \"3840x3840\",\n    \"template_url\": \"https://d3c24lvfmudc1v.cloudfront.net/public/background_change/ROne.png\",\n    \"modify_template_size\": \"3830x3830\",\n    \"overlay_template_x\": 5,\n    \"overlay_template_y\": 5,\n    \"origin_img\": \"https://drz0f01yeq1cx.cloudfront.net/1711939252580-7e40bd1a-e480-42ed-8585-3f9ffccf6bdb-5822.png\",\n    \"modify_origin_img_size\": \"3830x2145\",\n    \"overlay_origin_x\": 5,\n    \"overlay_origin_y\": 849,\n}");
  Request request = new Request.Builder()
    .url("https://contentapi.akool.com/api/v3/content/image/bg/replace")
    .method("POST", body)
    .addHeader("x-api-key", "{{API Key}}")
    .addHeader("content-type", "application/json")
    .build();
  Response response = client.newCall(request).execute();
  ```

  ```javascript Javascript theme={null}
  const myHeaders = new Headers();
  myHeaders.append("x-api-key", "{{API Key}}");
  myHeaders.append("Content-Type", "application/json");

  const raw = JSON.stringify({
     "canvas_size": "3840x3840",
      "template_url": "https://d3c24lvfmudc1v.cloudfront.net/public/background_change/ROne.png",
      "modify_template_size": "3830x3830",
      "overlay_template_x": 5,
      "overlay_template_y": 5,
      "origin_img": "https://drz0f01yeq1cx.cloudfront.net/1711939252580-7e40bd1a-e480-42ed-8585-3f9ffccf6bdb-5822.png",
      "modify_origin_img_size": "3830x2145",
      "overlay_origin_x": 5,
      "overlay_origin_y": 849
  });

  const requestOptions = {
    method: "POST",
    headers: myHeaders,
    body: raw,
    redirect: "follow"
  };

  fetch("https://openapi.akool.com/api/open/v3/content/image/bg/replace", requestOptions)
    .then((response) => response.text())
    .then((result) => console.log(result))
    .catch((error) => console.error(error));
  ```

  ```php PHP  theme={null}
  <?php
  $client = new Client();
  $headers = [
    'x-api-key' =>'{{API Key}}',
    'Content-Type' => 'application/json'
  ];
  $body = '{
    "canvas_size": "3840x3840",
      "template_url": "https://d3c24lvfmudc1v.cloudfront.net/public/background_change/ROne.png",
      "modify_template_size": "3830x3830",
      "overlay_template_x": 5,
      "overlay_template_y": 5,
      "origin_img": "https://drz0f01yeq1cx.cloudfront.net/1711939252580-7e40bd1a-e480-42ed-8585-3f9ffccf6bdb-5822.png",
      "modify_origin_img_size": "3830x2145",
      "overlay_origin_x": 5,
      "overlay_origin_y": 849
  }';
  $request = new Request('POST', 'https://openapi.akool.com/api/open/v3/content/image/bg/replace', $headers, $body);
  $res = $client->sendAsync($request)->wait();
  echo $res->getBody();
  ```

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

  url = "https://openapi.akool.com/api/open/v3/content/image/bg/replace"

  payload = json.dumps({
     "canvas_size": "3840x3840",
      "template_url": "https://d3c24lvfmudc1v.cloudfront.net/public/background_change/ROne.png",
      "modify_template_size": "3830x3830",
      "overlay_template_x": 5,
      "overlay_template_y": 5,
      "origin_img": "https://drz0f01yeq1cx.cloudfront.net/1711939252580-7e40bd1a-e480-42ed-8585-3f9ffccf6bdb-5822.png",
      "modify_origin_img_size": "3830x2145",
      "overlay_origin_x": 5,
      "overlay_origin_y": 849
  })
  headers = {
    'x-api-key':'{{API Key}}',
    'Content-Type': 'application/json'
  }

  response = requests.request("POST", url, headers=headers, data=payload)

  print(response.text)
  ```
</CodeGroup>

**Response**

```json theme={null}
{
    "code": 1000,
    "msg": "OK",
    "data": {
        "create_time": 1712133151184,
        "uid": 1432101,
        "type": 3,
        "faceswap_quality": 2,
        "image_id": "c7ed5294-6783-481e-af77-61a850cd19c7",
        "image_sub_status": 1,
        "image_status": 1,   // the status of image： 【1:queueing, 2:processing,3:completed, 4:failed】
        "deduction_credit": 4,
        "buttons": [],
        "used_buttons": [],
        "upscaled_urls": [],
        "error_reasons": [],
        "_id": "660d15b83ec46e810ca642f5",
        "__v": 0
    }
}
```

### Get  Image Result image info

```
GET https://openapi.akool.com/api/open/v3/content/image/infobymodelid?image_model_id=660d15b83ec46e810ca642f5
```

**Request Headers**

| **Parameter** | **Value**        | **Description**                                                                                                                                                 |
| ------------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| x-api-key     | API Key          | Your API Key used for request authorization. If both Authorization and x-api-key have values, Authorization will be used first and x-api-key will be discarded. |
| Authorization | Bearer `{token}` | Your API Key used for request authorization.[Get Token](/authentication/usage#get-the-token)                                                                    |

**Query Attributes**

| **Parameter**    | **Type** | **Value** | **Description**                                                                                                                                    |
| ---------------- | -------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| image\_model\_id | String   |           | image db id：You can get it based on the `_id` field returned by [Background Replace API](/ai-tools-suite/background-change#background-change) api. |

**Response Attributes**

| **Parameter** | **Type** | **Value**                          | **Description**                                                                                                                                          |
| ------------- | -------- | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| code          | int      | 1000                               | Interface returns business status code(1000:success)                                                                                                     |
| msg           | String   |                                    | Interface returns status information                                                                                                                     |
| data          | Object   | `{image_status:1,_id:"",image:""}` | image\_status:  the status of image： 【1:queueing, 2:processing, 3:completed, 4:failed】 image: Image result after processing \_id: Interface returns data |

**Example**

**Request**

<CodeGroup>
  ```bash cURL theme={null}
  curl --location 'https://openapi.akool.com/api/open/v3/content/image/infobymodelid?image_model_id=660d15b83ec46e810ca642f5' \
  --header "x-api-key: {{API Key}}"
  ```

  ```java Java theme={null}
  OkHttpClient client = new OkHttpClient().newBuilder()
    .build();
  MediaType mediaType = MediaType.parse("text/plain");
  RequestBody body = RequestBody.create(mediaType, "");
  Request request = new Request.Builder()
    .url("https://openapi.akool.com/api/open/v3/content/image/infobymodelid?image_model_id=660d15b83ec46e810ca642f5")
    .method("GET", body)
    .addHeader("x-api-key", "{{API Key}}")
    .build();
  Response response = client.newCall(request).execute();
  ```

  ```js Javascript  theme={null}
  const myHeaders = new Headers();
  myHeaders.append("x-api-key", "{{API Key}}");

  const requestOptions = {
    method: "GET",
    headers: myHeaders,
    redirect: "follow"
  };

  fetch("https://openapi.akool.com/api/open/v3/content/image/infobymodelid?image_model_id=660d15b83ec46e810ca642f5", requestOptions)
    .then((response) => response.text())
    .then((result) => console.log(result))
    .catch((error) => console.error(error));
  ```

  ```php PHP  theme={null}
  <?php
  $client = new Client();
  $headers = [
    'x-api-key' =>'{{API Key}}'
  ];
  $request = new Request('GET', 'https://openapi.akool.com/api/open/v3/content/image/infobymodelid?image_model_id=660d15b83ec46e810ca642f5', $headers);
  $res = $client->sendAsync($request)->wait();
  echo $res->getBody();
  ```

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

  url = "https://openapi.akool.com/api/open/v3/content/image/infobymodelid?image_model_id=660d15b83ec46e810ca642f5"

  payload = {}
  headers = {
    'x-api-key':'{{API Key}}'
  }

  response = requests.request("GET", url, headers=headers, data=payload)

  print(response.text)
  ```
</CodeGroup>

**Response**

```json theme={null}
{
    "code": 1000,
    "msg": "OK",
    "data": {
        "_id": "660d15b83ec46e810ca642f5",
                "create_time": 1712133560525,
                "uid": 1486241,
                "type": 3,
                "faceswap_quality": 2,
                "image_id": "e23018b5-b7a9-4981-a2ff-b20559f9b2cd",
                "image_sub_status": 3,
                "image_status": 3,  // the status of image：【1：queueing， 2：processing，3：completed，4：failed】
                "deduction_credit": 4,
                "buttons": [],
                "used_buttons": [],
                "upscaled_urls": [],
                "error_reasons": [],
                "__v": 0,
                "external_img": "https://drz0f01yeq1cx.cloudfront.net/1712133563402-result.png",
                "image": "https://drz0f01yeq1cx.cloudfront.net/1712133564746-d4a80a20-9612-4f59-958b-db9dec09b320-9409.png"  // Image result after processing  
    }
}
```

**Response Code Description**

<Note> Please note that if the value of the response code is not equal to 1000, the request is failed or wrong</Note>

| **Parameter** | **Value** | **Description**                                                       |
| ------------- | --------- | --------------------------------------------------------------------- |
| code          | 1000      | Success                                                               |
| code          | 1003      | Parameter error  or Parameter can not be empty                        |
| code          | 1005      | Operation is too frequent                                             |
| code          | 1006      | Your quota is not enough                                              |
| code          | 1007      | The number of people who can have their faces changed cannot exceed 8 |
| code          | 1101      | Invalid authorization or The request token has expired                |
| code          | 1102      | Authorization cannot be empty                                         |
| code          | 1200      | The account has been banned                                           |
