# Latent Consistency (SDXL & SDv1.5)

> Produce high-quality images with minimal inference steps.


## Overview

- **Endpoint**: `https://fal.run/fal-ai/lcm`
- **Model ID**: `fal-ai/lcm`
- **Category**: text-to-image
- **Kind**: inference
**Tags**: diffusion, lcm, real-time



## 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:


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

- **`image_url`** (`string`, _required_):
  The image to use as a base.
  - Examples: "https://storage.googleapis.com/falserverless/model_tests/lcm/beach.png"

- **`mask_url`** (`string`, _optional_):
  Mask URL for compatibility with generic LCM processing.

- **`strength`** (`float`, _optional_):
  The strength of the image. Default value: `0.8`
  - Default: `0.8`
  - Range: `0` to `1`

- **`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, illustration, animation. face. male, female", "ugly, deformed"

- **`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: 42

- **`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: `1`
  - Default: `1`
  - Range: `0` to `16`

- **`num_inference_steps`** (`integer`, _optional_):
  The number of inference steps to use for generating the image. The more steps
  the better the image will be but it will also take longer to generate. Default value: `4`
  - Default: `4`
  - Range: `1` to `12`

- **`sync_mode`** (`boolean`, _optional_):
  If `True`, the media will be returned as a data URI and the output data won't be available in the request history.
  - Default: `false`

- **`num_images`** (`integer`, _optional_):
  The number of images to generate. The function will return a list of images
  with the same prompt and negative prompt but different seeds. Default value: `1`
  - Default: `1`
  - Range: `1` to `8`

- **`enable_safety_checks`** (`boolean`, _optional_):
  If set to true, the resulting image will be checked whether it includes any
  potentially unsafe content. If it does, it will be replaced with a black
  image. Default value: `true`
  - Default: `true`

- **`request_id`** (`string`, _optional_):
  An id bound to a request, can be used with response to identify the request
  itself. Default value: `""`
  - Default: `""`



**Required Parameters Example**:

```json
{
  "prompt": "masterpiece, colorful, photo of a beach in hawaii, sun",
  "image_url": "https://storage.googleapis.com/falserverless/model_tests/lcm/beach.png"
}
```

**Full Example**:

```json
{
  "prompt": "masterpiece, colorful, photo of a beach in hawaii, sun",
  "image_url": "https://storage.googleapis.com/falserverless/model_tests/lcm/beach.png",
  "strength": 0.8,
  "negative_prompt": "cartoon, illustration, animation. face. male, female",
  "seed": 42,
  "guidance_scale": 1,
  "num_inference_steps": 4,
  "num_images": 1,
  "enable_safety_checks": true
}
```


### Output Schema

The API returns the following output format:

- **`images`** (`list<Image>`, _required_):
  The generated image files info.
  - Array of Image

- **`timings`** (`Timings`, _required_)

- **`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.

- **`num_inference_steps`** (`integer`, _optional_):
  Number of inference steps used to generate the image. It will be the same value of the one passed in the
  input or the default one in case none was passed. Default value: `4`
  - Default: `4`

- **`request_id`** (`string`, _optional_):
  An id bound to a request, can be used with response to identify the request
  itself. Default value: `""`
  - Default: `""`

- **`nsfw_content_detected`** (`list<boolean>`, _required_):
  A list of booleans indicating whether the generated image contains any
  potentially unsafe content. If the safety check is disabled, this field
  will have a false for each generated image.
  - Array of boolean



**Example Response**:

```json
{
  "images": [
    {
      "url": "",
      "content_type": "image/jpeg"
    }
  ],
  "num_inference_steps": 4
}
```


## Usage Examples

### cURL

```bash
curl --request POST \
  --url https://fal.run/fal-ai/lcm \
  --header "Authorization: Key $FAL_KEY" \
  --header "Content-Type: application/json" \
  --data '{
     "prompt": "masterpiece, colorful, photo of a beach in hawaii, sun",
     "image_url": "https://storage.googleapis.com/falserverless/model_tests/lcm/beach.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/lcm",
    arguments={
        "prompt": "masterpiece, colorful, photo of a beach in hawaii, sun",
        "image_url": "https://storage.googleapis.com/falserverless/model_tests/lcm/beach.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/lcm", {
  input: {
    prompt: "masterpiece, colorful, photo of a beach in hawaii, sun",
    image_url: "https://storage.googleapis.com/falserverless/model_tests/lcm/beach.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/lcm)
- [API Documentation](https://fal.ai/models/fal-ai/lcm/api)
- [OpenAPI Schema](https://fal.ai/api/openapi/queue/openapi.json?endpoint_id=fal-ai/lcm)

### 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)
