Skip to Content
Testing AI Image Generation - Step by Step Guide

Testing AI Image Generation - Step by Step Guide

✅ Prerequisites

  1. 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
  2. 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.ts

Expected 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 chars

If 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 dev

Watch for:

[social-post-designer-worker] Worker started [social-post-designer-worker] Listening on queue: agent__social-post-designer

Step 2: Start the API Server

# In terminal 2 - Start the API cd apps/api pnpm dev

Watch for:

Server listening at http://localhost:3003

Step 3: Start the Dashboard

# In terminal 3 - Start the DM dashboard cd apps/dashboard pnpm dev

Watch for:

Local: http://localhost:3000

Step 4: Create & Approve a Post

Option A: Via Dashboard (Recommended)

  1. Open DM dashboard: http://localhost:3001 
  2. Navigate to “Social Posts” or “Content”
  3. Find a post in “DM Review” status
  4. Click “Approve” button
  5. 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 successfully

Step 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:

  1. Check Redis is running: redis-cli ping (should return PONG)
  2. Check worker is running: Look for “Worker started” log
  3. Check queue status: Use BullBoard or Redis CLI

Images not appearing in Spaces

Fix:

  1. Check DO_SPACES_* environment variables
  2. Verify bucket permissions
  3. 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

  1. Production deployment: Update production environment variables
  2. Monitor credits: Check credit consumption in billing dashboard
  3. Quality review: Review generated images for brand consistency
  4. Performance: Monitor image generation time and worker queue depth
  5. Cost tracking: Track Azure API usage and costs

© 2026 Leadmetrics — Internal use only