Required variables
All environment variables must be configured in your Azure Function App’s application settings before deployment.
accountName
Your Azure Storage account name. Usage: Used to construct blob storage URLs and authenticate with Azure Storage. Example:visionaryaistorage
Where it’s used:
azure/lib/generateSASToken.js:8azure/src/functions/generateImage.js:7azure/src/functions/getImages.js:8
accountKey
Your Azure Storage account access key (key1 or key2). Usage: Provides authentication credentials for blob storage operations. Example:abc123def456... (base64-encoded key)
Where it’s used:
azure/lib/generateSASToken.js:9azure/src/functions/getImages.js:9
OPEN_AI_KEY
Your OpenAI API key with access to DALL-E 3 and GPT-3.5 models. Usage: Authenticates requests to OpenAI’s API for image generation and prompt suggestions. Example:sk-proj-... (starts with sk-)
Where it’s used:
azure/lib/openai.js:6
- Visit OpenAI Platform
- Navigate to API keys
- Click Create new secret key
- Copy and save the key securely
Ensure your OpenAI account has access to DALL-E 3. Check your usage limits and billing settings.
OPEN_AI_ORGANIZATION
Your OpenAI organization ID. Usage: Associates API requests with your OpenAI organization for billing and access control. Example:org-abc123...
Where it’s used:
azure/lib/openai.js:5
- Visit OpenAI Platform
- Navigate to Settings > Organization
- Copy your Organization ID
Configuration methods
Azure Portal
Add application settings
Click New application setting and add each variable:
| Name | Value |
|---|---|
accountName | Your storage account name |
accountKey | Your storage account key |
OPEN_AI_KEY | Your OpenAI API key |
OPEN_AI_ORGANIZATION | Your OpenAI org ID |
Azure CLI
Set all variables in a single command:Local development
For local testing, create alocal.settings.json file in the azure directory:
azure/local.settings.json
Retrieving Azure credentials
Storage account name
Storage account key
- Navigate to your Storage Account
- Select Security + networking > Access keys
- Copy Key from key1 or key2
Validation
Verify your environment variables are set correctly:Check Function App settings
Sensitive values like
accountKey are hidden in the output for security. Use the Azure Portal to verify them.Test with a function call
Test that environment variables are accessible:- Environment variables are spelled correctly
- OpenAI API key is valid and not expired
- Organization ID matches your OpenAI account
Security best practices
Use Azure Key Vault
For production deployments, store secrets in Azure Key Vault:Rotate credentials regularly
- Rotate storage account keys every 90 days
- Regenerate OpenAI API keys if compromised
- Update Key Vault secrets and app settings after rotation
Restrict access
- Use Azure RBAC to limit who can view/edit Function App settings
- Enable Azure AD authentication for Function App management
- Audit access logs in Azure Monitor
Troubleshooting
”undefined” or “null” values
Symptoms: Functions fail with errors about undefined environment variables. Causes:- Variables not set in Function App configuration
- Typos in variable names
- Function App not restarted after configuration changes
- Verify variable names match exactly (case-sensitive)
- Check values are set in Azure Portal > Configuration
- Restart the Function App
OpenAI authentication errors
Symptoms: “Invalid API key” or “Organization not found” errors. Causes:- Expired or invalid API key
- Wrong organization ID
- API key doesn’t have DALL-E 3 access
- Verify API key at OpenAI Platform
- Check organization ID matches your account
- Ensure billing is set up and DALL-E 3 is enabled
Blob storage authentication errors
Symptoms: “Authentication failed” when uploading/retrieving images. Causes:- Invalid storage account key
- Wrong storage account name
- Storage account key rotated
- Regenerate storage account key in Azure Portal
- Update
accountKeyin Function App settings - Verify
accountNamematches your storage account