# Clothes Changer

Change clothing in a photo using a reference clothing image.

## Description

Upload a photo of a person and a reference image of clothing. The API will apply the clothing from the reference image to the person while preserving their pose and identity.

## Authentication

**Required**: x402 payment

This endpoint requires payment via the x402 protocol. See the [Setup](./setup.md) for setup instructions.

## Request

**Endpoint**: `POST /api/clothes-changer/change`

**Content-Type**: `multipart/form-data`

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| subject | file | Yes | Photo of the person (JPG, PNG, or WebP, max 10MB) |
| clothing | file | Yes | Reference image of clothing to apply (JPG, PNG, or WebP, max 10MB) |
| aspectRatio | string | No | Desired aspect ratio for the output |

## Response

**200 OK**

```json
{
  "imageUrl": "/outputs/uuid-here.png"
}
```

| Field | Type | Description |
|-------|------|-------------|
| imageUrl | string | Path to the generated image |

## Error Codes

| Status | Code | Description |
|--------|------|-------------|
| 400 | VALIDATION_ERROR | Invalid request parameters |
| 402 | PAYMENT_REQUIRED | x402 payment not completed |
| 413 | FILE_TOO_LARGE | File exceeds 10MB limit |
| 415 | UNSUPPORTED_FORMAT | Invalid file type (must be JPG, PNG, or WebP) |
| 422 | INVALID_IMAGE_DATA | Unable to process image |
| 500 | INTERNAL_ERROR | AI generation failed |
| 504 | AI_GENERATION_TIMEOUT | AI request timed out |

## Example

```bash
npx x402-proxy -X POST \
  -F "subject=@person.jpg" \
  -F "clothing=@denim-jacket.jpg" \
  -F "aspectRatio=1:1" \
  https://ps.codejar.net/api/clothes-changer/change
```

**Response:**
```json
{
  "imageUrl": "/outputs/550e8400-e29b-41d4-a716-446655440003.png"
}
```
