Troubleshooting
Common issues and solutions for Qwen Image Edit
Troubleshooting Guide
This guide helps you resolve common issues when using Qwen Image Edit.
Common Issues
Authentication Problems
Invalid API Key
Problem: Getting 401 Unauthorized errors
Solutions:
# Check if API key is set correctly
echo $QWEN_API_KEY
# Verify API key format
# Should be: qwen-xxxxxxxxxxxxxxxxxxxx
Rate Limiting
Problem: Getting 429 Too Many Requests errors
Solutions:
- Implement exponential backoff
- Check your rate limits in the dashboard
- Consider upgrading your plan
const retryWithBackoff = async (fn, maxRetries = 3) => {
for (let i = 0; i < maxRetries; i++) {
try {
return await fn();
} catch (error) {
if (error.status === 429 && i < maxRetries - 1) {
await new Promise(resolve => setTimeout(resolve, Math.pow(2, i) * 1000));
continue;
}
throw error;
}
}
};
Image Processing Issues
Image Upload Failures
Problem: Images fail to upload or process
Common Causes:
- File size too large (max 10MB)
- Unsupported format
- Corrupted image file
Solutions:
// Check file size
if (file.size > 10 * 1024 * 1024) {
throw new Error('File size exceeds 10MB limit');
}
// Check file format
const supportedFormats = ['image/jpeg', 'image/png', 'image/webp'];
if (!supportedFormats.includes(file.type)) {
throw new Error('Unsupported file format');
}
// Compress image if needed
const compressImage = (file, quality = 0.8) => {
return new Promise((resolve) => {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
const img = new Image();
img.onload = () => {
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
canvas.toBlob(resolve, 'image/jpeg', quality);
};
img.src = URL.createObjectURL(file);
});
};
Poor Edit Quality
Problem: Edits don't look natural or accurate
Solutions:
- Use more specific prompts
- Adjust the strength parameter
- Try different editing modes
// Better prompt examples
const goodPrompts = [
"Replace the red car with a blue sports car",
"Change the woman's dress from black to elegant white",
"Add realistic sunglasses to the person's face"
];
// Avoid vague prompts
const badPrompts = [
"Make it better",
"Change the color",
"Add something"
];
Performance Issues
Slow Processing Times
Problem: Image edits take too long to complete
Solutions:
- Reduce image resolution before processing
- Use batch processing for multiple images
- Optimize your prompts
// Resize image for faster processing
const resizeImage = (file, maxWidth = 1024) => {
return new Promise((resolve) => {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
const img = new Image();
img.onload = () => {
const ratio = Math.min(maxWidth / img.width, maxWidth / img.height);
canvas.width = img.width * ratio;
canvas.height = img.height * ratio;
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
canvas.toBlob(resolve, 'image/jpeg', 0.9);
};
img.src = URL.createObjectURL(file);
});
};
Memory Issues
Problem: Browser crashes or becomes unresponsive
Solutions:
- Process images one at a time
- Clear image data after processing
- Use Web Workers for heavy operations
// Clean up image data
const processImage = async (imageFile) => {
try {
const result = await editImage(imageFile);
return result;
} finally {
// Clean up
if (imageFile instanceof File) {
URL.revokeObjectURL(imageFile);
}
}
};
Integration Issues
CORS Errors
Problem: Cross-origin requests blocked
Solutions:
// Use proxy for client-side requests
const proxyUrl = '/api/proxy/qwen';
// Or configure CORS headers on your server
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Authorization, Content-Type');
next();
});
Webhook Failures
Problem: Webhooks not being received
Solutions:
- Verify webhook URL is accessible
- Check webhook signature validation
- Implement retry logic
// Webhook signature validation
const crypto = require('crypto');
const validateWebhook = (payload, signature, secret) => {
const expectedSignature = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(expectedSignature)
);
};
Error Codes Reference
Code | Description | Solution |
---|---|---|
400 | Bad Request | Check request parameters |
401 | Unauthorized | Verify API key |
403 | Forbidden | Check account permissions |
404 | Not Found | Verify endpoint URL |
413 | Payload Too Large | Reduce image size |
429 | Too Many Requests | Implement rate limiting |
500 | Internal Server Error | Contact support |
503 | Service Unavailable | Try again later |
Debugging Tips
Enable Debug Mode
// Enable detailed logging
const client = new QwenImageEdit({
apiKey: process.env.QWEN_API_KEY,
debug: true
});
Check Network Requests
// Log all requests
const originalFetch = fetch;
window.fetch = async (...args) => {
console.log('Request:', args);
const response = await originalFetch(...args);
console.log('Response:', response);
return response;
};
Monitor Performance
// Track processing times
const startTime = performance.now();
const result = await editImage(image, prompt);
const endTime = performance.now();
console.log(`Processing took ${endTime - startTime} milliseconds`);
Getting Help
Before Contacting Support
- Check this troubleshooting guide
- Review the API Documentation
- Check the Examples for similar use cases
- Search our community forum
When Contacting Support
Include the following information:
- Error message and code
- Request/response details
- Image specifications (size, format)
- Browser/environment details
- Steps to reproduce
Support Channels
- Email: support@qwenimageedit.com
- Discord: Join our community
- GitHub: Report issues
- Documentation: docs.qwenimageedit.com
Best Practices for Avoiding Issues
- Always validate inputs before sending requests
- Implement proper error handling in your applications
- Use appropriate image sizes for your use case
- Monitor your API usage to avoid rate limits
- Keep your API keys secure and rotate them regularly
- Test thoroughly in a development environment first
- Stay updated with the latest API changes and best practices
Last updated: January 2024