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

# Background Change

> [!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.

### Background Change

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

**Request Headers**

| **Parameter** | **Value** | **Description** |
| - | - | - |
| Authorization | Bearer token | Your API Key used for request authorization |

**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.

**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
\[!TIP] The first combination of parameters: use template\_url

```json theme={null}
{
    "canvas_size": "3840x3840",
    "template_url": "https://s3-alpha-sig.figma.com/img/dd86/048d/a2f66b5440ca0097162432cc5d420f31?Expires=1712534400&Key-Pair-Id=APKAQ4GOSFWCVNEHN3O4&Signature=YfFEN1MK9UZvh5CX8ne6OOPWLW4mMYU7x8jm7CyCtD5XyEmz-nsuzuLE2TdfYNXtt6vF3TLmyRbECkpAKzEnnpR8LMNgT7w2v-qn~QwnJAjAhmBhBwZ95eUEQ1IPxpX~8Gp8U3aUOYHla3mwWEULlSpFgcei6HffDZh2oIC6prKzH8rWB4JuUcpUvKw7Lq~kUfeEZ8Em-l3DvgQYzrKIuAAvoPKiYOeqIcmUs9Ba1d9wAFbjJXxHqo9xxJENMLtXIOqjGbcZLV9DWpk-fZnQAhC-ikrqoEpU~zA64aqcGYE0pv~LmV7LrCrugBcujQFBvdZqgdoV8po4HBH1Io~TkQ__",
    "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

```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

```json theme={null}
{
    "color_code": "#aafbe3",
    "canvas_size": "3840x3840",
    "template_url": "https://s3-alpha-sig.figma.com/img/dd86/048d/a2f66b5440ca0097162432cc5d420f31?Expires=1712534400&Key-Pair-Id=APKAQ4GOSFWCVNEHN3O4&Signature=YfFEN1MK9UZvh5CX8ne6OOPWLW4mMYU7x8jm7CyCtD5XyEmz-nsuzuLE2TdfYNXtt6vF3TLmyRbECkpAKzEnnpR8LMNgT7w2v-qn~QwnJAjAhmBhBwZ95eUEQ1IPxpX~8Gp8U3aUOYHla3mwWEULlSpFgcei6HffDZh2oIC6prKzH8rWB4JuUcpUvKw7Lq~kUfeEZ8Em-l3DvgQYzrKIuAAvoPKiYOeqIcmUs9Ba1d9wAFbjJXxHqo9xxJENMLtXIOqjGbcZLV9DWpk-fZnQAhC-ikrqoEpU~zA64aqcGYE0pv~LmV7LrCrugBcujQFBvdZqgdoV8po4HBH1Io~TkQ__",
    "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:

```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**

```bash cURL theme={null}
curl --location 'https://openapi.akool.com/api/open/v3/content/image/bg/replace' \
--header 'Authorization: Bearer token' \
--header 'Content-Type: application/json' \
--data '{
    "canvas_size": "3840x3840",
    "template_url": "https://s3-alpha-sig.figma.com/img/dd86/048d/a2f66b5440ca0097162432cc5d420f31?Expires=1712534400&Key-Pair-Id=APKAQ4GOSFWCVNEHN3O4&Signature=YfFEN1MK9UZvh5CX8ne6OOPWLW4mMYU7x8jm7CyCtD5XyEmz-nsuzuLE2TdfYNXtt6vF3TLmyRbECkpAKzEnnpR8LMNgT7w2v-qn~QwnJAjAhmBhBwZ95eUEQ1IPxpX~8Gp8U3aUOYHla3mwWEULlSpFgcei6HffDZh2oIC6prKzH8rWB4JuUcpUvKw7Lq~kUfeEZ8Em-l3DvgQYzrKIuAAvoPKiYOeqIcmUs9Ba1d9wAFbjJXxHqo9xxJENMLtXIOqjGbcZLV9DWpk-fZnQAhC-ikrqoEpU~zA64aqcGYE0pv~LmV7LrCrugBcujQFBvdZqgdoV8po4HBH1Io~TkQ__",
    "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://s3-alpha-sig.figma.com/img/dd86/048d/a2f66b5440ca0097162432cc5d420f31?Expires=1712534400&Key-Pair-Id=APKAQ4GOSFWCVNEHN3O4&Signature=YfFEN1MK9UZvh5CX8ne6OOPWLW4mMYU7x8jm7CyCtD5XyEmz-nsuzuLE2TdfYNXtt6vF3TLmyRbECkpAKzEnnpR8LMNgT7w2v-qn~QwnJAjAhmBhBwZ95eUEQ1IPxpX~8Gp8U3aUOYHla3mwWEULlSpFgcei6HffDZh2oIC6prKzH8rWB4JuUcpUvKw7Lq~kUfeEZ8Em-l3DvgQYzrKIuAAvoPKiYOeqIcmUs9Ba1d9wAFbjJXxHqo9xxJENMLtXIOqjGbcZLV9DWpk-fZnQAhC-ikrqoEpU~zA64aqcGYE0pv~LmV7LrCrugBcujQFBvdZqgdoV8po4HBH1Io~TkQ__\",\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("authorization", "Bearer token")
  .addHeader("content-type", "application/json")
  .build();
Response response = client.newCall(request).execute();
```

```javascript Javascript theme={null}
const myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer token");
myHeaders.append("Content-Type", "application/json");

const raw = JSON.stringify({
   "canvas_size": "3840x3840",
    "template_url": "https://s3-alpha-sig.figma.com/img/dd86/048d/a2f66b5440ca0097162432cc5d420f31?Expires=1712534400&Key-Pair-Id=APKAQ4GOSFWCVNEHN3O4&Signature=YfFEN1MK9UZvh5CX8ne6OOPWLW4mMYU7x8jm7CyCtD5XyEmz-nsuzuLE2TdfYNXtt6vF3TLmyRbECkpAKzEnnpR8LMNgT7w2v-qn~QwnJAjAhmBhBwZ95eUEQ1IPxpX~8Gp8U3aUOYHla3mwWEULlSpFgcei6HffDZh2oIC6prKzH8rWB4JuUcpUvKw7Lq~kUfeEZ8Em-l3DvgQYzrKIuAAvoPKiYOeqIcmUs9Ba1d9wAFbjJXxHqo9xxJENMLtXIOqjGbcZLV9DWpk-fZnQAhC-ikrqoEpU~zA64aqcGYE0pv~LmV7LrCrugBcujQFBvdZqgdoV8po4HBH1Io~TkQ__",
    "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 = [
  'Authorization' => 'Bearer token',
  'Content-Type' => 'application/json'
];
$body = '{
  "canvas_size": "3840x3840",
    "template_url": "https://s3-alpha-sig.figma.com/img/dd86/048d/a2f66b5440ca0097162432cc5d420f31?Expires=1712534400&Key-Pair-Id=APKAQ4GOSFWCVNEHN3O4&Signature=YfFEN1MK9UZvh5CX8ne6OOPWLW4mMYU7x8jm7CyCtD5XyEmz-nsuzuLE2TdfYNXtt6vF3TLmyRbECkpAKzEnnpR8LMNgT7w2v-qn~QwnJAjAhmBhBwZ95eUEQ1IPxpX~8Gp8U3aUOYHla3mwWEULlSpFgcei6HffDZh2oIC6prKzH8rWB4JuUcpUvKw7Lq~kUfeEZ8Em-l3DvgQYzrKIuAAvoPKiYOeqIcmUs9Ba1d9wAFbjJXxHqo9xxJENMLtXIOqjGbcZLV9DWpk-fZnQAhC-ikrqoEpU~zA64aqcGYE0pv~LmV7LrCrugBcujQFBvdZqgdoV8po4HBH1Io~TkQ__",
    "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://s3-alpha-sig.figma.com/img/dd86/048d/a2f66b5440ca0097162432cc5d420f31?Expires=1712534400&Key-Pair-Id=APKAQ4GOSFWCVNEHN3O4&Signature=YfFEN1MK9UZvh5CX8ne6OOPWLW4mMYU7x8jm7CyCtD5XyEmz-nsuzuLE2TdfYNXtt6vF3TLmyRbECkpAKzEnnpR8LMNgT7w2v-qn~QwnJAjAhmBhBwZ95eUEQ1IPxpX~8Gp8U3aUOYHla3mwWEULlSpFgcei6HffDZh2oIC6prKzH8rWB4JuUcpUvKw7Lq~kUfeEZ8Em-l3DvgQYzrKIuAAvoPKiYOeqIcmUs9Ba1d9wAFbjJXxHqo9xxJENMLtXIOqjGbcZLV9DWpk-fZnQAhC-ikrqoEpU~zA64aqcGYE0pv~LmV7LrCrugBcujQFBvdZqgdoV8po4HBH1Io~TkQ__",
    "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 = {
  'Authorization': 'Bearer token',
  'Content-Type': 'application/json'
}

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

print(response.text)
```

**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** |
| - | - | - |
| Authorization | Bearer token | Your API Key used for request authorization |

**Query Attributes**

| **Parameter** | **Type** | **Value** | **Description** |
| - | - | - | - |
| image\_model\_id | String | | image db id：You can get it based on the `_id` field returned by [https://openapi.akool.com/api/open/v3/content/image/createbyimagine](https://openapi.akool.com/api/open/v3/content/image/createbyimagine) 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**

```bash cURL theme={null}
curl --location 'https://openapi.akool.com/api/open/v3/content/image/infobymodelid?image_model_id=660d15b83ec46e810ca642f5' \
--header 'Authorization: Bearer token'
```

```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("Authorization", "Bearer token")
  .build();
Response response = client.newCall(request).execute();
```

```js Javascript  theme={null}
const myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer token");

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 = [
  'Authorization' => 'Bearer token'
];
$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 = {
  'Authorization': 'Bearer token'
}

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

print(response.text)
```

**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

| **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 |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.