This guide explains how to set up Azure OpenAI with DALL-E 3 for AI-powered image generation in LearnSpeak.
LearnSpeak uses Azure OpenAI DALL-E 3 to generate educational, child-safe images for vocabulary words. This feature helps teachers quickly create visual learning materials.
- Azure Account: Active Azure subscription
- Azure OpenAI Service: Access to Azure OpenAI (requires application approval)
- DALL-E 3 Deployment: DALL-E 3 model deployed in your Azure OpenAI resource
-
Go to Azure Portal
-
Click "Create a resource"
-
Search for "Azure OpenAI"
-
Click "Create" and fill in:
- Subscription: Your Azure subscription
- Resource Group: Create new or use existing
- Region: Choose a region (e.g.,
East US,West Europe)- For Hong Kong: Use
East Asiaor nearest region
- For Hong Kong: Use
- Name: Your resource name (e.g.,
learnspeak-openai) - Pricing Tier: Standard S0
-
Click "Review + Create" → "Create"
-
Navigate to your Azure OpenAI resource
-
Click "Model deployments" in the left menu
-
Click "Create new deployment"
-
Fill in deployment details:
- Select a model: Choose
dall-e-3 - Model version: Latest available (e.g.,
3.0) - Deployment name:
dall-e-3(or your preferred name) - Content filter: Default (recommended for child-safe content)
- Select a model: Choose
-
Click "Create"
-
Wait for deployment to complete (usually 1-2 minutes)
- In your Azure OpenAI resource, go to "Keys and Endpoint"
- Copy the following:
- KEY 1 (or KEY 2)
- Endpoint (e.g.,
https://YOUR-RESOURCE.openai.azure.com/)
Add the following to your .env file in the backend directory:
# Azure OpenAI Configuration
AZURE_OPENAI_KEY=your_azure_openai_key_here
AZURE_OPENAI_ENDPOINT=https://YOUR-RESOURCE.openai.azure.com/
AZURE_OPENAI_DEPLOYMENT=dall-e-3
# Image Generation Cache (optional)
IMAGE_CACHE_ENABLED=true| Variable | Description | Example |
|---|---|---|
AZURE_OPENAI_KEY |
Your Azure OpenAI API key | abc123... |
AZURE_OPENAI_ENDPOINT |
Your Azure OpenAI endpoint URL | https://learnspeak.openai.azure.com/ |
AZURE_OPENAI_DEPLOYMENT |
Name of your DALL-E 3 deployment | dall-e-3 |
IMAGE_CACHE_ENABLED |
Enable/disable image caching | true or false |
cd backend
sh run.shCheck the logs for:
✅ Image generation service initialized
- Log in as a teacher
- Go to "Create Word" or "Bulk Word Creation"
- Enter a word (e.g., "apple")
- Click "🎨 Generate Image"
- Wait 10-30 seconds for image generation
- Image should appear automatically
- Child-Safe Prompts: All prompts are designed for children ages 4-12
- Cartoon Style: Cute, colorful illustrations suitable for learning
- Context-Aware: Uses both base word and translation for better results
- Customizable: Size, quality, and style options available
Generated images are cached locally to:
- Reduce API costs
- Speed up repeated requests
- Work offline with previously generated images
Cache location: backend/uploads/image-cache/
| Parameter | Options | Default | Description |
|---|---|---|---|
size |
1024x1024, 1792x1024, 1024x1792 |
1024x1024 |
Image dimensions |
quality |
standard, hd |
standard |
Image quality (HD costs more) |
style |
vivid, natural |
vivid |
Image style (vivid = more dramatic) |
| Quality | Size | Price per Image |
|---|---|---|
| Standard | 1024×1024 | $0.040 |
| Standard | 1024×1792, 1792×1024 | $0.080 |
| HD | 1024×1024 | $0.080 |
| HD | 1024×1792, 1792×1024 | $0.120 |
- 100 vocabulary words: $4.00 - $12.00 (depending on quality)
- 500 vocabulary words: $20.00 - $60.00
- With caching: Costs only apply to new/unique images
For educational purposes, standard quality is sufficient and costs 50% less than HD.
Keep IMAGE_CACHE_ENABLED=true to avoid regenerating identical images.
Use the "Bulk Word Creation" page to generate multiple images efficiently.
Always review AI-generated images before using them with students, as DALL-E 3 may occasionally produce unexpected results.
The system uses pre-built prompts optimized for educational content:
A cute, colorful cartoon illustration of '{word}' ({translation})
designed for children learning Cantonese. The image should be simple,
bright, cheerful, and educational. Safe for children ages 4-12.
Solution: Add AZURE_OPENAI_KEY to your .env file.
Solution:
- Check that your API key is correct
- Verify the key hasn't expired
- Ensure the endpoint URL is correct
Solution:
- Verify your deployment name matches
AZURE_OPENAI_DEPLOYMENT - Check that DALL-E 3 is deployed in your Azure OpenAI resource
Solution:
- You've hit rate limits
- Wait a few minutes and try again
- Consider upgrading your Azure OpenAI pricing tier
Causes:
- Azure region distance (use closer region)
- High Azure load (try different time)
- Network latency
Solutions:
- Use Hong Kong-friendly region (
East Asia) - Implement retry logic
- Generate images in advance during off-peak hours
- Never commit
.envfile to Git - Use Azure Key Vault for production
- Rotate keys regularly (every 90 days)
- Azure OpenAI includes built-in content filters
- All prompts are designed for child-safe content
- Teachers should review generated images
- Only teachers and admins can generate images
- Learners cannot access image generation endpoints
- Rate limiting recommended for production
POST /api/v1/images/generate
Authorization: Bearer {token}
Content-Type: application/json
{
"word": "apple",
"translation": "蘋果",
"size": "1024x1024",
"quality": "standard",
"style": "vivid"
}POST /api/v1/images/generate/batch
Authorization: Bearer {token}
Content-Type: application/json
{
"words": [
{
"word": "apple",
"translation": "蘋果"
},
{
"word": "banana",
"translation": "香蕉"
}
]
}GET /api/v1/images/cache/stats
Authorization: Bearer {token}DELETE /api/v1/images/cache
Authorization: Bearer {token}- Location: Hong Kong
- Latency: Lowest (<10ms)
- DALL-E 3: ✅ Supported
- Compliance: Hong Kong data residency
- Location: Singapore
- Latency: Low (~20-30ms)
- DALL-E 3: ✅ Supported
- Compliance: APAC data residency
- Location: Tokyo
- Latency: Medium (~40-60ms)
- DALL-E 3: ✅ Supported
- Compliance: Asia-Pacific
# Check cache size
du -sh backend/uploads/image-cache
# Count cached images
ls backend/uploads/image-cache/*.png | wc -l- Go to Azure Portal
- Navigate to your Azure OpenAI resource
- Click "Metrics" → "Total Tokens"
- View usage trends
Set up budget alerts in Azure:
- Azure Portal → Cost Management → Budgets
- Create new budget
- Set threshold (e.g., $50/month)
- Add email alerts
For issues or questions:
- Check Azure OpenAI Status
- Review Azure OpenAI Troubleshooting Guide
- Contact LearnSpeak development team
Last Updated: January 2025 Version: 1.0 Service: Azure OpenAI DALL-E 3