Skip to main content

Image to Image with LCM


Image to Image with LCM

POST https://api.novita.ai/v3/lcm-img2img

10x faster image generation with latent consistency models, synthesizing High-Resolution images with few-step inference.

Request header parameters

  • Content-TypestringRequired

    undefined

    Enum:
    application/json
  • AuthorizationstringRequired

    Bearer authentication format, for example: Bearer {{API Key}}.

Request Body parameters

  • extraobject

    Optional extra parameters for the request.

    Show properties
  • model_namestringRequired

    This parameter specifies the name of the model checkpoint. Retrieve the corresponding sd_name_in_api value by invoking the https://novita.ai/reference/model/query_model.html endpoint with type=checkpoint as the query parameter.

  • input_imagestringRequired

    The base64 of input image, with a maximum resolution of 2048 * 2048 and a max file size of 30 Mb, the returned image will be the same with size of input images.

  • promptstringRequired

    Text input required to guide the image generation, divided by `,`, Range [1, 1024].

  • negative_promptstring

    Text input that will not guide the image generation, divided by `,`, you can also add embedding (textual inversion) models like `badhandv4_16755`,Range: [1, 1024]

  • image_numintegerRequired

    Image numbers. Range: [1, 16]

  • sd_vaestringRequired

    VAE(Variational Auto Encoder),sd_vae can be access in api /v3/models with query params type=vae, like sd_name_in_api: customVAE.safetensors, get reference at https://novita.ai/get-started/Misc.html#what-s-variational-autoencoders-vae.

  • loras[object]

    LoRA is a fast and lightweight training method that inserts and trains a significantly smaller number of parameters instead of all the model parameters. Currenlty supports up to 5 LoRAs.

    Show properties
  • embeddings[object]

    Textual Inversion is a training method for personalizing models by learning new text embeddings from a few example images, currenlty supports up to 5 embeddings.

    Show properties
  • stepsintegerRequired

    The number of denoising steps. More steps usually can produce higher quality images, but take more time to generate, Range: [1, 8]

  • guidance_scalenumberRequired

    This setting says how close the Stable Diffusion will listen to your prompt, higer guidance forces the model to better follow the prompt, but result in lower quality output, Range [0, 3].

  • seedintegerRequired

    A seed is a number from which Stable Diffusion generates noise, which, makes generation deterministic. Using the same seed and set of parameters will produce identical image each time, minimum -1.

  • clip_skipinteger

    This parameter indicates the number of layers to stop from the bottom during optimization, so clip_skip on 2 would mean, that in SD1.x model where the CLIP has 12 layers, you would stop at 10th layer, Range [1, 12], get reference at https://novita.ai/get-started/Misc.html#what-s-clip-skip.

  • strengthnumber¦null

    The lower the strength, the more closely the output images will resemble the input image, Range: [0, 1]

Responses

  • images[object]

    Image information.

    Show properties

Example

1. Img2img request with LCM

10x faster image generation with latent consistency models, synthesizing High-Resolution images with few-step inference.

Request:

curl --location --request POST 'https://dev-api.novita.ai/v3/lcm-img2img' \
--header 'Authorization: Bearer {{key}}' \
--header 'Content-Type: application/json' \
--header 'Accept-Encoding: gzip' \
--data-raw '{
    "model_name": "dreamshaper_8_93211.safetensors",
    "input_image": "{{Base64 encoded image}}",
    "prompt": "beautilful sunflower, sun",
    "negative_prompt": "",
    "sd_vae": "vae-ft-mse-840000-ema-pruned.safetensors",
    "loras":[
        {
            "model_name": "more_details_59655",
            "strenth": 0.5
        },
        {
            "model_name": "Gothpunk_30978",
            "strenth": 0.5
        }
    ],
    "embeddings": [
        {
            "model_name": "AS-YoungV2"
        },
        {
            "model_name": "MidAged"
        }
    ],
    "image_num": 1,
    "steps": 3,
    "seed": 123,
    "clip_skip": 1,
    "guidance_scale": 0
}'

HTTP status codes in the 2xx range indicate that the request has been successfully accepted, code 400 means requst params error, while status codes in the 5xx range indicate internal server errors.

Response:

{
  "image": [
    {
      "image_url": "https://faas-output-image.s3.ap-southeast-1.amazonaws.com/test/lcm_img2img_e1ca4ee4-aa69-4073-94ab-f2dddc6bf7fc_0.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20231201%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20231201T081801Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=4d9d50cf00116cea5409acbef51caaf023f805804be3f13efcb980982a2b4d46",
      "image_url_ttl": "3600",
      "image_type": "jpeg"
    }
  ]
}