Generate Background API

Try on PicWish

AI generates natural matching backgrounds from a transparent foreground PNG and a prompt or template ID. It works for product photos, marketing posters, and design assets. This endpoint currently supports asynchronous requests.

The result image URL is valid for 1 hour. Please download and store it promptly.

Authentication

Every API request must include your API Key in the X-API-KEY request header. Send it with each request exactly as shown in the examples and parameter descriptions.

X-API-KEY: YOUR_API_KEY

Create a background generation task

POST /api/tasks/visual/background

Body Parameters

image_url string optional

Source image URL. If this parameter is present, the other image source parameter must be empty.

one required
image_file file optional

Source image file as binary data. If this parameter is present, the other image source parameter must be empty.

For image upload requirements, see Guidelines and Limits #5.

batch_size integer optional

Number of images generated in each batch. Currently only 1 or 2 is supported. Default is 2.

prompt string optional

Background prompt. Multiple languages are supported, but English works best. Maximum length is 1024 characters.

one required
scene_type integer optional

Background template ID. You can fetch the latest template IDs from the scene_type API. Use either prompt or scene_type.

negative_prompt string optional

Negative prompt. Multiple languages are supported, but English works best.

Return Parameters

status number

HTTP response status code. 200 means success, and non-200 means failure. See Status Code Definitions.

message string

Response message. If the task fails, refer to this field or contact support.

data.task_id string

Background generation task ID used for polling.

Query background generation result

GET /api/tasks/visual/background/{task_id}

Path Parameters

task_id string required

Task ID returned after creating a background generation task. Use it to query the processing result.

Return Parameters

status number

HTTP response status code. 200 means success, and non-200 means failure. See Status Code Definitions.

message string

Response message. If the task fails, refer to this field or contact support.

data.task_id string

Background generation task ID. If the task fails, contact support with this task_id.

data.created_at string

Timestamp of task creation.

data.processed_at string

Timestamp when the task started to be processed.

data.completed_at string

Timestamp of task completion.

data.image_1 string

URL or Base64 data of the first generated background image.

data.image_2 string

URL or Base64 data of the second generated background image.

data.progress number

Task processing progress.

data.state number

Task status. 1 means succeeded, greater than 1 means processing, and less than 0 means failed. -7 means invalid image file. See Status Code Definitions.

data.return_type number

Result return method.

data.state_detail string

Detailed task status.

data.time_elapsed number

Processing time in milliseconds.

Guidelines and Limits

  1. The result image URL is valid for 1 hour. Please download and store it promptly.

  2. HTTP status 200 means the HTTP request succeeded, not that background generation succeeded. Check data.state for the task result. See Status Code Definitions.

  3. The input image must be a transparent PNG with only the foreground, with resolution from 256x256 to 4096x4096.

  4. The output image resolution is up to 1024x1024 and keeps the source image aspect ratio.

  5. Uploaded images must meet the following format, resolution, and file size limits.

    FormatResolutionSize
    pngUp to 4096 x 4096Up to 20MB