API Documentation

Complete guide to using the Qwen Image Edit API

API Documentation

The Qwen Image Edit API provides powerful image editing capabilities through simple HTTP endpoints. This guide covers all available endpoints, parameters, and usage examples.

Authentication

All API requests require authentication using an API key. Include your API key in the request headers:

const headers = {
  'Authorization': `Bearer ${API_KEY}`,
  'Content-Type': 'application/json'
};

Base URL

https://qwenimageedit.top/api

Endpoints

Text Editing

Edit or add text within images while preserving the original style and context.

Endpoint: POST /api/image/text-edit

Parameters:

ParameterTypeRequiredDescription
imageFile/URLYesSource image to edit
instructionstringYesText editing instruction
positionobjectNoText position coordinates
styleobjectNoText style preferences

Example Request:

const response = await fetch('/api/image/text-edit', {
  method: 'POST',
  headers,
  body: JSON.stringify({
    image: 'https://example.com/image.jpg',
    instruction: 'Change the text "Hello" to "Welcome"',
    position: { x: 100, y: 50 },
    style: {
      fontSize: 24,
      color: '#000000',
      fontFamily: 'Arial'
    }
  })
});

const result = await response.json();

Response:

{
  "success": true,
  "editedImage": "https://example.com/edited-image.jpg",
  "processingTime": 2.5,
  "creditsUsed": 1
}

Semantic Editing

Perform high-level semantic changes to images, such as style transfer or object manipulation.

Endpoint: POST /api/image/semantic-edit

Parameters:

ParameterTypeRequiredDescription
imageFile/URLYesSource image to edit
promptstringYesSemantic editing instruction
strengthnumberNoEdit strength (0.1-1.0)
preserveAreasarrayNoAreas to preserve during editing

Example Request:

const response = await fetch('/api/image/semantic-edit', {
  method: 'POST',
  headers,
  body: JSON.stringify({
    image: 'https://example.com/portrait.jpg',
    prompt: 'Convert to impressionist painting style',
    strength: 0.8,
    preserveAreas: [
      { x: 50, y: 50, width: 200, height: 200 }
    ]
  })
});

const result = await response.json();

Batch Processing

Process multiple images in a single request for efficiency.

Endpoint: POST /api/image/batch-edit

Parameters:

ParameterTypeRequiredDescription
imagesarrayYesArray of image URLs or files
operationsarrayYesArray of editing operations
parallelbooleanNoProcess images in parallel

Example Request:

const response = await fetch('/api/image/batch-edit', {
  method: 'POST',
  headers,
  body: JSON.stringify({
    images: [
      'https://example.com/image1.jpg',
      'https://example.com/image2.jpg'
    ],
    operations: [
      {
        type: 'text-edit',
        instruction: 'Add watermark "© 2024"',
        position: { x: 10, y: 10 }
      }
    ],
    parallel: true
  })
});

Error Handling

The API returns standard HTTP status codes and detailed error messages:

{
  "success": false,
  "error": {
    "code": "INVALID_IMAGE",
    "message": "The provided image format is not supported",
    "details": "Supported formats: JPEG, PNG, WebP"
  }
}

Common Error Codes:

  • INVALID_API_KEY: Invalid or missing API key
  • INSUFFICIENT_CREDITS: Not enough credits for the operation
  • INVALID_IMAGE: Unsupported image format or corrupted file
  • PROCESSING_FAILED: Image processing failed
  • RATE_LIMIT_EXCEEDED: Too many requests

Rate Limits

  • Free tier: 10 requests per minute
  • Pro tier: 100 requests per minute
  • Enterprise: Custom limits

SDKs and Libraries

JavaScript/TypeScript

npm install @qwen-image-edit/sdk
import { QwenImageEdit } from '@qwen-image-edit/sdk';

const client = new QwenImageEdit({
  apiKey: 'your-api-key',
  baseUrl: 'https://qwenimageedit.top/api'
});

const result = await client.textEdit({
  image: 'path/to/image.jpg',
  instruction: 'Change text color to red'
});

Python

pip install qwen-image-edit
from qwen_image_edit import QwenImageEdit

client = QwenImageEdit(api_key='your-api-key')

result = client.text_edit(
    image='path/to/image.jpg',
    instruction='Change text color to red'
)

Webhooks

For long-running operations, you can use webhooks to receive notifications when processing is complete:

const response = await fetch('/api/image/text-edit', {
  method: 'POST',
  headers,
  body: JSON.stringify({
    image: 'https://example.com/large-image.jpg',
    instruction: 'Complex editing task',
    webhook: {
      url: 'https://your-app.com/webhook',
      secret: 'webhook-secret'
    }
  })
});

Best Practices

  1. Image Quality: Use high-resolution images (minimum 512x512) for better results
  2. Clear Instructions: Provide specific, clear editing instructions
  3. Error Handling: Always implement proper error handling
  4. Rate Limiting: Respect rate limits and implement exponential backoff
  5. Caching: Cache results when possible to reduce API calls

Support

For technical support and questions: