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

# Text to Image / Image to Image

> Generate images from text prompts or transform existing images using WaveSpeed AI models

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

## Endpoint

```
POST https://openapi.akool.com/api/open/v4/content/image/createBySourcePrompt
```

## 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](https://docs.akool.com/authentication/usage.md#get-the-token) |

## Body Attributes

| **Parameter** | **Type** | **Required** | **Description** |
| - | - | - | - |
| prompt | String | true | Text prompt describing the image to generate |
| model\_name | String | false | Model name. Options: `wavespeed-ai/flux-krea-dev-lora` (text-to-image), `wavespeed-ai/flux-kontext-dev` (image-to-image). Auto-selected based on source\_images if not provided |
| source\_images | Array | false | Array of source image URLs for image-to-image transformation. When provided, automatically uses image-to-image model |
| scale | String | false | Aspect ratio. Options: "1:1", "3:2", "4:3", "16:9", "2:3", "3:4", "9:16", "Original" (image-to-image only). Default: "1:1" |
| resolution | String | false | Output resolution. Options: "1080p", "4k". Default: "4k" |
| batch\_quantity | Integer | false | Number of images to generate (1-4). Default: 1 |
| similar | Number | false | Similarity strength for image-to-image (0-1). Default: 0.5. Only applicable for image-to-image model |
| negative\_prompt | String | false | Negative prompt to exclude certain elements from the generated image |
| webhookurl | String | false | Callback URL for receiving generation results |

## 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 (single object when batch\_quantity=1, array when batch\_quantity>1) |
| - \_id | String | Document ID |
| - uid | Integer | User ID |
| - team\_id | String | Team ID |
| - create\_time | Long | Creation timestamp |
| - prompt | String | The prompt used for generation |
| - origin\_prompt | String | Original prompt text |
| - source\_image | String | Source image URL (for image-to-image) |
| - image\_status | Integer | Status: 1=queueing, 2=processing, 3=completed, 4=failed |
| - image\_sub\_status | Integer | Sub-status for detailed tracking |
| - deduction\_credit | Integer | Credits deducted per image |
| - model\_name | String | Model used for generation |
| - provider | String | Model provider (wavespeed-ai) |
| - type | Integer | Type identifier (4 = image generation) |
| - from | Integer | Source identifier (4 = v4 API) |
| - sub\_type | Integer | Sub-type: 40001=text-to-image, 40002=image-to-image |
| - file\_name | String | Generated file name |

## Supported Models

| **Model Name** | **Type** | **Description** |
| - | - | - |
| wavespeed-ai/flux-krea-dev-lora | Text-to-Image | Akool V2 text-to-image model. Generates images from text prompts |
| wavespeed-ai/flux-kontext-dev | Image-to-Image | Akool V2 image-to-image model. Transforms existing images based on prompts |

## Example

### Text-to-Image Request

```json theme={null}
{
  "model_name": "wavespeed-ai/flux-krea-dev-lora",
  "negative_prompt": "low quality, worst quality, blurry, out of focus",
  "prompt": "A majestic mountain landscape at sunset with golden light",
  "scale": "16:9",
  "resolution": "4k",
  "batch_quantity": 1
}
```

### Image-to-Image Request

```json theme={null}
{
  "model_name": "wavespeed-ai/flux-kontext-dev",
  "negative_prompt": "low quality, worst quality, blurry, out of focus",
  "prompt": "Transform this into a watercolor painting style",
  "source_images": ["https://example.com/source-image.jpg"],
  "scale": "1:1",
  "resolution": "4k",
  "similar": 0.7,
  "batch_quantity": 1
}
```

### Request

```bash cURL theme={null}
curl --location 'https://openapi.akool.com/api/open/v4/content/image/createBySourcePrompt' \
--header 'x-api-key: {{API Key}}' \
--header 'Content-Type: application/json' \
--data '{
  "prompt": "A majestic mountain landscape at sunset with golden light",
  "scale": "16:9",
  "resolution": "4k",
  "batch_quantity": 1
}'
```

```java Java theme={null}
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n  \"prompt\": \"A majestic mountain landscape at sunset with golden light\",\n  \"scale\": \"16:9\",\n  \"resolution\": \"4k\",\n  \"batch_quantity\": 1\n}");
Request request = new Request.Builder()
  .url("https://openapi.akool.com/api/open/v4/content/image/createBySourcePrompt")
  .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({
  "prompt": "A majestic mountain landscape at sunset with golden light",
  "scale": "16:9",
  "resolution": "4k",
  "batch_quantity": 1
});

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

fetch("https://openapi.akool.com/api/open/v4/content/image/createBySourcePrompt", 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 = '{
  "prompt": "A majestic mountain landscape at sunset with golden light",
  "scale": "16:9",
  "resolution": "4k",
  "batch_quantity": 1
}';
$request = new Request('POST', 'https://openapi.akool.com/api/open/v4/content/image/createBySourcePrompt', $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/v4/content/image/createBySourcePrompt"

payload = json.dumps({
  "prompt": "A majestic mountain landscape at sunset with golden light",
  "scale": "16:9",
  "resolution": "4k",
  "batch_quantity": 1
})
headers = {
  'x-api-key':'{{API Key}}',
  '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": {
    "_id": "6650a1b2c3d4e5f6a7b8c9d0",
    "uid": 378337,
    "team_id": "team_123456",
    "create_time": 1716859314633,
    "prompt": "A majestic mountain landscape at sunset with golden light",
    "origin_prompt": "A majestic mountain landscape at sunset with golden light",
    "source_image": "",
    "image_status": 1,
    "image_sub_status": 1,
    "deduction_credit": 1,
    "model_name": "wavespeed-ai/flux-krea-dev-lora",
    "provider": "wavespeed-ai",
    "type": 4,
    "from": 4,
    "sub_type": 40001,
    "file_name": "ImageGenerator_1716859314633.png"
  }
}
```

### Batch Generation Response (batch\_quantity > 1)

```json theme={null}
{
  "code": 1000,
  "msg": "OK",
  "data": [
    {
      "_id": "6650a1b2c3d4e5f6a7b8c9d0",
      "uid": 378337,
      "team_id": "team_123456",
      "create_time": 1716859314633,
      "prompt": "A majestic mountain landscape at sunset with golden light",
      "image_status": 1,
      "deduction_credit": 1,
      "model_name": "wavespeed-ai/flux-krea-dev-lora",
      "type": 4,
      "from": 4,
      "sub_type": 40001
    },
    {
      "_id": "6650a1b2c3d4e5f6a7b8c9d1",
      "uid": 378337,
      "team_id": "team_123456",
      "create_time": 1716859314634,
      "prompt": "A majestic mountain landscape at sunset with golden light",
      "image_status": 1,
      "deduction_credit": 1,
      "model_name": "wavespeed-ai/flux-krea-dev-lora",
      "type": 4,
      "from": 4,
      "sub_type": 40001
    }
  ]
}
```

## Important Notes

* **Model Auto-Selection**: If `model_name` is not provided, the system automatically selects the appropriate model based on whether `source_images` is provided
* **Text-to-Image**: Use `wavespeed-ai/flux-krea-dev-lora` or omit `model_name` and `source_images`
* **Image-to-Image**: Use `wavespeed-ai/flux-kontext-dev` or provide `source_images` (first URL will be used as source)
* **Batch Generation**: Set `batch_quantity` (1-4) to generate multiple images in one request. Each image deducts credits separately
* **Resolution**: Default is "4k". Both "1080p" and "4k" cost 1 credit per image
* **Similar Parameter**: Only applicable for image-to-image model. Controls how closely the output matches the source image (0=more creative, 1=more similar)
* **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 `_id` from the response to check image status using the [Get Image Result](https://docs.akool.com/ai-tools-suite/image-generate/get-result.md) API

## Response Code Description

> [!NOTE]
>
> Please note that if the value of the response code is not equal to 1000, the request has failed or encountered an error.

| Code | Description |
| - | - |
| 1000 | Success |
| 1003 | Parameter error or parameter validate error |
| 1101 | Invalid authorization or the request token has expired |
| 1102 | Authorization cannot be empty |
| 1108 | Image generate error, please try again later |
| 1200 | The account has been banned |


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