Advanced ID Photo API

Try on PicWish

Create advanced ID photos with custom dimensions, background colors, face-position constraints, beauty enhancement, outfit changes, watermarked preview, and layout output. It works for ID photo specification, background adjustment, outfit replacement, and printable layouts, with async and sync request modes.

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 an advanced ID photo task

POST /api/tasks/visual/external/idphoto

Body Parameters

image_file file optional

Image file. Supports jpg, jpeg, bmp, png, webp, tiff, bitmap. Either image_file or image_url. Priority: image_file>image_url. Image size <15MB, max resolution 4096x4096

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

image_url string optional

Image download URL. Supports HTTP and OSS protocols, max 512 characters, download timeout 10s

last_id string optional

Reuse last task input. image_id from task return (not task_id), if provided, image input can be omitted

sync integer optional

Synchronous/Asynchronous. 1=sync, 0=async

size string optional

ID photo size. Default is the original image size. Format: {width}x{height}, for example 300x400. Use a lowercase x as the separator, and each pixel value must be between 100 and 2000.

format string optional

Output format. Default is png. png returns a transparent background; jpg returns a white background.

return_type integer optional

Result return format. 1 returns an image URL; 2 returns a base64-encoded string. Default is 1.

spec_id integer optional

Specification ID. Specification includes size, background color, face size, file size

dpi integer optional

Resolution DPI. Min 10, max 1000

px_width integer optional

Pixel width. Can pass (px_width, px_height) or (mm_width, mm_height), default (295, 413), <1800 pixels

px_height integer optional

Pixel height. Used with px_width, <1800 pixels

mm_width integer optional

Millimeter width. Used with mm_height, <180mm

mm_height integer optional

Millimeter height. Used with mm_width, <180mm

change_bg integer optional

Whether to cutout and change background. 0 or 1

bg_color string optional

Background color. Hex format, common colors: white FFFFFF, red FF0000, blue 438EDB, default white

bg_color2 string optional

Gradient background color. Hex format, background gradients from top bg_color to bottom bg_color2, default empty

face_width integer optional

Face width. Face width (pixels)

min_face_width integer optional

Minimum face width. Minimum face width (pixels)

max_face_width integer optional

Maximum face width. Maximum face width (pixels)

face_height integer optional

Face height. Face height (pixels)

min_face_height integer optional

Minimum face height. Minimum face height (pixels)

max_face_height integer optional

Maximum face height. Maximum face height (pixels)

head_top integer optional

Head top distance. Distance from head top to top edge (pixels)

min_head_top integer optional

Minimum head top. Minimum distance from head top (pixels)

max_head_top integer optional

Maximum head top. Maximum distance from head top (pixels)

chin_top integer optional

Chin top distance. Distance from chin to top edge (pixels)

min_chin_top integer optional

Minimum chin top. Minimum distance from chin (pixels)

max_chin_top integer optional

Maximum chin top. Maximum distance from chin (pixels)

eyes_top integer optional

Eyes top distance. Distance from eyes to top edge (pixels)

min_eyes_top integer optional

Minimum eyes top. Minimum distance from eyes (pixels)

max_eyes_top integer optional

Maximum eyes top. Maximum distance from eyes (pixels)

auto_bright integer optional

Auto brighten. 0 or 1, whether to auto adjust brightness

bright_factor number optional

Brightness intensity. [0, 1], brightness coefficient

auto_smooth integer optional

Auto smooth skin. 0 or 1, whether to auto smooth skin

smooth_factor number optional

Smoothing intensity. [0, 1], smoothing coefficient

auto_thin_face integer optional

Auto slim face. 0 or 1, whether to auto slim face

thin_face_factor number optional

Face slimming intensity. [0, 1], face slimming coefficient

auto_sharp integer optional

Auto sharpen. 0 or 1, whether to auto sharpen

sharp_factor number optional

Sharpening intensity. [0, 1], sharpening coefficient

clothes_id string optional

Clothing template ID. man_1~man_20, woman_1~woman_20, child_1~child_10, default empty

preview integer optional

Preview only. 0 or 1, preview has watermark and does not consume credits

quality integer optional

Compression quality. [1, 100], larger value means larger file size

min_file_size integer optional

Target minimum size (Bytes). [0, inf], e.g. 10240 means min file size 10KB, only takes effect when quality is empty, default empty

max_file_size integer optional

Target maximum size (Bytes). [0, inf], only takes effect when quality is empty, default empty

add_label integer optional

Add label. 0 or 1, whether to add label at bottom

label_text string optional

Label text. Label content at bottom, default empty

label_height integer optional

Label height. Label height at bottom (pixels)

layout integer optional

Layout. 0 or 1, whether to return layout

layout_vertical integer optional

Layout direction. 0 or 1, horizontal or vertical layout, default horizontal

layout_size string optional

Paper size. "5inch" or "6inch", 5-inch or 6-inch layout

layout_bg_color string optional

Canvas background color. Hex format, e.g. white FFFFFF, default gray

layout_qr_code_data string optional

QR code data. Layout additional QR code data, default empty

layout_qr_code_size integer optional

QR code size. Layout additional QR code size in pixels

layout_label_text string optional

Canvas label text. Layout additional text, use \n for line breaks, default empty

Return Parameters

status number

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

message string

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

data.task_id string

Advanced ID photo task ID used for polling.

status number

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

message string

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

data.task_id string

Task ID. If processing fails, contact support with this task_id.

data.image_id string

The image_id returned from the task, not the task_id. Use it as last_id to reuse the image in the next request.

data.created_at integer

Task creation timestamp.

data.processed_at integer

Timestamp when task processing started.

data.completed_at integer

Task completion timestamp.

data.image string

Download URL or base64 data of the processed ID photo result. URL results are valid for 1 hour.

data.progress number

Task progress. 100 means processing is complete.

data.return_type number

Result return method.

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.state_detail string

Detailed task status.

Query advanced ID photo result

GET /api/tasks/visual/external/idphoto/{task_id}

Path Parameters

task_id string required

Task ID returned after creating an advanced ID photo 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

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

data.task_id string

Task ID. If processing fails, contact support with this task_id.

data.image_id string

The image_id returned from the task, not the task_id. Use it as last_id to reuse the image in the next request.

data.created_at integer

Task creation timestamp.

data.processed_at integer

Timestamp when task processing started.

data.completed_at integer

Task completion timestamp.

data.image string

Download URL or base64 data of the processed ID photo result. URL results are valid for 1 hour.

data.progress number

Task progress. 100 means processing is complete.

data.return_type number

Result return method.

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.state_detail string

Detailed task status.

Guidelines and Limits

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

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

  3. When passing URLs as parameters, follow URL encoding standards to prevent parameter parsing issues.

  4. Either image_file or image_url is required, and image_file has higher priority when both are sent. You can also provide last_id to reuse the previous task input and omit the image input.

  5. Standard ID photo costs 6 credits per request; outfit change with clothes_id costs 15 credits; enabling any beauty enhancement adds 8 credits; layout=1 adds 5 credits; preview=1 returns a watermarked preview and consumes no credits.

  6. Use spec_id for preset ID photo specifications, or pass px_width/px_height or mm_width/mm_height. Pixel values must be less than 1800, millimeter values less than 180, and dpi must be between 10 and 1000.

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

    FormatResolutionSize
    jpg, jpeg, bmp, png, webp, tiff, bitmapUp to 4096 x 4096Up to 15MB