# Inpainting sdxl and sd

> Inpaint images with SD and SDXL


## Overview

- **Endpoint**: `https://fal.run/fal-ai/inpaint`
- **Model ID**: `fal-ai/inpaint`
- **Category**: image-to-image
- **Kind**: inference
**Tags**: editing, diffusion



## Pricing

- **Price**: $0 per compute seconds

For more details, see [fal.ai pricing](https://fal.ai/pricing).

## API Information

This model can be used via our HTTP API or more conveniently via our client libraries.
See the input and output schema below, as well as the usage examples.


### Input Schema

The API accepts the following input parameters:


- **`model_name`** (`string`, _required_):
  URL or HuggingFace ID of the base model to generate the image.
  - Examples: "diffusers/stable-diffusion-xl-1.0-inpainting-0.1", "stabilityai/stable-diffusion-xl-base-1.0", "runwayml/stable-diffusion-v1-5", "SG161222/Realistic_Vision_V2.0"

- **`prompt`** (`string`, _required_):
  The prompt to use for generating the image. Be as descriptive as possible for best results.
  - Examples: "a photo of a cat"

- **`negative_prompt`** (`string`, _optional_):
  The negative prompt to use. Use it to address details that you don't want
  in the image. This could be colors, objects, scenery and even the small details
  (e.g. moustache, blurry, low resolution). Default value: `""`
  - Default: `""`
  - Examples: "cartoon, painting, illustration, (worst quality, low quality, normal quality:2)", "nsfw, cartoon, (epicnegative:0.9)"

- **`image_url`** (`string`, _required_):
  Input image for img2img or inpaint mode
  - Examples: "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"

- **`mask_url`** (`string`, _required_):
  Input mask for inpaint mode. Black areas will be preserved, white areas will be inpainted.
  - Examples: "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"

- **`num_inference_steps`** (`integer`, _optional_):
  Increasing the amount of steps tells Stable Diffusion that it should take more steps
  to generate your final result which can increase the amount of detail in your image. Default value: `30`
  - Default: `30`
  - Range: `0` to `150`

- **`guidance_scale`** (`float`, _optional_):
  The CFG (Classifier Free Guidance) scale is a measure of how close you want
  the model to stick to your prompt when looking for a related image to show you. Default value: `7.5`
  - Default: `7.5`
  - Range: `0` to `20`

- **`seed`** (`integer`, _optional_):
  The same seed and the same prompt given to the same version of Stable Diffusion
  will output the same image every time.
  - Examples: 1234



**Required Parameters Example**:

```json
{
  "model_name": "diffusers/stable-diffusion-xl-1.0-inpainting-0.1",
  "prompt": "a photo of a cat",
  "image_url": "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png",
  "mask_url": "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
}
```

**Full Example**:

```json
{
  "model_name": "diffusers/stable-diffusion-xl-1.0-inpainting-0.1",
  "prompt": "a photo of a cat",
  "negative_prompt": "cartoon, painting, illustration, (worst quality, low quality, normal quality:2)",
  "image_url": "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png",
  "mask_url": "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png",
  "num_inference_steps": 30,
  "guidance_scale": 7.5,
  "seed": 1234
}
```


### Output Schema

The API returns the following output format:

- **`image`** (`Image`, _required_):
  The generated image files info.

- **`seed`** (`integer`, _required_):
  Seed of the generated Image. It will be the same value of the one passed in the
  input or the randomly generated that was used in case none was passed.



**Example Response**:

```json
{
  "image": {
    "url": "",
    "content_type": "image/png",
    "file_name": "z9RV14K95DvU.png",
    "file_size": 4404019,
    "width": 1024,
    "height": 1024
  }
}
```


## Usage Examples

### cURL

```bash
curl --request POST \
  --url https://fal.run/fal-ai/inpaint \
  --header "Authorization: Key $FAL_KEY" \
  --header "Content-Type: application/json" \
  --data '{
     "model_name": "diffusers/stable-diffusion-xl-1.0-inpainting-0.1",
     "prompt": "a photo of a cat",
     "image_url": "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png",
     "mask_url": "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
   }'
```

### Python

Ensure you have the Python client installed:

```bash
pip install fal-client
```

Then use the API client to make requests:

```python
import fal_client

def on_queue_update(update):
    if isinstance(update, fal_client.InProgress):
        for log in update.logs:
           print(log["message"])

result = fal_client.subscribe(
    "fal-ai/inpaint",
    arguments={
        "model_name": "diffusers/stable-diffusion-xl-1.0-inpainting-0.1",
        "prompt": "a photo of a cat",
        "image_url": "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png",
        "mask_url": "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
    },
    with_logs=True,
    on_queue_update=on_queue_update,
)
print(result)
```

### JavaScript

Ensure you have the JavaScript client installed:

```bash
npm install --save @fal-ai/client
```

Then use the API client to make requests:

```javascript
import { fal } from "@fal-ai/client";

const result = await fal.subscribe("fal-ai/inpaint", {
  input: {
    model_name: "diffusers/stable-diffusion-xl-1.0-inpainting-0.1",
    prompt: "a photo of a cat",
    image_url: "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png",
    mask_url: "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
  },
  logs: true,
  onQueueUpdate: (update) => {
    if (update.status === "IN_PROGRESS") {
      update.logs.map((log) => log.message).forEach(console.log);
    }
  },
});
console.log(result.data);
console.log(result.requestId);
```


## Additional Resources

### Documentation

- [Model Playground](https://fal.ai/models/fal-ai/inpaint)
- [API Documentation](https://fal.ai/models/fal-ai/inpaint/api)
- [OpenAPI Schema](https://fal.ai/api/openapi/queue/openapi.json?endpoint_id=fal-ai/inpaint)

### fal.ai Platform

- [Platform Documentation](https://docs.fal.ai)
- [Python Client](https://docs.fal.ai/clients/python)
- [JavaScript Client](https://docs.fal.ai/clients/javascript)
