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

# Generate 4K or Variations

> Upscale images to 4K or generate variations from existing image generation results

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

## Endpoint

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

## 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** | **Type** | **Required** | **Description**                                                                                                                                                                                                                                                                                      |
| ------------- | -------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \_id          | String   | true         | The image `_id` you had generated, from the [Create By Source Prompt API](/ai-tools-suite/image-generate/create-by-source-prompt) response                                                                                                                                                           |
| button        | String   | true         | The type of operation to perform. Get available values from the `buttons` field in [Get Image Result API](/ai-tools-suite/image-generate/get-result) response. U1-U4: Generate a single 4K image based on the corresponding image. V1-V4: Generate a single variant based on the corresponding image |
| webhookUrl    | String   | false        | Callback URL address based on HTTP request                                                                                                                                                                                                                                                           |

## Response Attributes

| **Parameter**               | **Type** | **Description**                                         |
| --------------------------- | -------- | ------------------------------------------------------- |
| code                        | Integer  | Interface returns business status code (1000:success)   |
| msg                         | String   | Interface returns status information                    |
| data                        | Object   | Response data object                                    |
| - \_id                      | String   | Document ID for the new image                           |
| - image\_content\_model\_id | String   | The original image `_id` from the source generation     |
| - create\_time              | Long     | Creation timestamp                                      |
| - op\_button                | String   | The operation button used                               |
| - op\_buttonMessageId       | String   | Operation message ID                                    |
| - image\_status             | Integer  | Status: 1=queueing, 2=processing, 3=completed, 4=failed |
| - deduction\_credit         | Integer  | Credits deducted                                        |
| - from                      | Integer  | Source identifier                                       |
| - buttons                   | Array    | Available operation buttons                             |
| - used\_buttons             | Array    | Already used buttons                                    |
| - upscaled\_urls            | Array    | Upscaled image URLs                                     |

## Example

### Request Body

```json theme={null}
{
  "_id": "65d3206b83ccf5ab7d46cdc6",
  "button": "U2",
  "webhookUrl": ""
}
```

### Request

<CodeGroup>
  ```bash cURL theme={null}
  curl --location 'https://openapi.akool.com/api/open/v3/content/image/createbybutton' \
  --header 'x-api-key: {{API Key}}' \
  --header 'Content-Type: application/json' \
  --data '{
    "_id": "65d3206b83ccf5ab7d46cdc6",
    "button": "U2",
    "webhookUrl": ""
  }'
  ```

  ```java Java theme={null}
  OkHttpClient client = new OkHttpClient().newBuilder()
    .build();
  MediaType mediaType = MediaType.parse("application/json");
  RequestBody body = RequestBody.create(mediaType, "{\n  \"_id\": \"65d3206b83ccf5ab7d46cdc6\",\n  \"button\": \"U2\",\n  \"webhookUrl\": \"\"\n}");
  Request request = new Request.Builder()
    .url("https://openapi.akool.com/api/open/v3/content/image/createbybutton")
    .method("POST", body)
    .addHeader("x-api-key", "{{API Key}}")
    .addHeader("Content-Type", "application/json")
    .build();
  Response response = client.newCall(request).execute();
  ```

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

  const raw = JSON.stringify({
    "_id": "65d3206b83ccf5ab7d46cdc6",
    "button": "U2",
    "webhookUrl": ""
  });

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

  fetch("https://openapi.akool.com/api/open/v3/content/image/createbybutton", 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 = '{
    "_id": "65d3206b83ccf5ab7d46cdc6",
    "button": "U2",
    "webhookUrl": ""
  }';
  $request = new Request('POST', 'https://openapi.akool.com/api/open/v3/content/image/createbybutton', $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/createbybutton"

  payload = json.dumps({
    "_id": "65d3206b83ccf5ab7d46cdc6",
    "button": "U2",
    "webhookUrl": ""
  })
  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": {
    "faceswap_quality": 2,
    "deduction_credit": 2,
    "buttons": [],
    "used_buttons": [],
    "upscaled_urls": [],
    "_id": "6508292f16e5ba407d47d21b",
    "image_content_model_id": "6508288416e5ba407d47d13f",
    "create_time": 1695033647012,
    "op_button": "U2",
    "op_buttonMessageId": "kwZsk6elltno5Nt37VLj",
    "image_status": 1,
    "from": 1
  }
}
```

## Button Operations

| Button | Description                                  |
| ------ | -------------------------------------------- |
| U1     | Generate a single 4K image based on image #1 |
| U2     | Generate a single 4K image based on image #2 |
| U3     | Generate a single 4K image based on image #3 |
| U4     | Generate a single 4K image based on image #4 |
| V1     | Generate a single variant based on image #1  |
| V2     | Generate a single variant based on image #2  |
| V3     | Generate a single variant based on image #3  |
| V4     | Generate a single variant based on image #4  |

## Important Notes

* The `_id` must be from a previously generated image via the [Create By Source Prompt API](/ai-tools-suite/image-generate/create-by-source-prompt)
* Check available buttons from the `buttons` field in the [Get Image Result API](/ai-tools-suite/image-generate/get-result) response before performing an operation
* Once a button is used, it will move from `buttons` to `used_buttons` and cannot be used again
* **Resource Expiration**: Generated images are valid for 7 days, save them promptly
* **Webhook**: Use `webhookUrl` to receive notifications when image generation is complete
* Save the new `_id` from the response to check image status using the [Get Image Result](/ai-tools-suite/image-generate/get-result) API
