This document describes how to integrate Karlo APIs into your service with a REST API.
The Karlo model version for Karlo APIs has been changed to 2.0 on July 6, 2023, and to 2.0.4.0 on November 10, 2023 with additional features related to image editing. The new version offers enhanced features than previous versions.
The original image must comply with the specifications below.
JPG
, PNG
, webp
(Recommended)Karlo API handles the image file for the request and the response as a Base64 encoded string value.
image
parameter.image
field and save it as a PNG
image file.Below is a sample for Base64 encoding and decoding.
import io
import base64
from PIL import Image
# Base64 encoding
def imageToString(img):
img_byte_arr = io.BytesIO()
img.save(img_byte_arr, format='PNG')
my_encoded_img = base64.encodebytes(img_byte_arr.getvalue()).decode('ascii')
return my_encoded_img
# Base64 decoding and saving as a PNG file
def stringToImage(base64_string, mode='RGBA'):
imgdata = base64.b64decode(str(base64_string))
img = Image.open(io.BytesIO(imgdata)).convert(mode)
return img
# Image loading
img = Image.open('my_image.png')
# Base64 encoding
img_base64 = imageToString(img)
# Decoding and saving
image = stringToImage(img_base64, mode='RGB')
Method | URL | Authorization |
---|---|---|
POST |
https://api.kakaobrain.com/v2/inference/karlo/t2i |
REST API Key |
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | - | - | - |
Create new images based on the given text prompt.
Include the REST API key in the request header, and send a POST
request. You must specify the prompt in the request body. Refer to How to use to request more efficiently with optional parameters.
If failed, refer to Error code to figure out the reason.
Name | Description | Required |
---|---|---|
Authorization | Authorization: KakaoAK ${REST_API_KEY} REST API key as a type of user authentication. |
O |
Content-Type | Content-Type: application/json The data type of the request. |
O |
Name | Type | Description | Required |
---|---|---|---|
prompt | String |
A text describing the desired image. (Maximum: 2048 characters) |
O |
negative_prompt | String |
A text describing anything you want to exclude or control from the image when it is generated. (Maximum: 2048 characters) |
X |
width | Integer |
Width of the image, a multiple of 8. (Unit: pixel, Default: 512, Minumum: 384, Maximum: 640) |
X |
height | Integer |
Height of the image, a multiple of 8. (Unit: pixel, Default: 512, Minumum: 384, Maximum: 640) |
X |
upscale | Boolean |
Whether to upscale the generated image.true : Upscalefalse : Do not upscale |
X |
scale | Integer |
Rate to upscale the image, 2 or 4. (Default: 2) Note: Even if the scale is set to 4, you can only upscale the image up to 2048 pixels in width and height. |
X |
image_format | String |
Format to save the image in. One of:webp jpeg png (Default: webp ) |
X |
image_quality | Integer |
Save Image Quality. (Default: 70, Minumum: 1, Maximum: 100) |
X |
samples | Integer |
Number of images to generate. (Default: 1, Minumum: 1, Maximum: 8) |
X |
return_type | String |
Type of the image to return. One of:base64_string : A Base64 encoded value of the image fileurl : A URL of the image file(Default: url ) |
X |
prior_num_inference_steps | Integer |
The number of steps of the prior denoising process. (Default: 25, Minumum: 10, Maximum: 100) |
X |
prior_guidance_scale | Double |
Guidance scale of the prior denoising process. (Default: 5.0, Minumum: 1.0, Maximum: 20.0) |
X |
num_inference_steps | Integer |
The number of steps of the decoder denoising process. (Default: 50, Minumum: 10, Maximum: 100) |
X |
guidance_scale | Double |
Guidance scale of denoising process. (Default: 5.0, Minumum: 1.0, Maximum: 20.0) |
X |
scheduler | String |
Scheduler used by decoder denoising process, One of:decoder_ddim_v_prediction decoder_ddpm_v_prediction (Default: decoder_ddim_v_prediction ) |
X |
seed | Integer[] |
A seed of length equal to the batch size length.seed must have the same lengh with the number of samples .Composed of numbers greater than or equal to 0 and less than or equal to 4,294,967,295. If none, a random. (Default: null )Note: Karlo always generates the same image, if all parameters, including seed , have the same value. |
X |
nsfw_checker | Boolean |
Whether to perform Detect NSFW content on the generated image.true : Performfalse Do not perform(Default: false ) |
X |
face_refiner | FaceRefiner |
Setting parameters for Refine facial structure. | X |
Name | Type | Description | Required |
---|---|---|---|
bbox_size_threshold | Double |
Ratio of facial area to total image to apply face shape refinement feature, apply feature only if actual facial area is smaller than set size (Default: 1, Minumum: 0, Maximum: 1) |
X |
bbox_filter_threshold | Double |
Threshold to determine if the image is a human face, not applied if 0 .(Default: 1, Minumum: 0, Maximum: 1) |
X |
restoration_repeats | Double |
Number of facial structure refinements applied (Default: 2, Minumum: 1, Maximum: 10) |
X |
weight_sft | Double |
Original image retention weight determines how much of the original image is retained. The higher the value, the more of the original image is preserved. (Default: 0.5, Minumum: 0, Maximum 1) |
X |
Name | Type | Description | Required |
---|---|---|---|
id | String |
Transaction ID | O |
model_version | String |
The version of Karlo model that processed the request. | O |
images | Image[] |
An array of generated images. | O |
Name | Type | Description |
---|---|---|
id | String |
Image ID |
seed | Integer |
The seed value used to generate this image. Used to regenerate an image with the same content. |
image | String |
Image file. A Base64 string or URL depends on the return_type value of the request.URL is only active for 10 minutes from the response time. |
nsfw_content_detected | Boolean |
Whether the image includes NSFW(Not Safe For Work) content.true : Includedfalse : Not includedNote: Return null when unused. |
nsfw_score | Double |
NSFW score of the image. Note: Return null when unused. |
# Libraries for REST API requests and image processing
import requests
import json
import urllib
from PIL import Image
# Input the REST API key in [My Application] > [App keys]
REST_API_KEY = '${REST_API_KEY}'
# Generate image
def t2i(prompt, negative_prompt):
r = requests.post(
'https://api.kakaobrain.com/v2/inference/karlo/t2i',
json = {
'prompt': prompt,
'negative_prompt': negative_prompt
},
headers = {
'Authorization': f'KakaoAK {REST_API_KEY}',
'Content-Type': 'application/json'
}
)
# Convert the response to JSON
response = json.loads(r.content)
return response
# Prompt
prompt = "A cat with white fur"
negative_prompt = "sleeping cat, dog, human, ugly face, cropped"
# Call the API
response = t2i(prompt, negative_prompt)
# Show the first image of the response
result = Image.open(urllib.request.urlopen(response.get("images")[0].get("image")))
result.show()
curl -v -X POST "https://api.kakaobrain.com/v2/inference/karlo/t2i" \
-H "Authorization: KakaoAK ${REST_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A cat with white fur",
"negative_prompt": "sleeping cat, human, ugly face, cropped"
}'
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": "3d6fb820-9845-4b3e-8d6d-7cfd01db5649",
"model_version": "${MODEL_VERSION}",
"images": [
{
"id": "a80108f8-b9c6-4bf4-aa38-957a38ced4a8",
"seed": 3878985944,
"image": "https://mk.kakaocdn.net/dna/karlo/image/..."
}
]
}
Method | URL | Authorization |
---|---|---|
POST |
https://api.kakaobrain.com/v2/inference/karlo/upscale |
REST API Key |
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | - | - | - |
Upscale the given image.
Include the REST API key in the request header, and send a POST
request. Pass the images to upscale in images
. Specify the rate to upscale as 2 or 4 by scale
.
If failed, refer to Error code to figure out the reason.
Name | Description | Required |
---|---|---|
Authorization | Authorization: KakaoAK ${REST_API_KEY} REST API key as a type of user authentication. |
O |
Content-Type | Content-Type: application/json The data type of the request. |
O |
Name | Type | Description | Required |
---|---|---|---|
images | String[] |
An array of the values of image files to upscale, refer to Image file specification. Images must be with a size of up to 1024 pixels in width and height. Supports webp , png , jpeg , heic file formats.(Maximum: 8 images) |
O |
scale | Integer |
Rate to upscale the image, 2 or 4. (Default: 2) Note: Even if the scale is set to 4, you can only upscale the image up to 2048 pixels in width and height. |
X |
image_format | String |
Format to save the image in. One of:webp jpeg png (Default: webp ) |
X |
image_quality | Integer |
Save Image Quality. (Default: 70, Minumum: 1, Maximum: 100) |
X |
return_type | String |
Type of the image to return. One of:base64_string : A Base64 encoded value of the image fileurl : A URL of the image file(Default: url ) |
X |
Name | Type | Description |
---|---|---|
images | String[] |
An array of generated images. Base64 strings or URLs depends on the return_type value of the request.URL is only active for 10 minutes from the response time. |
# Libraries for REST API requests and image processing
import requests
import json
import io
import base64
import urllib
from PIL import Image
# Input the REST API key in [My Application] > [App keys]
REST_API_KEY = '${REST_API_KEY}'
# Upscale
def upscale(images, scale=2):
r = requests.post(
'https://api.kakaobrain.com/v2/inference/karlo/upscale',
json = {
'images': images,
'scale': scale
},
headers = {
'Authorization': f'KakaoAK {REST_API_KEY}',
'Content-Type': 'application/json'
}
)
# Convert the response to JSON
response = json.loads(r.content)
return response
# Base64 encoding
def imageToString(img):
img_byte_arr = io.BytesIO()
img.save(img_byte_arr, format='PNG')
my_encoded_img = base64.encodebytes(img_byte_arr.getvalue()).decode('ascii')
return my_encoded_img
# Loading image
img = Image.open('original.png')
# Base64 encoding
img_base64 = imageToString(img)
# An array of Base64 encoded images
img_arr = []
img_arr.append(img_base64)
# Call the API
response = upscale(img_arr, 2)
# Show the first image of the response
result = Image.open(urllib.request.urlopen(response.get("images")[0]))
result.show()
curl -v -X POST "https://api.kakaobrain.com/v2/inference/karlo/upscale" \
-H "Authorization: KakaoAK ${REST_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"images": [
"iVBORw0KGgoAAAANSUhEUgA..."
]
}'
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": "ca2fff9c-83ae-4def-86b9-efdf107cdb96",
"model_version": "${MODEL_VERSION}",
"images": [
"https://mk.kakaocdn.net/dna/karlo/image/..."
]
}
Method | URL | Authorization |
---|---|---|
POST |
https://api.kakaobrain.com/v2/inference/karlo/variations |
REST API Key |
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | - | - | - |
Create variations of the given image.
Include the REST API key in the request header, and send a POST
request. Refer to How to use to request more efficiently with optional parameters.
If failed, refer to Error code to figure out the reason.
Name | Description | Required |
---|---|---|
Authorization | Authorization: KakaoAK ${REST_API_KEY} REST API key as a type of user authentication. |
O |
Content-Type | Content-Type: application/json The data type of the request. |
O |
Name | Type | Description | Required |
---|---|---|---|
image | String |
A Base64 encoded value of the original image file. | O |
width | Integer |
Width of the image, a multiple of 8. (Unit: pixel, Default: 512, Minumum: 384, Maximum: 640) |
X |
height | Integer |
Height of the image, a multiple of 8. (Unit: pixel, Default: 512, Minumum: 384, Maximum: 640) |
X |
upscale | Boolean |
Whether to upscale the generated image.true : Upscalefalse : Do not upscale |
X |
scale | Integer |
Rate to upscale the image, 2 or 4. (Default: 2) Note: Even if the scale is set to 4, you can only upscale the image up to 2048 pixels in width and height. |
X |
image_format | String |
Format to save the image in. One of:webp jpeg png (Default: webp ) |
X |
image_quality | Integer |
Save Image Quality. (Default: 70, Minumum: 1, Maximum: 100) |
X |
samples | Integer |
Number of images to generate. (Default: 1, Minumum: 1, Maximum: 8) |
X |
return_type | String |
Type of the image to return. One of:base64_string : A Base64 encoded value of the image fileurl : A URL of the image file(Default: url ) |
X |
num_inference_steps | Integer |
The number of steps of the decoder denoising process. (Default: 50, Minumum: 10, Maximum: 100) |
X |
guidance_scale | Double |
Guidance scale of denoising process. (Default: 5.0, Minumum: 1.0, Maximum: 20.0) |
X |
scheduler | String |
Scheduler used by decoder denoising process, One of:decoder_ddim_v_prediction decoder_ddpm_v_prediction (Default: decoder_ddim_v_prediction ) |
X |
seed | Integer[] |
A seed of length equal to the batch size length.seed must have the same lengh with the number of samples .Composed of numbers greater than or equal to 0 and less than or equal to 4,294,967,295. If none, a random. (Default: null )Note: Karlo always generates the same image, if all parameters, including seed , have the same value. |
X |
nsfw_checker | Boolean |
Whether to perform Detect NSFW content on the generated image.true : Performfalse Do not perform(Default: false ) |
X |
face_refiner | FaceRefiner |
Setting parameters for Refine facial structure. | X |
Name | Type | Description |
---|---|---|
id | String |
Transaction ID |
model_version | String |
The version of Karlo model that processed the request. |
images | Image[] |
An array of generated images. |
# Libraries for REST API requests and image processing
import requests
import json
import io
import base64
import urllib
from PIL import Image
# Input the REST API key in [My Application] > [App keys]
REST_API_KEY = '${REST_API_KEY}'
# Make variation
def variations(image):
r = requests.post(
'https://api.kakaobrain.com/v2/inference/karlo/variations',
json = {
'image': image
},
headers = {
'Authorization': f'KakaoAK {REST_API_KEY}',
'Content-Type': 'application/json'
}
)
# Convert the response to JSON
response = json.loads(r.content)
return response
# Base64 encoding
def imageToString(img):
img_byte_arr = io.BytesIO()
img.save(img_byte_arr, format='PNG')
my_encoded_img = base64.encodebytes(img_byte_arr.getvalue()).decode('ascii')
return my_encoded_img
# Loading image
img = Image.open('original.png')
# Base64 encoding
img_base64 = imageToString(img)
# Call the API
response = variations(img_base64)
print(response)
# Show the first image of the response
result = Image.open(urllib.request.urlopen(response.get("images")[0].get("image")))
result.show()
curl -v -X POST "https://api.kakaobrain.com/v2/inference/karlo/variations" \
-H "Authorization: KakaoAK ${REST_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"image": "iVBORw0KGgoAAAANSUhEUgA..."
}'
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": "6c0db22f-ecba-4d84-a817-b06e06a207da",
"model_version": "${MODEL_VERSION}",
"images": [
{
"id": "812702f0-3627-4a32-91cc-eaec50910156",
"image": "https://mk.kakaocdn.net/dna/karlo/image/...",
"seed": 2639508875
}
]
}
Method | URL | Authorization |
---|---|---|
POST |
https://api.kakaobrain.com/v2/inference/karlo/inpainting |
REST API key |
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | - | - | - |
Creates a connected image based on the given image.
Include the REST API key in the request header, and send a POST
request. Refer to How to use to request more efficiently with optional parameters.
If failed, refer to Error code to figure out the reason.
Name | Description | Required |
---|---|---|
Authorization | Authorization: KakaoAK ${REST_API_KEY} REST API key as a type of user authentication. |
O |
Content-Type | Content-Type: application/json The data type of the request. |
O |
Name | Type | Description | Required |
---|---|---|---|
prompt | String |
A text describing the desired image. (Maximum: 2048 characters) |
O |
negative_prompt | String |
A text describing anything you want to exclude or control from the image when it is generated. (Maximum: 2048 characters) |
X |
image | String |
A Base64 encoded value of the original image file, refer to Image file specification Images must be with a size of up to 1024 pixels in width and height. Supports webp , png , jpeg , heic file formats. |
O |
mask | String |
A Base64 encoded value of the image with the area to be edited colored black (RGB or Grayscale value 0 ), refer to Image file specification |
O |
reference_image | String |
A Base64 encoded value of the image to reference when calibrating the edit area Images must be with a size of up to 1024 pixels in width and height. Supports webp , png , jpeg , heic file formats. |
X |
upscale | Boolean |
Whether to upscale the generated image.true : Upscalefalse : Do not upscale |
X |
scale | Integer |
Rate to upscale the image, 2 or 4. (Default: 2) Note: Even if the scale is set to 4, you can only upscale the image up to 2048 pixels in width and height. |
X |
image_format | String |
Format to save the image in. One of:webp jpeg png (Default: webp ) |
X |
image_quality | Integer |
Save Image Quality. (Default: 70, Minumum: 1, Maximum: 100) |
X |
samples | Integer |
Number of images to generate. (Default: 1, Minumum: 1, Maximum: 8) |
X |
return_type | String |
Type of the image to return. One of:base64_string : A Base64 encoded value of the image fileurl : A URL of the image file(Default: url ) |
X |
prior_num_inference_steps | Integer |
The number of steps of the prior denoising process. (Default: 25, Minumum: 10, Maximum: 100) |
X |
prior_guidance_scale | Double |
Guidance scale of the prior denoising process. (Default: 5.0, Minumum: 1.0, Maximum: 20.0) |
X |
num_inference_steps | Integer |
The number of steps of the decoder denoising process. (Default: 50, Minumum: 10, Maximum: 100) |
X |
guidance_scale | Double |
Guidance scale of denoising process. (Default: 5.0, Minumum: 1.0, Maximum: 20.0) |
X |
seed | Integer[] |
A seed of length equal to the batch size length.seed must have the same lengh with the number of samples .Composed of numbers greater than or equal to 0 and less than or equal to 4,294,967,295. If none, a random. (Default: null )Note: Karlo always generates the same image, if all parameters, including seed , have the same value. |
X |
nsfw_checker | Boolean |
Whether to perform Detect NSFW content on the generated image.true : Performfalse Do not perform(Default: false ) |
X |
face_refiner | FaceRefiner |
Setting parameters for Refine facial structure. | X |
Name | Type | Description |
---|---|---|
id | String |
Transaction ID |
model_version | String |
The version of Karlo model that processed the request. |
images | Image[] |
An array of generated images. |
# Libraries for REST API requests and image processing
import requests
import json
import io
import base64
import urllib
from PIL import Image
# Input the REST API key in [My Application] > [App keys]
REST_API_KEY = '${REST_API_KEY}'
# Modify image
def inpainting(image, mask):
r = requests.post(
'https://api.kakaobrain.com/v2/inference/karlo/inpainting',
json = {
'image': image,
'mask': mask
},
headers = {
'Authorization': f'KakaoAK {REST_API_KEY}',
'Content-Type': 'application/json'
}
)
# Convert the response to JSON
response = json.loads(r.content)
return response
# Base64 encoding
def imageToString(img):
img_byte_arr = io.BytesIO()
img.save(img_byte_arr, format='PNG')
my_encoded_img = base64.encodebytes(img_byte_arr.getvalue()).decode('ascii')
return my_encoded_img
# Loading image
img = Image.open('image.png')
mask = Image.open('mask.png')
# Base64 encoding
img_base64 = imageToString(img)
mask_base64 = imageToString(mask)
# Call the API
response = inpainting(img_base64,mask_base64)
print(response)
# Show the first image of the response
result = Image.open(urllib.request.urlopen(response.get("images")[0].get("image")))
result.show()
curl -v -X POST "https://api.kakaobrain.com/v2/inference/karlo/variations" \
-H "Authorization: KakaoAK ${REST_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"prompt": "tiger",
"image": "https://mk.kakaocdn.net/dn/karlo-dev/...",
"mask": "https://mk.kakaocdn.net/dn/karlo-dev/...",
"negative_prompt": "dog, human",
"samples": 1,
"prior_num_inference_steps": 25,
"prior_guidance_scale": 5,
"num_inference_steps": 50,
"guidance_scale": 5,
"seed": [0],
"nsfw_checker": true,
"upscale": false,
"scale": 2,
"face_refiner": {
"bbox_size_threshold": 1,
"bbox_filter_threshold": 0.5,
"restoration_repeats": 2,
"weight_sft": 0.5
},
"image_format": "webp",
"image_quality": 70
}'
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": "3d6fb820-9845-4b3e-8d6d-7cfd01db5649",
"model_version": "${MODEL_VERSION}",
"images": [
{
"id": "a80108f8-b9c6-4bf4-aa38-957a38ced4a8",
"seed": 3878985944,
"image": "https://mk.kakaocdn.net/dna/karlo/image/..."
}
]
}
Method | URL | Authorization |
---|---|---|
POST |
https://api.kakaobrain.com/v2/inference/karlo/face_refiner |
REST API key |
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | - | - | - |
Refines the person's face to be natural in the image.
Generate image, Make variation, Modify image support a parameter to refine facial structure for the result of the request.
Include the REST API key in the request header, and send a POST
request. Refer to How to use to request more efficiently with optional parameters.
If failed, refer to Error code to figure out the reason.
Name | Description | Required |
---|---|---|
Authorization | Authorization: KakaoAK ${REST_API_KEY} REST API key as a type of user authentication. |
O |
Content-Type | Content-Type: application/json The data type of the request. |
O |
Name | Type | Description | Required |
---|---|---|---|
images | String[] |
An array of the values of image files to upscale, refer to Image file specification. Images must be with a size of up to 1024 pixels in width and height. Supports webp , png , jpeg , heic file formats.(Maximum: 8 images) |
O |
image_format | String |
Format to save the image in. One of:webp jpeg png (Default: webp ) |
X |
image_quality | Integer |
Save Image Quality. (Default: 70, Minumum: 1, Maximum: 100) |
X |
return_type | String |
Type of the image to return. One of:base64_string : A Base64 encoded value of the image fileurl : A URL of the image file(Default: url ) |
X |
bbox_size_threshold | Double |
Ratio of facial area to total image to apply face shape refinement feature, apply feature only if actual facial area is smaller than set size (Default: 1, Minumum: 0, Maximum: 1) |
X |
bbox_filter_threshold | Double |
Threshold to determine if the image is a human face, not applied if 0 .(Default: 1, Minumum: 0, Maximum: 1) |
X |
restoration_repeats | Double |
Number of facial structure refinements applied (Default: 2, Minumum: 1, Maximum: 10) |
X |
weight_sft | Double |
Original image retention weight determines how much of the original image is retained. The higher the value, the more of the original image is preserved. (Default: 0.5, Minumum: 0, Maximum 1) |
X |
Name | Type | Description | Required |
---|---|---|---|
id | String |
Transaction ID | O |
model_version | String |
The version of Karlo model that processed the request. | O |
images | Image[] |
An array of generated images. | O |
# Libraries for REST API requests and image processing
import requests
import json
import io
import base64
import urllib
from PIL import Image
# Input the REST API key in [My Application] > [App keys]
REST_API_KEY = '${REST_API_KEY}'
# Refine facial structure
def faceRefiner(image):
r = requests.post(
'https://api.kakaobrain.com/v2/inference/karlo/face_refiner',
json = {
'images': [image]
},
headers = {
'Authorization': f'KakaoAK {REST_API_KEY}',
'Content-Type': 'application/json'
}
)
# Convert the response to JSON
response = json.loads(r.content)
return response
# Base64 encoding
def imageToString(img):
img_byte_arr = io.BytesIO()
img.save(img_byte_arr, format='PNG')
my_encoded_img = base64.encodebytes(img_byte_arr.getvalue()).decode('ascii')
return my_encoded_img
# Loading image
img = Image.open('original.png')
# Base64 encoding
img_base64 = imageToString(img)
# Call the API
response = faceRefiner(img_base64)
print(response)
# Show the first image of the response
result = Image.open(urllib.request.urlopen(response.get("images")[0]))
result.show()
curl -v -X POST "https://api.kakaobrain.com/v2/inference/karlo/face_refiner" \
-H "Authorization: KakaoAK ${REST_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"images": [
"iVBORw0KGgoAAAANSUhEUgA...",
"aVZCT1J3MEtHZ29BQUFBTNV..."
],
"image_format": "webp",
"image_quality": 70,
"bbox_size_threshold": 1,
"bbox_filter_threshold": 0.5,
"restoration_repeats": 2,
"weight_sft": 0.5
}'
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": "ca2fff9c-83ae-4def-86b9-efdf107cdb96",
"model_version": "${MODEL_VERSION}",
"images": [
"https://mk.kakaocdn.net/dna/karlo/image/...",
"https://mk.kakaocdn.net/dna/karlo/image/..."
]
}
Method | URL | Authorization |
---|---|---|
POST |
https://api.kakaobrain.com/v2/inference/karlo/nsfw_checker |
REST API Key |
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | - | - | - |
Detect whether the given image includes NSFW(Not Safe For Work) content.
Generate image, Upscale, Make variation support a parameter to detect NSFW content for the result of the request.
Include the REST API key in the request header, and send a POST
request. Pass the images in images
.
If failed, refer to Error code to figure out the reason.
Name | Description | Required |
---|---|---|
Authorization | Authorization: KakaoAK ${REST_API_KEY} REST API key as a type of user authentication. |
O |
Content-Type | Content-Type: application/json The data type of the request. |
O |
Name | Type | Description | Required |
---|---|---|---|
images | String[] |
An array of Base64 encoded values of the image files. (Maximum: 8 images) |
O |
Name | Type | Description |
---|---|---|
id | String |
Transaction ID |
model_version | String |
The version of Karlo model that processed the request. |
results | Result[] |
The results of NSFW detection |
Name | Type | Description | Required |
---|---|---|---|
nsfw_content_detected | Boolean |
Whether the image includes NSFW(Not Safe For Work) content.true : Includedfalse : Not included |
X |
nsfw_score | Double |
NSFW score of the image. | X |
# Libraries for REST API requests and image processing
import requests
import json
import io
import base64
from PIL import Image
# Input the REST API key in [My Application] > [App keys]
REST_API_KEY = '${REST_API_KEY}'
# Detect NSFW content
def nsfw(images):
r = requests.post(
'https://api.kakaobrain.com/v2/inference/karlo/nsfw_checker',
json = {
'images': images
},
headers = {
'Authorization': f'KakaoAK {REST_API_KEY}',
'Content-Type': 'application/json'
}
)
# Convert the response to JSON
response = json.loads(r.content)
return response
# Base64 encoding
def imageToString(img):
img_byte_arr = io.BytesIO()
img.save(img_byte_arr, format='PNG')
my_encoded_img = base64.encodebytes(img_byte_arr.getvalue()).decode('ascii')
return my_encoded_img
# Loading image
img = Image.open('target.png')
# Base64 encoding
img_base64 = imageToString(img)
# An array of Base64 encoded images
img_arr = []
img_arr.append(img_base64)
# Call the API
response = nsfw(img_arr)
# Print the result
print(response)
curl -v -X POST "https://api.kakaobrain.com/v2/inference/karlo/nsfw_checker" \
-H "Authorization: KakaoAK ${REST_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"images": [
"iVBORw0KGgoAAAANSUhEUgA..."
]
}'
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": "31aed005-9d31-4248-8a5e-3d086f1eae0e",
"model_version": "${MODEL_VERSION}",
"results": [
{
"nsfw_content_detected": false,
"nsfw_score": 0.20849609375
}
]
}