Overview
TheImagenClient class provides a full-featured interface to the Imagen AI API, supporting project creation, image uploads, AI-powered editing, status monitoring, and download management. It handles authentication, error management, and resource cleanup automatically.
Features
- Async context manager support for automatic session cleanup
- Concurrent uploads and downloads with configurable limits
- Progress tracking callbacks for long-running operations
- Comprehensive error handling with specific exception types
- Automatic retry and status polling for editing operations
- Support for both RAW and JPEG file formats
- MD5 hash verification for upload integrity
- Custom logging configuration
Initialization
Constructor
Your Imagen AI API key obtained from the Imagen AI platform
Base URL for the API
Optional custom logger instance for this client
Optional logging level for the logger (e.g.,
logging.INFO, logging.DEBUG)Example Usage
Class Methods
set_logger
A logging.Logger instance to use for all SDK operations
Optional logging level (e.g.,
logging.INFO, logging.DEBUG)Project Management
create_project
Optional project name. If not provided, a UUID will be generated. Must be unique across your account.
Project UUID that can be used for subsequent operations
ProjectError- If project creation fails (e.g., name already exists)AuthenticationError- If API key is invalidImagenError- For other API-related errors
Project names must be unique. If a project with the same name already exists, this method will raise a
ProjectError. Consider using timestamps or client identifiers in project names to ensure uniqueness.Image Upload
upload_images
UUID of the target project from create_project()
List of local image file paths to upload. All files must be of the same type (RAW or JPEG).
Maximum concurrent uploads. Adjust based on your internet connection speed.
Whether to calculate MD5 hashes for upload verification. Enables integrity checking but increases processing time.
Optional callback function called during upload progress. Receives
(current_index, total_files, current_file_path).Object containing upload statistics:
total: Total number of files attemptedsuccessful: Number of successfully uploaded filesfailed: Number of failed uploadsresults: List of UploadResult objects with details for each file
UploadError- If no valid files found or upload failsValueError- If max_concurrent < 1ProjectError- If project doesn’t exist or is invalidAuthenticationError- If API key is invalid
- All files in a project must be the same type (all RAW or all JPEG)
- Larger max_concurrent values may improve speed but use more bandwidth
- MD5 calculation adds processing time but ensures upload integrity
- Invalid file paths are automatically skipped and logged
AI Editing
start_editing
UUID of the project containing uploaded images
Profile ID representing your trained editing style. Obtain this from the Imagen AI app after training your profile.
Optional photography type for optimization. Options:
PORTRAITS, WEDDING, EVENTS, REAL_ESTATE, etc.Optional editing parameters:
crop: Auto-crop imagesstraighten: Auto-straighten horizonsportrait_crop: Portrait-specific croppingsmooth_skin: Skin smoothing for portraitshdr_merge: HDR bracket merging
Final status information when editing completes:
status: “Completed” or “Failed”progress: Final progress percentagedetails: Additional status information
ProjectError- If editing fails or project doesn’t existAuthenticationError- If API key is invalidImagenError- For other API-related errors
- This method blocks until editing completes (can take several minutes)
- Progress is logged automatically during the process
- Profile keys are obtained from training in the Imagen AI app
- The AI generates XMP files compatible with Lightroom/Photoshop
Download Management
get_download_links
UUID of the project with completed editing
List of temporary download URLs for XMP files. URLs are valid for a limited time.
ProjectError- If getting links fails or project doesn’t existAuthenticationError- If API key is invalidImagenError- For other API-related errors
download_files
List of download URLs from get_download_links() or get_export_links()
Directory to save downloaded files. Created if it doesn’t exist.
Maximum number of concurrent downloads
Optional callback function. Receives
(current_index, total_files, status_message).List of local file paths where files were successfully downloaded
DownloadError- If no files could be downloaded or output directory issuesValueError- If max_concurrent < 1ImagenError- For network-related download failures
Export Operations
export_project
UUID of the project with completed editing
Final status information:
status: “Completed” or “Failed”progress: Final progress percentagedetails: Additional status information
ProjectError- If export fails or project doesn’t existAuthenticationError- If API key is invalidImagenError- For other API-related errors
get_export_links
UUID of the project with completed export
List of temporary download URLs for JPEG files
ProjectError- If getting links fails or project doesn’t existAuthenticationError- If API key is invalidImagenError- For other API-related errors
Profile Management
get_profiles
List of available profiles with details:
profile_key: Unique identifier for use in editingprofile_name: Human-readable name of the profileprofile_type: Type/tier of the profileimage_type: Whether profile works with “RAW” or “JPG” files
ImagenError- If getting profiles failsAuthenticationError- If API key is invalid
- Profiles are created by training in the Imagen AI app
- Each profile works with either RAW or JPEG files, not both
- Profile keys are required for all editing operations
Resource Management
close
Context Manager
Properties
logger
The logger instance for this client