This repository provides a concrete example of how to use TheDogAPI portrait-related endpoints to create a pet profile, upload source images, perform physical analyses, and generate artistic portraits.
- Python 3.x
- A valid API Key from TheDogAPI.com
- Clone this repository.
- Install dependencies:
pip install requests python-dotenv
- Create a
.envfile in thepython/directory:API_KEY=your_api_key_here API_URL=https://api.thedogapi.com/v1
cd python
python3 create-portraits.pyThe follow table summarizes the portrait-related endpoints demonstrated in this repo:
| Operation | Method | URL | Description |
|---|---|---|---|
| Create Pet | POST |
/v1/pets |
Creates a pet record and uploads multiple images in one multipart request. |
| Analyze | POST |
/v1/pets/{id}/{module} |
Runs physical analyses (e.g. estimated-age, body-condition-score). |
| Request Portrait | POST |
/v1/pets/{id}/portrait |
Triggers the generation of an artistic portrait. Supports styles like studio, pencil_sketch, professional, and oil_painting. |
| Check Status | GET |
/v1/pets/{id}/portrait/{pid} |
(Optional) Check the status of a long-running generation. |
| Get Styles | GET |
/v1/pets/portrait-styles |
Lists available artistic styles. |
| Upload Image | POST |
/v1/images/upload-sync |
Alternative way to upload a single image synchronously. |
create-portraits.py: The main script that orchestrates the entire workflow.output-data/: Contains subfolders for each pet with raw JSON analysis responses.output-portraits/: Contains subfolders for each pet with generated portrait images.../test-images/dogs/: Source directory. Each subfolder here is treated as a separate pet.
- Automatic Discovery: The script scans
../test-images/dogs/for subfolders. Each folder name is used as thepet_nameandsub_id. - Bulk Upload: For each folder, it collects all valid image files and uploads them in a single
multipart/form-datarequest when creating the pet profile. - Organized Outputs: Analysis results and portraits are saved in dedicated subfolders within
output-data/andoutput-portraits/, matching the source folder name. - Multi-Style Portraits: It generates four artistic styles (
studio,pencil_sketch,professional,oil_painting) for every discovered pet.
If you are having issues with specific endpoints, ensure your x-api-key header is correctly set and that you are using the correct PET_ID returned from the /pets endpoint.