Testing AI Image Generation - Step by Step Guide
✅ Prerequisites
-
Environment variables set (already done):
AZURE_IMAGE_API_KEY=DzQKmjEA8WofYwOxbLaPVmek5PWqMt3XeBUuDNm5BGVybFJwscQSJQQJ99CCACF24PCXJ3w3AAAAACOG1Joz AZURE_IMAGE_ENDPOINT=https://getmo-mn31nkpp-uaenorth.cognitiveservices.azure.com/openai/deployments/gpt-image-1.5/images/generations?api-version=2024-02-01 -
Services running:
- PostgreSQL (port 5434)
- Redis (port 6379)
- DigitalOcean Spaces configured
🧪 Test Method 1: Quick Provider Test (2 minutes)
Test just the Azure connection and image generation:
# Run the test script
pnpm tsx scripts/test-image-generation.tsExpected output:
🧪 Testing Azure GPT Image 1.5 Image Generation
📡 Step 1: Testing Azure provider connection...
✅ Provider initialized successfully
🎨 Step 2: Generating test image...
✅ Image generated successfully!
Created at: 2026-04-24T...
Image count: 1
Has base64 data: true
Base64 length: ~150000 charsIf this works, Azure GPT Image 1.5 is connected correctly! ✅
🔄 Test Method 2: End-to-End Flow (10 minutes)
Test the complete workflow from post creation to image generation:
Step 1: Start the Worker
# In terminal 1 - Start the agents worker
cd packages/agents
pnpm devWatch for:
[social-post-designer-worker] Worker started
[social-post-designer-worker] Listening on queue: agent__social-post-designerStep 2: Start the API Server
# In terminal 2 - Start the API
cd apps/api
pnpm devWatch for:
Server listening at http://localhost:3003Step 3: Start the Dashboard
# In terminal 3 - Start the DM dashboard
cd apps/dashboard
pnpm devWatch for:
Local: http://localhost:3000Step 4: Create & Approve a Post
Option A: Via Dashboard (Recommended)
- Open DM dashboard: http://localhost:3001
- Navigate to “Social Posts” or “Content”
- Find a post in “DM Review” status
- Click “Approve” button
- Watch terminal 1 (worker logs) for image generation
Option B: Via API (curl)
# Get a post in dm_review status
curl http://localhost:3003/dm/v1/social \
-H "Authorization: Bearer YOUR_DM_TOKEN"
# Approve the post (replace POST_ID)
curl -X POST http://localhost:3003/dm/v1/social/POST_ID/dm-approve \
-H "Authorization: Bearer YOUR_DM_TOKEN" \
-H "Content-Type: application/json"Step 5: Watch the Worker Logs
In terminal 1, you should see:
[social-post-designer-worker] Job started: {...}
[social-post-designer-worker] Generating 1 images for social post...
[social-post-designer-worker] Reserved 2 credits for image generation
[social-post-designer-worker] Generating image 1/1...
[social-post-designer-worker] Image generated successfully
[social-post-designer-worker] Overlaying logo...
[social-post-designer-worker] Uploading to Spaces...
[social-post-designer-worker] Media record created: media-xxx
[social-post-designer-worker] Consumed 2 credits
[social-post-designer-worker] Post status updated to: client_review
[social-post-designer-worker] Job completed successfullyStep 6: Verify Images Created
Check in database:
# Run this in a terminal
pnpm tsx -e "
import { db } from '@leadmetrics/db';
const media = await db.media.findMany({
where: { socialPostId: 'YOUR_POST_ID' },
orderBy: { createdAt: 'desc' },
take: 5
});
console.log(media);
"Check in DigitalOcean Spaces:
- Navigate to your DO Spaces bucket
- Look for files under
social-posters/folder - Images should be PNG files with tenant/post IDs in the path
Check in Dashboard:
- Refresh the post detail page
- Post status should now be “Client Review”
- Images should be visible in the preview
🎯 Test Method 3: Direct Worker Trigger (Advanced)
Manually trigger the worker for a specific post:
// test-trigger-worker.ts
import { enqueueSocialPostDesigner } from "@leadmetrics/queue";
await enqueueSocialPostDesigner({
activityId: "your-activity-id",
tenantId: "your-tenant-id",
wakeReason: "new_task",
});
console.log("✅ Worker job enqueued");Run:
pnpm tsx test-trigger-worker.ts🐛 Troubleshooting
Error: “Neither Azure nor OpenAI credentials configured”
Fix: Check environment variables are loaded:
node -e "console.log(process.env.AZURE_IMAGE_API_KEY?.substring(0, 10))"Should output: DzQKmjEA8W
If not, restart your terminal or source the .env file.
Error: “Azure OpenAI image generation failed: 401”
Fix: API key is invalid or expired. Verify in Azure portal.
Error: “Azure OpenAI image generation failed: 429”
Fix: Rate limit reached. Wait a few minutes and retry.
Worker doesn’t process job
Fix:
- Check Redis is running:
redis-cli ping(should returnPONG) - Check worker is running: Look for “Worker started” log
- Check queue status: Use BullBoard or Redis CLI
Images not appearing in Spaces
Fix:
- Check DO_SPACES_* environment variables
- Verify bucket permissions
- Check worker logs for upload errors
📊 Success Criteria
✅ Test script runs without errors
✅ Provider generates test image successfully
✅ Worker processes approval and generates images
✅ Images uploaded to DigitalOcean Spaces
✅ Media records created in database
✅ Post status advances to “client_review”
✅ Credits consumed and logged
📝 Next Steps After Testing
- Production deployment: Update production environment variables
- Monitor credits: Check credit consumption in billing dashboard
- Quality review: Review generated images for brand consistency
- Performance: Monitor image generation time and worker queue depth
- Cost tracking: Track Azure API usage and costs