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

CodeDescriptionSolution
400Bad RequestCheck request parameters
401UnauthorizedVerify API key
403ForbiddenCheck account permissions
404Not FoundVerify endpoint URL
413Payload Too LargeReduce image size
429Too Many RequestsImplement rate limiting
500Internal Server ErrorContact support
503Service UnavailableTry 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

  1. Check this troubleshooting guide
  2. Review the API Documentation
  3. Check the Examples for similar use cases
  4. 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

Best Practices for Avoiding Issues

  1. Always validate inputs before sending requests
  2. Implement proper error handling in your applications
  3. Use appropriate image sizes for your use case
  4. Monitor your API usage to avoid rate limits
  5. Keep your API keys secure and rotate them regularly
  6. Test thoroughly in a development environment first
  7. Stay updated with the latest API changes and best practices

Last updated: January 2024