Text to Image
Text to Image
POST https://api.novita.ai/v3/async/txt2img
Generate images from text prompts using Stable Diffusion models.
This is an asynchronous API; only the task_id will be returned. You should use the task_id to request the Task Result API to retrieve the image generation results.
Example
1. Txt2img request with normal parameters
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/txt2img' \
--header 'Authorization: Bearer {{API Key}}' \
--header 'Content-Type: application/json' \
--data '{
"extra": {
"response_image_type": "jpeg"
},
"request": {
"prompt": "a cute dog",
"model_name": "sd_xl_base_1.0.safetensors",
"negative_prompt": "nsfw, bottle, bad face",
"width": 1024,
"height": 1024,
"image_num": 2,
"steps": 20,
"seed": -1,
"clip_skip": 1,
"sampler_name": "Euler a",
"guidance_scale": 7.5
}
}'
Response:
{
"task_id": "f10333f2-2dd7-4f56-a177-e3c02a774d9a"
}
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=f10333f2-2dd7-4f56-a177-e3c02a774d9a' \
--header 'Authorization: Bearer {{API Key}}'
Response:
{
"extra": {
"seed": "392212448",
"enable_nsfw_detection": false,
"debug_info": {
"request_info": "{\"model\":\"sd_xl_base_1.0.safetensors\",\"prompts\":[\"a cute dog\"],\"negative_prompts\":[\"nsfw, bottle,bad face\"],\"seeds\":[392212448],\"height\":384,\"width\":512,\"guidance_scale\":7.5,\"num_images_per_prompt\":2,\"num_inference_steps\":20,\"sampler_name\":\"Euler a\",\"clip_skip\":1}",
"submit_time_ms": "1715052533293",
"execute_time_ms": "1715052533362",
"complete_time_ms": "1715052537148"
}
},
"task": {
"task_id": "f10333f2-2dd7-4f56-a177-e3c02a774d9a",
"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/f10333f2-2dd7-4f56-a177-e3c02a774d9a/80443e6739584fcb82bc2cf4f3b557fb.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20240507%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20240507T032908Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=b375b64e0886d0253d5463af241a30bd4a1e4718287f37f73b0e80d5dce4d214",
"image_url_ttl": "3600",
"image_type": "jpeg",
"nsfw_detection_result": null
}, {
"image_url": "https://faas-output-image.s3.ap-southeast-1.amazonaws.com/prod/f10333f2-2dd7-4f56-a177-e3c02a774d9a/9b16e333242244e58a4d03c4bfb1bca5.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20240507%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20240507T032908Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=fff0623985c741661497532eb682a7ae23094bcf2e55c4eee61e256e97c81e3c",
"image_url_ttl": "3600",
"image_type": "jpeg",
"nsfw_detection_result": null
}],
"videos": [],
"audios": []
}
2.Txt2img request with lora
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/txt2img' \
--header 'Authorization: Bearer {{API Key}}' \
--header 'Content-Type: application/json' \
--data '{
"extra": {
"response_image_type": "jpeg"
},
"request": {
"prompt": "a cute dog",
"model_name": "majicmixRealistic_v6_65516.safetensors",
"negative_prompt": "nsfw, bottle,bad face",
"width": 512,
"height": 512,
"image_num": 2,
"steps": 20,
"seed": 123,
"clip_skip": 1,
"sampler_name": "Euler a",
"guidance_scale": 7.5,
"loras": [
{
"model_name": "add_detail_44319",
"strength": 0.7
},
{
"model_name": "more_details_59655",
"strength": 0.7
}
]
}
}'
Response:
{
"task_id": "6469ca5b-5929-4200-b263-241020763eb8"
}
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=6469ca5b-5929-4200-b263-241020763eb8' \
--header 'Authorization: Bearer {{API Key}}'
Response:
{
"extra": {
"seed": "123"
},
"task": {
"task_id": "6469ca5b-5929-4200-b263-241020763eb8",
"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/6469ca5b-5929-4200-b263-241020763eb8/xxx.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20240111%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20240111T134101Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=bbe71142c83df530e1dfb6be1a26faa1d9907b24f0fc77b2aee399683c51b134",
"image_url_ttl": "3600",
"image_type": "jpeg"
},
{
"image_url": "https://faas-output-image.s3.ap-southeast-1.amazonaws.com/prod/6469ca5b-5929-4200-b263-241020763eb8/xxx.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20240111%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20240111T134101Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=8fc609a70c35d7b12f7690443dae6e59d2550b76461e73b2fd8296ec4333e208",
"image_url_ttl": "3600",
"image_type": "jpeg"
}
],
"videos": []
}
3.Txt2img request with upscale
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/txt2img' \
--header 'Authorization: Bearer {{API Key}}' \
--header 'Content-Type: application/json' \
--data '{
"extra": {
"response_image_type": "jpeg"
},
"request": {
"prompt": "a cute dog",
"model_name": "realisticVisionV51_v51VAE_94301.safetensors",
"negative_prompt": "nsfw, bottle,bad face",
"width": 512,
"height": 512,
"image_num": 2,
"steps": 20,
"seed": 123,
"clip_skip": 1,
"sampler_name": "Euler a",
"guidance_scale": 7.5,
"hires_fix": {
"target_width": 1024,
"target_height": 1024,
"strength": 0.8,
"upscaler": "Latent"
}
}
}'
Response:
{
"task_id": "6469ca5b-5929-4200-b263-241020763eb8"
}
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=6469ca5b-5929-4200-b263-241020763eb8' \
--header 'Authorization: Bearer {{API Key}}'
Response:
{
"extra": {
"seed": "123",
"enable_nsfw_detection": false
},
"task": {
"task_id": "6469ca5b-5929-4200-b263-241020763eb8",
"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/6469ca5b-5929-4200-b263-241020763eb8/23a98c94383e466289b4ae39a2d1fe73.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20240307%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20240307T034029Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=3f45b6214e176fc90f3c78e04bc01e5883f25a0a8122409eb00ae8ea971d1be6",
"image_url_ttl": "3600",
"image_type": "jpeg",
"nsfw_detection_result": null
},
{
"image_url": "https://faas-output-image.s3.ap-southeast-1.amazonaws.com/prod/6469ca5b-5929-4200-b263-241020763eb8/19146c52474445e4ae2554ad807f7f6b.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20240307%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20240307T034029Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=a69c62262cdec60dd74f2efc2fd965cb98473112ce291542930d5b7d9b37755a",
"image_url_ttl": "3600",
"image_type": "jpeg",
"nsfw_detection_result": null
}
],
"videos": []
}
4.Txt2img request with SDXL 1.0
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/txt2img' \
--header 'Authorization: Bearer {{API Key}}' \
--header 'Content-Type: application/json' \
--data '{
"extra": {
"response_image_type": "jpeg"
},
"request": {
"prompt": "a cute dog",
"model_name": "sd_xl_base_1.0.safetensors",
"negative_prompt": "nsfw, bottle,bad face",
"width": 1024,
"height": 1024,
"image_num": 1,
"steps": 20,
"seed": -1,
"clip_skip": 1,
"sampler_name": "Euler a",
"guidance_scale": 7.5
}
}'
Response:
{
"task_id": "6469ca5b-5929-4200-b263-241020763eb8"
}
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=6469ca5b-5929-4200-b263-241020763eb8' \
--header 'Authorization: Bearer {{API Key}}'
Response:
{
"extra": {
"seed": "3706472920",
"enable_nsfw_detection": false
},
"task": {
"task_id": "346b3562-ae4e-4849-a9fb-9318cb1a689d",
"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/346b3562-ae4e-4849-a9fb-9318cb1a689d/5698013f545d425cbcdeae00cef8c435.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20240307%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20240307T033747Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=68f00e2800de145d5c2c9d05f957a684283fa8dce41049337b8ce59267c49cf2",
"image_url_ttl": "3600",
"image_type": "jpeg",
"nsfw_detection_result": null
}
],
"videos": []
}
5.Txt2img 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 {{API 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:
curl --location 'https://api.novita.ai/v3/async/txt2img' \
--header 'Authorization: Bearer {{API Key}}' \
--header 'Content-Type: application/json' \
--data '{
"extra": {
"response_image_type": "jpeg"
},
"request": {
"prompt": "1girl",
"model_name": "realisticVisionV51_v51VAE_94301.safetensors",
"negative_prompt": "nsfw, bottle,bad face",
"width": 512,
"height": 512,
"image_num": 1,
"steps": 20,
"seed": -1,
"clip_skip": 1,
"sampler_name": "Euler a",
"guidance_scale": 7.5,
"embeddings": [
{
"model_name": "badhandv4_16755.pt"
},
{
"model_name": "BadDream_53202.pt"
}
]
}
}'
Response:
{
"task_id": "6469ca5b-5929-4200-b263-241020763eb8"
}
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=6469ca5b-5929-4200-b263-241020763eb8' \
--header 'Authorization: Bearer {{API Key}}'
Response:
{
"extra": {
"seed": "767172278",
"enable_nsfw_detection": false
},
"task": {
"task_id": "22388880-1c37-4ae1-8738-2fe7f5e8af57",
"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/6469ca5b-5929-4200-b263-241020763eb8/72768e59c4884965824347bfb400e3fd.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20240307%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20240307T035327Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=e0a44ec5fe21d9e64dc59b1b53017df737218b8c7db6f4e6d2cd46ca8e42b2ab",
"image_url_ttl": "3600",
"image_type": "jpeg",
"nsfw_detection_result": null
}
],
"videos": []
}
6.Txt2img 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/txt2img' \
--header 'Authorization: Bearer {{API Key}}' \
--header 'Content-Type: application/json' \
--data '{
"extra": {
"response_image_type": "jpeg",
"enable_nsfw_detection": true,
"nsfw_detection_level": 2
},
"request": {
"prompt": "1girl,sexy",
"model_name": "dreamshaper_8_93211.safetensors",
"negative_prompt": "nsfw, bottle,bad face",
"width": 512,
"height": 512,
"image_num": 4,
"steps": 20,
"seed": -1,
"clip_skip": 1,
"sampler_name": "Euler a",
"guidance_scale": 7.5
}
}'
Response:
{
"code": 0,
"msg": "",
"data": {
"task_id": "0fe0f291-05c9-41a4-83bb-3365d4b54f8b"
}
}
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 withtrue
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 theimages
field in the response. Thevalid
field denotes the success of the NSFW detection process, while theconfidence
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=0fe0f291-05c9-41a4-83bb-3365d4b54f8b' \
--header 'Authorization: Bearer {{API Key}}'
Response:
{
"extra": {
"seed": "1998521869",
"enable_nsfw_detection": true
},
"task": {
"task_id": "0fe0f291-05c9-41a4-83bb-3365d4b54f8b",
"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/0fe0f291-05c9-41a4-83bb-3365d4b54f8b/50dc49337e5d4ea289050198206b6a11.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20240308%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20240308T091609Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=b8cdebb0ffa90fa869843cbab9d2e348678f621bad35c4bf1f3f90637c512f59",
"image_url_ttl": "3600",
"image_type": "jpeg",
"nsfw_detection_result": {
"valid": true,
"confidence": 93.7176
}
},
{
"image_url": "https://faas-output-image.s3.ap-southeast-1.amazonaws.com/prod/0fe0f291-05c9-41a4-83bb-3365d4b54f8b/9692d408ce65497ba2c1f5da99a72f12.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20240308%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20240308T091609Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=f213cbabdf6d411d9e414377ae2d538cd8dff692befdbe3fa0183c737aeea0c6",
"image_url_ttl": "3600",
"image_type": "jpeg",
"nsfw_detection_result": {
"valid": true,
"confidence": 94.4329
}
},
{
"image_url": "https://faas-output-image.s3.ap-southeast-1.amazonaws.com/prod/0fe0f291-05c9-41a4-83bb-3365d4b54f8b/68336b4bd7194b9b87b53aabcfcd92cf.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20240308%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20240308T091609Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=faa315d2a0a97706486ff00d02399dc12dcd5eb08e9a538c9997bdf389137269",
"image_url_ttl": "3600",
"image_type": "jpeg",
"nsfw_detection_result": {
"valid": true,
"confidence": 94.4224
}
},
{
"image_url": "https://faas-output-image.s3.ap-southeast-1.amazonaws.com/prod/0fe0f291-05c9-41a4-83bb-3365d4b54f8b/a8bc5e8263aa4d9389215b749e56af45.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIASVPYCN6LRCW3SOUV%2F20240308%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=20240308T091609Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=4197c88e751861bbd30e8b9f1fadb67a6808f26e91b57c0ae5ed0512e05bb8ab",
"image_url_ttl": "3600",
"image_type": "jpeg",
"nsfw_detection_result": {
"valid": true,
"confidence": 94.6823
}
}
],
"videos": []
}