# Material Changer

Change the material or texture of objects in images using AI.

## Description

Upload an image and specify the object and the new material you want to apply. Google Gemini 2.5 Flash Image (nano-banana) will intelligently replace the material while maintaining the original shape and lighting.

## Authentication

**Required**: x402 payment

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

## Request

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

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

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| image | file | Yes | Input image (JPEG, PNG, or WebP, max 10MB) |
| targetDescription | string | No | Description of the object to change (e.g., "the sofa", "the car body") |
| materialDescription | string | No | Description of the new material (e.g., "leather", "brushed steel", "wood grain") |

## Response

**200 OK**

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

| Field | Type | Description |
|-------|------|-------------|
| imageUrl | string | Path to the processed image with material changed |

## Error Codes

| Status | Code | Description |
|--------|------|-------------|
| 400 | VALIDATION_ERROR | No image provided |
| 402 | PAYMENT_REQUIRED | x402 payment not completed |
| 413 | FILE_TOO_LARGE | File exceeds 10MB limit |
| 415 | UNSUPPORTED_FORMAT | File type not allowed (only JPEG, PNG, WebP) |
| 500 | INTERNAL_ERROR | AI generation failed |
| 504 | AI_GENERATION_TIMEOUT | AI request timed out |

## Examples

### Change sofa material to leather

```bash
npx x402-proxy -X POST \
  -F "image=@living-room.jpg" \
  -F "targetDescription=the sofa" \
  -F "materialDescription=luxury red leather" \
  https://ps.codejar.net/api/material-changer/change
```

### Change car body to matte black

```bash
npx x402-proxy -X POST \
  -F "image=@car-photo.jpg" \
  -F "targetDescription=the car body" \
  -F "materialDescription=matte black vinyl wrap" \
  https://ps.codejar.net/api/material-changer/change
```

### Change wall to brick texture

```bash
npx x402-proxy -X POST \
  -F "image=@room.jpg" \
  -F "targetDescription=the feature wall" \
  -F "materialDescription=exposed brick" \
  https://ps.codejar.net/api/material-changer/change
```

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

## Use Cases

- **Interior Design**: Preview furniture with different materials and colors
- **Automotive**: Visualize cars with different paint or wrap finishes
- **Real Estate**: Show property with different flooring or wall materials
- **E-commerce**: Display products with alternative material options
- **Architectural Visualization**: Apply different building materials to designs
