Advanced Workflow Examples
This guide covers advanced techniques for power users who want to maximize their Veez.ai API usage with automation, batch processing, and optimization strategies.
Batch Product Creation
Multi-Product Pipeline
Create multiple products from a single template with different textures:
#!/bin/bash
TOKEN="your_token_here"
TEMPLATE_ID="279"
TEXTURE_DIR="./product-designs"
# Create products for all images in directory
for image in "$TEXTURE_DIR"/*.{jpg,png}; do
if [ -f "$image" ]; then
filename=$(basename "$image")
product_name="${filename%.*}"
echo "Creating product: $product_name"
response=$(curl -s -X POST https://app.veez.ai/api/product/ \
-H "Authorization: Bearer $TOKEN" \
-F "template_id=$TEMPLATE_ID" \
-F "name=$product_name" \
-F "texture[0]=@$image" \
-F "texture[0][key]=TEX01")
product_id=$(echo $response | jq -r '.id')
echo "✅ Created: $product_id"
# Start LoRA generation immediately
curl -s -X POST https://app.veez.ai/api/product/$product_id/generate-lora \
-H "Authorization: Bearer $TOKEN" > /dev/null
echo "🧠 LoRA generation started for $product_name"
# Log for later processing
echo "$product_id,$product_name,$(date)" >> products.log
# Rate limiting
sleep 10
fi
done
Multi-Template Strategy
Create products across different templates for variety:
#!/bin/bash
TOKEN="your_token_here"
# Define template-texture pairs
declare -A templates=(
["279"]="coffee-design.jpg"
["280"]="bottle-label.jpg"
["281"]="package-front.jpg"
)
for template_id in "${!templates[@]}"; do
texture_file="${templates[$template_id]}"
echo "Creating product with template $template_id"
response=$(curl -s -X POST https://app.veez.ai/api/product/ \
-H "Authorization: Bearer $TOKEN" \
-F "template_id=$template_id" \
-F "name=Product-T$template_id" \
-F "texture[0]=@$texture_file" \
-F "texture[0][key]=TEX01")
product_id=$(echo $response | jq -r '.id')
echo "Product ID: $product_id"
done
Advanced LoRA Management
LoRA Queue Monitor
Monitor multiple LoRA generations simultaneously:
#!/bin/bash
TOKEN="your_token_here"
# Read product IDs from log file
while IFS=',' read -r product_id product_name timestamp; do
echo "Checking LoRA status for: $product_name"
status=$(curl -s -H "Authorization: Bearer $TOKEN" \
https://app.veez.ai/api/product/$product_id | jq -r '.lora_enabled')
if [ "$status" = "1" ]; then
echo "✅ $product_name - LoRA ready!"
echo "$product_id,ready,$(date)" >> lora_status.log
else
echo "⏳ $product_name - Still processing..."
fi
done < products.log
echo "LoRA status check complete"
Intelligent LoRA Retry
Automatically retry failed LoRA generations:
#!/bin/bash
check_and_retry_lora() {
local product_id=$1
local max_retries=3
local retry_count=0
while [ $retry_count -lt $max_retries ]; do
echo "Attempt $((retry_count + 1)) for product: $product_id"
# Start LoRA generation
result=$(curl -s -X POST https://app.veez.ai/api/product/$product_id/generate-lora \
-H "Authorization: Bearer $TOKEN")
if echo "$result" | jq -r '.result' | grep -q "progress\|created"; then
echo "✅ LoRA generation successful"
return 0
else
echo "❌ Failed, retrying in 60 seconds..."
sleep 60
((retry_count++))
fi
done
echo "❌ Failed after $max_retries attempts"
return 1
}
# Usage
check_and_retry_lora "your_product_id"
Sophisticated Prediction Strategies
Prompt Template System
Create reusable prompt templates for consistency:
#!/bin/bash
TOKEN="your_token_here"
PRODUCT_ID="your_product_id"
# Define prompt templates
declare -A prompt_templates=(
["lifestyle"]="A {product} in a modern {room}, {lighting}, lifestyle photography"
["commercial"]="Professional {product} shot on {surface}, studio lighting, commercial photography"
["outdoor"]="A {product} in {outdoor_setting}, {time_of_day} lighting, natural environment"
["luxury"]="Premium {product} on {luxury_surface}, elegant {luxury_lighting}, high-end photography"
)
# Context variables
declare -A contexts=(
["room"]="living room,kitchen,bedroom,office"
["lighting"]="soft natural light,warm golden hour,bright daylight,dramatic lighting"
["surface"]="marble countertop,wooden table,glass surface,concrete platform"
["outdoor_setting"]="garden terrace,beach setting,mountain backdrop,urban rooftop"
["time_of_day"]="golden hour,morning,afternoon,sunset"
["luxury_surface"]="marble pedestal,velvet cushion,crystal platform,gold surface"
["luxury_lighting"]="soft studio lighting,dramatic spotlighting,ambient glow"
)
generate_prompt() {
local template_name=$1
local template="${prompt_templates[$template_name]}"
# Replace placeholders with random context
for key in "${!contexts[@]}"; do
IFS=',' read -ra options <<< "${contexts[$key]}"
random_option=${options[$RANDOM % ${#options[@]}]}
template=${template//\{$key\}/$random_option}
done
# Replace {product} with generic term
template=${template//\{product\}/premium product}
echo "$template"
}
# Generate predictions with different templates
for template_name in "${!prompt_templates[@]}"; do
prompt=$(generate_prompt "$template_name")
echo "Creating $template_name prediction: $prompt"
curl -X POST https://app.veez.ai/api/prediction/ \
-H "Authorization: Bearer $TOKEN" \
-F "product_id=$PRODUCT_ID" \
-F "prompt=$prompt" \
-F "aspect_ratio=16:9"
sleep 5
done
Aspect Ratio Optimization
Generate images optimized for different platforms:
#!/bin/bash
TOKEN="your_token_here"
PRODUCT_ID="your_product_id"
BASE_PROMPT="Premium product on marble surface, professional lighting"
# Platform-specific configurations
declare -A platforms=(
["instagram_feed"]="1:1"
["instagram_story"]="9:16"
["facebook_cover"]="16:9"
["pinterest"]="2:3"
["website_banner"]="16:9"
["mobile_app"]="4:5"
)
for platform in "${!platforms[@]}"; do
aspect_ratio="${platforms[$platform]}"
echo "Generating for $platform ($aspect_ratio)"
response=$(curl -s -X POST https://app.veez.ai/api/prediction/ \
-H "Authorization: Bearer $TOKEN" \
-F "product_id=$PRODUCT_ID" \
-F "prompt=$BASE_PROMPT, optimized for $platform" \
-F "aspect_ratio=$aspect_ratio")
prediction_id=$(echo $response | jq -r '.id')
echo "$prediction_id,$platform,$aspect_ratio,$(date)" >> predictions.log
sleep 10
done
A/B Testing Framework
Test different prompt variations systematically:
#!/bin/bash
TOKEN="your_token_here"
PRODUCT_ID="your_product_id"
# A/B test variations
declare -a lighting_vars=(
"soft natural lighting"
"dramatic studio lighting"
"warm golden hour lighting"
"bright professional lighting"
)
declare -a environment_vars=(
"modern kitchen"
"elegant dining room"
"contemporary office"
"luxury hotel lobby"
)
declare -a style_vars=(
"lifestyle photography"
"commercial product photography"
"editorial style photography"
"high-end fashion photography"
)
# Generate all combinations
for lighting in "${lighting_vars[@]}"; do
for environment in "${environment_vars[@]}"; do
for style in "${style_vars[@]}"; do
prompt="Premium product in $environment, $lighting, $style"
echo "Testing: $prompt"
response=$(curl -s -X POST https://app.veez.ai/api/prediction/ \
-H "Authorization: Bearer $TOKEN" \
-F "product_id=$PRODUCT_ID" \
-F "prompt=$prompt" \
-F "aspect_ratio=1:1")
prediction_id=$(echo $response | jq -r '.id')
# Log for analysis
echo "$prediction_id,\"$lighting\",\"$environment\",\"$style\",$(date)" >> ab_test.csv
sleep 15 # Rate limiting
done
done
done
Automated Quality Control
Image Download and Organization
Automatically download and organize generated images:
#!/bin/bash
TOKEN="your_token_here"
OUTPUT_DIR="./generated_images"
mkdir -p "$OUTPUT_DIR"
# Process predictions log
while IFS=',' read -r prediction_id platform aspect_ratio timestamp; do
echo "Processing prediction: $prediction_id"
# Wait for completion if recent
sleep 60
# Get prediction details
response=$(curl -s -H "Authorization: Bearer $TOKEN" \
https://app.veez.ai/api/prediction/$prediction_id)
images=$(echo $response | jq -r '.images[]')
if [ -n "$images" ]; then
counter=0
for image_url in $images; do
filename="${platform}_${aspect_ratio//:/x}_${prediction_id}_${counter}.png"
echo "Downloading: $filename"
curl -s -o "$OUTPUT_DIR/$filename" "$image_url"
((counter++))
done
echo "✅ Downloaded images for $prediction_id"
else
echo "⚠️ No images ready for $prediction_id"
fi
done < predictions.log
Metadata Extraction
Extract and store metadata for generated images:
#!/bin/bash
TOKEN="your_token_here"
create_metadata() {
local prediction_id=$1
response=$(curl -s -H "Authorization: Bearer $TOKEN" \
https://app.veez.ai/api/prediction/$prediction_id)
# Extract metadata
product_id=$(echo $response | jq -r '.product_id')
prompt=$(echo $response | jq -r '.prompt')
date_created=$(echo $response | jq -r '.date_modification')
image_count=$(echo $response | jq -r '.images | length')
# Create metadata file
cat > "metadata_${prediction_id}.json" << EOF
{
"prediction_id": "$prediction_id",
"product_id": "$product_id",
"prompt": "$prompt",
"date_created": "$date_created",
"image_count": $image_count,
"images": $(echo $response | jq '.images'),
"generated_at": "$(date -Iseconds)"
}
EOF
echo "📄 Metadata saved for $prediction_id"
}
# Process all predictions
for prediction_id in $(cut -d',' -f1 predictions.log); do
create_metadata "$prediction_id"
done
Performance Optimization
Parallel Processing
Process multiple operations concurrently:
#!/bin/bash
TOKEN="your_token_here"
MAX_PARALLEL=5
# Function to create product
create_product() {
local image=$1
local template_id=$2
filename=$(basename "$image")
product_name="${filename%.*}"
response=$(curl -s -X POST https://app.veez.ai/api/product/ \
-H "Authorization: Bearer $TOKEN" \
-F "template_id=$template_id" \
-F "name=$product_name" \
-F "texture[0]=@$image" \
-F "texture[0][key]=TEX01")
product_id=$(echo $response | jq -r '.id')
echo "$product_id created from $image"
}
export -f create_product
export TOKEN
# Use GNU parallel for concurrent processing
find ./images -name "*.jpg" | \
parallel -j $MAX_PARALLEL create_product {} 279
Resource Monitoring
Monitor API usage and performance:
#!/bin/bash
TOKEN="your_token_here"
# Track API calls
log_api_call() {
local endpoint=$1
local method=$2
local start_time=$3
local end_time=$4
duration=$((end_time - start_time))
echo "$(date -Iseconds),$method,$endpoint,$duration,ms" >> api_performance.csv
}
# Wrapper for API calls with monitoring
monitored_curl() {
local start_time=$(date +%s%3N)
local response=$(curl -s "$@")
local end_time=$(date +%s%3N)
# Extract endpoint from curl args
endpoint=$(echo "$@" | grep -o 'https://[^[:space:]]*' | sed 's/.*api\///')
method=$(echo "$@" | grep -o '\-X [A-Z]*' | cut -d' ' -f2)
method=${method:-GET}
log_api_call "$endpoint" "$method" "$start_time" "$end_time"
echo "$response"
}
# Usage
response=$(monitored_curl -H "Authorization: Bearer $TOKEN" \
https://app.veez.ai/api/template/)
Error Handling and Resilience
Robust Request Wrapper
Handle errors gracefully with retries:
#!/bin/bash
robust_api_call() {
local url=$1
local method=${2:-GET}
local max_retries=${3:-3}
local retry_delay=${4:-5}
local retry_count=0
while [ $retry_count -lt $max_retries ]; do
echo "Attempt $((retry_count + 1)) for $method $url"
if [ "$method" = "GET" ]; then
response=$(curl -s -w "%{http_code}" -H "Authorization: Bearer $TOKEN" "$url")
else
# Handle POST requests (add form data as needed)
response=$(curl -s -w "%{http_code}" -X "$method" -H "Authorization: Bearer $TOKEN" "$url")
fi
http_code="${response: -3}"
body="${response%???}"
case $http_code in
200|201)
echo "$body"
return 0
;;
429)
echo "Rate limited, waiting $((retry_delay * 2)) seconds..."
sleep $((retry_delay * 2))
;;
5??)
echo "Server error ($http_code), retrying in $retry_delay seconds..."
sleep $retry_delay
;;
*)
echo "Error $http_code: $body"
return 1
;;
esac
((retry_count++))
retry_delay=$((retry_delay * 2)) # Exponential backoff
done
echo "Failed after $max_retries attempts"
return 1
}
# Usage
robust_api_call "https://app.veez.ai/api/template/" "GET" 3 5
Next Steps
With these advanced techniques, you can:
- Scale your operations with batch processing
- Automate quality control with monitoring scripts
- Optimize for different platforms with smart aspect ratios
- Handle errors gracefully with robust retry logic
For production deployments, consider:
- Setting up CI/CD pipelines for automated image generation
- Implementing webhooks for real-time processing
- Creating dashboards for monitoring API usage
- Building custom applications using these patterns