Skip to main content

Image to Image


Image to Image

POST https://api.novita.ai/v3/async/img2img

Generate images with Stable Diffusion Models from Image and Text Prompts.

This is an asynchronous API; only the task_id is returned initially. Utilize this task_id to query the Task Result API at https://novita.ai/reference/task/task.htmlopen in new window in order to retrieve the results of the image generation.

Request header parameters

  • AuthorizationstringRequired

  • Content-TypestringRequired

    Enum: application/json

Request Body parameters

  • extraobject

    extra infos.

    Show properties
  • requestobjectRequired

    Show properties

Responses

  • task_idstring

    task_id

Example

1. Image to image request with normal parameter.

Please set the Content-Type header to application/json in your HTTP request to indicate that you are sending JSON data. Currently, only JSON format is supported.

Request with image_assets_id:

curl --location 'https://api.novita.ai/v3/async/img2img' \
--header 'Authorization: Bearer {{key}}' \
--header 'Content-Type: application/json' \
--data '{
    "extra": {
        "response_image_type": "jpeg"
    },
    "request": {
        "model_name": "chilloutmix_NiPrunedFp32Fix.safetensors",
        "prompt": "a cute dog",
        "negative_prompt": "",
        "height": 512,
        "width": 384,
        "image_num": 1,
        "steps": 20,
        "seed": -1,
        "clip_skip": 1,
        "guidance_scale": 7.5,
        "sampler_name": "Euler a",
        "embeddings": [
            {
                "model_name": "pureerosface_v1_5162.pt"
            }
        ],
        "loras": [
            {
              "model_name": "add_detail_44319",
              "strength": 0.7
            },
            {
              "model_name": "more_details_59655",
              "strength": 0.7
            }
        ],
        "image_base64": "{{Base64 encode image}}"
    }
}'

Response:

{
    "code": 0,
    "msg": "",
    "data": {
        "task_id": "73fab7c0-e24f-4027-9df0-81ff8ce4bc1f"
    }
}

Use task_id to get images

HTTP status codes in the 2xx range indicate that the request has been successfully accepted, while status codes in the 5xx range indicate internal server errors.

You can get images url in imgs of response.

Request:

curl --location --request GET 'https://api.novita.ai/v3/async/task-result?task_id=73fab7c0-e24f-4027-9df0-81ff8ce4bc1f' \
--header 'Authorization: Bearer {{key}}'

Response:

{
    "extra": {
        "seed": "1434608307"
    },
    "task": {
        "task_id": "73fab7c0-e24f-4027-9df0-81ff8ce4bc1f",
        "task_type": "IMG_TO_IMG",
        "status": "TASK_STATUS_SUCCEED",
        "reason": "",
        "eta": 0,
        "progress_percent": 0
    },
    "images": [
        {
            "image_url": "https://faas-output-image.s3.ap-southeast-1.amazonaws.com/prod/73fab7c0-e24f-4027-9df0-81ff8ce4bc1f/d54551765e41409fbc80f7c23dc89241.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20240115%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20240115T083555Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=92dca9221e620d708c29ec525ed50ceb984dda23d8b7a352b4a19be682c8906e",
            "image_url_ttl": "3600",
            "image_type": "jpeg"
        }
    ],
    "videos": []
}

2. Image to image request with controlNet.

Please set the Content-Type header to application/json in your HTTP request to indicate that you are sending JSON data. Currently, only JSON format is supported.

Request with image_assets_id:

curl --location 'https://api.novita.ai/v3/async/img2img' \
--header 'Authorization: Bearer {{key}}' \
--header 'Content-Type: application/json' \
--data '{
    "extra": {
        "response_image_type": "jpeg"
    },
    "request": {
        "model_name": "realcartoon25D_v3_240762.safetensors",
        "prompt": "1girl",
        "negative_prompt": "bad quality, bad anatomy, worst quality, low quality, lowres, extra fingers, blur, blurry, ugly, wrong proportions, watermark, image artifacts, bad eyes, bad hands, bad arms",
        "height": 1024,
        "width": 1024,
        "image_num": 1,
        "steps": 20,
        "seed": -1,
        "clip_skip": 1,
        "guidance_scale": 7,
        "sampler_name": "Euler",
        "controlnet": {
            "units": [
                {
                    "model_name": "control_v11p_sd15_openpose",
                    "image_base64": "{{Base64 encode image}}",
                    "strength": 0.5,
                    "preprocessor": "openpose"
                }
            ]
        },
        "image_base64": "{{Base64 encode image}}"
    }
}'

Response:

{
    "code": 0,
    "msg": "",
    "data": {
        "task_id": "5867de36-7b76-4dc7-876e-818e3ffe683e"
    }
}

Use task_id to get images

HTTP status codes in the 2xx range indicate that the request has been successfully accepted, while status codes in the 5xx range indicate internal server errors.

You can get images url in imgs of response.

Request:

curl --location --request GET 'https://api.novita.ai/v3/async/task-result?task_id=5867de36-7b76-4dc7-876e-818e3ffe683e' \
--header 'Authorization: Bearer {{key}}'

Response:

{
    "extra": {
        "seed": "632855931",
        "enable_nsfw_detection": false
    },
    "task": {
        "task_id": "5867de36-7b76-4dc7-876e-818e3ffe683e",
        "task_type": "IMG_TO_IMG",
        "status": "TASK_STATUS_SUCCEED",
        "reason": "",
        "eta": 0,
        "progress_percent": 0
    },
    "images": [
        {
            "image_url": "https://faas-output-image.s3.ap-southeast-1.amazonaws.com/prod/5867de36-7b76-4dc7-876e-818e3ffe683e/6569906512e14c2da82d74e69882b3a4.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20240307%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20240307T064348Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=f506cd2dc7ed7526bfe1cf4074722a1178efe242db6ca56e1e7dbca9b67230d2",
            "image_url_ttl": "3600",
            "image_type": "jpeg",
            "nsfw_detection_result": null
        }
    ],
    "videos": []
}

3. Image to image request with Textual Inversion(embedding).

Please set the Content-Type header to application/json in your HTTP request to indicate that you are sending JSON data. Currently, only JSON format is supported.

Request for textual inversion names:

curl --location --request GET 'https://api.novita.ai/v3/model?filter.visibility=public&pagination.limit=100&pagination.cursor=c_0&filter.types=textualinversion&filter.source=civitai' \
--header 'Authorization: Bearer {{key}}' | jq '.models[].sd_name'

Response:

"epiCPhotoGasm-colorfulPhoto-neg_108119.pt"
"epiCNegative_66017.pt"
"verybadimagenegative_v1.3_21434.pt"
"FastNegativeV2_65067.pt"
"AS-YoungV2.pt"
"AS-YoungV2-neg.pt"
"AS-YoungestV2.pt"
"AS-YoungerV2.pt"
"AS-MidAged.pt"
"AS-Elderly.pt"
"AS-Adult.pt"
"AS-Adult-neg.pt"
"Adult.pt"
"MidAged.pt"
"unaestheticXLv13_98060.safetensors"
"unaestheticXL_Sky3.1_134255.safetensors"
"EasyNegativeV2_75525.safetensors"
"BadDream_53202.pt"
"UnrealisticDream_53204.pt"
"negative_hand-neg_43127.pt"
"bad_prompt_version2-neg_42594.pt"
"Asian-Less-Toon_39763.pt"
"badhandv4_16755.pt"
"easynegative_8955.safetensors"
"aestheticc-65800_8615.pt"
"corneo_side_deepthroat_6490.pt"
"corneo_tentacle_sex.pt"
"By bad artist -neg_6310.pt"
"dpthrt_5441.pt"
"ng_deepnegative_v1_75t_5845.pt"
"pureerosface_v1_5162.pt"

Request with image_assets_id:

curl --location 'https://api.novita.ai/v3/async/img2img' \
--header 'Authorization: Bearer {{key}}' \
--header 'Content-Type: application/json' \
--data '{
    "extra": {
        "response_image_type": "jpeg"
    },
    "request": {
        "model_name": "realcartoon25D_v3_240762.safetensors",
        "prompt": "dark theme girl",
        "negative_prompt": "",
        "height": 1024,
        "width": 1024,
        "image_num": 1,
        "steps": 20,
        "seed": 123,
        "clip_skip": 1,
        "guidance_scale": 7.5,
        "sampler_name": "Euler a",
        "embeddings": [
            {
                "model_name": "badhandv4_16755.pt"
            },
            {
                "model_name": "BadDream_53202.pt"
            }
        ],
        "image_base64": "{{Base64 encode image}}"
    }
}'

Response:

{
    "code": 0,
    "msg": "",
    "data": {
        "task_id": "6411f576-1c62-48b4-a0d5-427488721159"
    }
}

Use task_id to get images

HTTP status codes in the 2xx range indicate that the request has been successfully accepted, while status codes in the 5xx range indicate internal server errors.

You can get images url in imgs of response.

Request:

curl --location --request GET 'https://api.novita.ai/v3/async/task-result?task_id=6411f576-1c62-48b4-a0d5-427488721159' \
--header 'Authorization: Bearer {{key}}'

Response:

{
    "extra": {
        "seed": "170871295",
        "enable_nsfw_detection": false
    },
    "task": {
        "task_id": "6411f576-1c62-48b4-a0d5-427488721159",
        "task_type": "IMG_TO_IMG",
        "status": "TASK_STATUS_SUCCEED",
        "reason": "",
        "eta": 0,
        "progress_percent": 0
    },
    "images": [
        {
            "image_url": "https://faas-output-image.s3.ap-southeast-1.amazonaws.com/prod/6411f576-1c62-48b4-a0d5-427488721159/ede3a87d667e4371abc687b9ede03938.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20240307%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20240307T065015Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=228bb2254bf7de328814c89b200287ab903f7f5690033f810c745ae7be902b76",
            "image_url_ttl": "3600",
            "image_type": "jpeg",
            "nsfw_detection_result": null
        }
    ],
    "videos": []
}

4. Img2img request with nsfw_detection.

When set enable_nsfw_detection true, NSFW detection will be enabled, incurring an additional cost of $0.0015 for each generated image.

nsfw_detection_level, nsfw check level, ranging from 0 to 2, with higher levels indicating stricter NSFW detection criteria. The default value is 0. The following table lists the NSFW detection criteria for each level.

- 0: Explicit Nudity, Explicit Sexual Activity, Sex Toys; Hate Symbols.
- 1: Explicit Nudity, Explicit Sexual Activity, Sex Toys; Hate Symbols; Non-Explicit Nudity, Obstructed Intimate Parts, Kissing on the Lips.
- 2: Explicit Nudity, Explicit Sexual Activity, Sex Toys; Hate Symbols; Non-Explicit Nudity, Obstructed Intimate Parts, Kissing on the Lips; Female Swimwear or Underwear, Male Swimwear or Underwear.

Please set the Content-Type header to application/json in your HTTP request to indicate that you are sending JSON data. Currently, only JSON format is supported.

Request:

curl --location 'https://api.novita.ai/v3/async/img2img' \
--header 'Authorization: Bearer {{key}}' \
--header 'Content-Type: application/json' \
--data '{
    "extra": {
        "response_image_type": "jpeg",
        "enable_nsfw_detection": true,
        "nsfw_detection_level": 2
    },
    "request": {
        "model_name": "chilloutmix_NiPrunedFp32Fix.safetensors",
        "prompt": "a cute dog",
        "negative_prompt": "",
        "height": 512,
        "width": 384,
        "image_num": 1,
        "steps": 20,
        "seed": 123,
        "clip_skip": 1,
        "guidance_scale": 7.5,
        "sampler_name": "Euler a",
        "embeddings": [
            {
                "model_name": "pureerosface_v1_5162.pt"
            }
        ],
        "loras": [
            {
                "model_name": "MS_Real_AssSpread",
                "strength": 0.7
            },
            {
                "model_name": "MS_Real_Cameltoe_Lite",
                "strength": 0.9
            }
        ],
        "controlnet": {
            "units": [
                {
                    "model_name": "control_v11f1e_sd15_tile",
                    "image_base64": "{{Base64 encode image}}",
                    "strength": 1,
                    "preprocessor": "openpose"
                }
            ]
        },
        "image_base64": "{{Base64 encode image}}"
    }
}'

Response:

{
    "code": 0,
    "msg": "",
    "data": {
        "task_id": "741597cc-8e27-4932-9d75-34f07b96413e"
    }
}

Use task_id to get images

HTTP status codes in the 2xx range indicate that the request has been successfully accepted, while status codes in the 5xx range indicate internal server errors.

You can get images url in imgs of response.

There are two results in reponse.

  • enable_nsfw_detection, when return with true means NSFW detection is enabled.

  • nsfw_detection_result, presenting an array of NSFW detection outcomes for each image. The order of elements in the nsfw_detection_result array corresponds one-to-one with the sequence of images in the images field in the response. The valid field denotes the success of the NSFW detection process, while the confidence field, ranging from 0 to 100, signifies the confidence level of the NSFW detection result. Higher confidence values, nearing 100, suggest a greater likelihood of the corresponding image containing NSFW content.

Request:

curl --location --request GET 'https://api.novita.ai/v3/async/task-result?task_id=741597cc-8e27-4932-9d75-34f07b96413e' \
--header 'Authorization: Bearer {{key}}'

Response:

{
    "extra": {
        "seed": "3183986171",
        "enable_nsfw_detection": true
    },
    "task": {
        "task_id": "741597cc-8e27-4932-9d75-34f07b96413e",
        "task_type": "TXT_TO_IMG",
        "status": "TASK_STATUS_SUCCEED",
        "reason": "",
        "eta": 0,
        "progress_percent": 0
    },
    "images": [
        {
            "image_url": "https://faas-output-image.s3.ap-southeast-1.amazonaws.com/prod/741597cc-8e27-4932-9d75-34f07b96413e/6e38c309732f4241b99f75e54ffdb54a.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20240124%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20240124T141031Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=9edf916b9f3148207953140d0ec545a468e50fc80e635d4a7fa182c67989ced8",
            "image_url_ttl": "3600",
            "image_type": "jpeg",
            "nsfw_detection_result": {
                "valid": true,
                "confidence": 0
            }
        },
        {
            "image_url": "https://faas-output-image.s3.ap-southeast-1.amazonaws.com/prod/741597cc-8e27-4932-9d75-34f07b96413e/b8346c9cbe494102be2a28f29c0005b1.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20240124%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20240124T141031Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=d81316dea2446aab04cd5e559504a2a8fa7245958d766afd8f372e7e8fb02fb9",
            "image_url_ttl": "3600",
            "image_type": "jpeg",
            "nsfw_detection_result": {
                "valid": true,
                "confidence": 0
            }
        },
        {
            "image_url": "https://faas-output-image.s3.ap-southeast-1.amazonaws.com/prod/741597cc-8e27-4932-9d75-34f07b96413e/f6e0f939a5e4466990595445a41e75ef.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20240124%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20240124T141031Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=6d719fe7e4e6cb0f93ec07616b20e968f659b12102e4b11c866016780eb2eb6c",
            "image_url_ttl": "3600",
            "image_type": "jpeg",
            "nsfw_detection_result": {
                "valid": true,
                "confidence": 0
            }
        },
        {
            "image_url": "https://faas-output-image.s3.ap-southeast-1.amazonaws.com/prod/741597cc-8e27-4932-9d75-34f07b96413e/ddbc7d39db1d4468bd3c9d92556b99ee.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20240124%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20240124T141031Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=259a5d358175132a2c0adfcd23142bb8227cd6e68052b99779686956c04a713a",
            "image_url_ttl": "3600",
            "image_type": "jpeg",
            "nsfw_detection_result": {
                "valid": true,
                "confidence": 0
            }
        }
    ],
    "videos": []
}