ID Photo API

Try on PicWish

AI detects the portrait and generates an ID photo at a specified size. It can output a transparent PNG or a JPG with a white or custom solid background. It works for ID photo cropping, background adjustment, and size normalization, 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 ID photo task

POST /api/tasks/visual/idphoto

Body Parameters

image_url string optional

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

one required
image_file file optional

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

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

sync integer optional

Whether to wait for the result and return it immediately. Use 0 to return a task_id asynchronously, then fetch the result later with the task_id. Use 1 to wait and return the result synchronously. Results are kept for up to 1 hour.

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.

bg_color string optional

Solid background color, only valid when format=jpg. If omitted, JPG uses a white background. Format: RRGGBB, for example FFFFFF.

return_type integer optional

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

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. Usually success for a successful request.

data.task_id string

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. Usually success for a successful request.

data.task_id string

ID photo 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 string

The result image URL or base64 data. URL results are valid for 1 hour.

data.progress number

Task progress. 100 means processing is complete.

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.

Query ID photo result

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

Path Parameters

task_id string required

Task ID returned after creating an 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. Usually success for a successful request.

data.task_id string

ID photo 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 string

The result image URL or base64 data. URL results are valid for 1 hour.

data.progress number

Task progress. 100 means processing is complete.

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.

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 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. The ID photo size parameter uses the {width}x{height} format, and each pixel value must be between 100 and 2000.

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

    FormatResolutionSize
    jpg, jpeg, bmp, png, webp, tiff, tif, bitmap, raw, rgb, jfif, lzwUp to 4096 x 4096Up to 20MB