GalleryLog inGet Recraft Free

AI Image Generation API

Learn the basics of the Recraft API, including image generation, style creation, image vectorization, background removal and practical examples.

Features

Styles

A style is a descriptor that defines the visual appearance and feel of generated images. This includes a wide array of elements such as textures and visual effects, shapes and colors, composition and lines, etc. There are four classes of base styles: realistic image, digital illustration, vector illustration and icon.

Realistic
Show More

Images of style “realistic” are expected to look like just ordinary photographs made with a digital camera or a smartphone or a film camera.

Digital illustration
Show More

Images of style “digital illustration” are pictures drawn by hand or using computers - virtually everything except photos and vector illustrations. The most crucial difference from “realistic images” is that illustrations possess simplified textures (like in 3D-rendered or manually drawn images) - or they are stylized in a certain creative way. The difference from “vector illustration” is that “digital illustrations” allow for more complex color transitions, shades, fine textures.

Vector illustration
Show More

Images of style “vector illustration” are expected to look like those drawn using vector graphics (see Wikipedia). Usually, they use only a few different colors at once, shapes are filled with flat colors or simple color gradients. Shapes of objects can be arbitrarily complex.

Icon
Show More

Images of style “icon” are small digital images or symbols used in the graphical user interface. They are designed to be simple and recognizable at small sizes, often visually summarizing the action or object they stand for, or they can act as the visual identity for an app or a website and are crucial in branding.


A style (except realistic images) can be refined by adding a substyle for more precise definition. Below, you will find a list of supported styles and corresponding substyles. Additionally, you have an option to create your own style by combining a base style (realistic image, digital illustration, vector illustration or icon) with a collection of reference images.

Pricing

API Unit package pricing

The following are the API Unit packages available from Recraft for the use of the Recraft API Service. API Unit packages must be purchased in advance and all API Unit packages are non-cancelable and non-refundable. Any number of unit packages can be bought. 

Price API Units
US $1.00 1,000

API Unit charges for API services

The following are the Service charges (in API Units) for use of the API Services. API Units will be automatically deducted from Member’s pre-purchased API Unit package upon use of the described Service by the Member. The Recraft Service is the system of record for determining API Unit usage.

Service Description API Units Charged
Raster Image Generation Per One Image 40
Vector Image Generation Per One Image 80
Raster Image Style Creation 40
Vector Image Style Creation 40
Image Vectorization 40
Raster Image Background Removal 40

Getting Started

Authenticate and interact with our API in a matter of minutes.

Authentication

We use Bearer API tokens for authentication. To access your API key, log in to Recraft, enter your profile and hit 'Generate' (available only if your API units balance is above zero). All requests should include your API key in an Authorization HTTP header as follows:

Authorization: Bearer RECRAFT_API_TOKEN

REST / Python Library

The Recraft API adheres to REST principles, allowing you to interact using any utilities (e.g., curl), programming languages, or libraries of your choice.

One of the easiest of available alternatives is OpenAI Python library which is also compatible with Recraft API, but it’s important to remember that not all parameters/options are supported or implemented. Additionally, some parameters may have different meanings, or they may be quietly ignored if they are not applicable to the Recraft API.

Future examples will be shown using that library, for example, once installed, you can use the following code to be authenticated:

from openai import OpenAI

client = OpenAI(
  base_url='https://external.api.recraft.ai/v1',
  api_key=<TOKEN>,
)

Usage

Dig into the details of using the Recraft API.

Generate Image

Creates an image given a prompt.

POST https://external.api.recraft.ai/v1/images/generations

Example

response = client.images.generate(
  prompt='race car on a track',
  style='digital_illustration',
)
print(response.data[0].url)

Output

URL: https://img.recraft.ai/TH4CG_8z2Ql8G1B_mx9tkVQk67i6TmdM9Av13L2-ERE
/rs:fit:1024:1024:0/raw:1/plain/abs:/
/prod/images/a9f881cb-7638-4fa8-88d2-cc65dbfd0375

Parameters

Parameter Type Description
prompt (required) string A text description of the desired image(s). The maximum length is 500 characters.
n integer or null, default is 1 Currently, only n=1 and n=2 are supported at the moment.
style_id UUID or null Use a previously uploaded style as a reference, this topic is covered above and below.
style string or null, default is realistic_image The style of the generated images, this topic is covered above.
substyle string or null This topic is covered above.
response_format string or null, default is url The format in which the generated images are returned. Must be one of url or b64_json.
size string or null, default is 1024x1024 The size of the generated images in WxH format, supported values are published below.
controls object or null A set of custom parameters to tweak generation process, this topic is covered below.


Note
: style_id and style parameters are mutually exclusive. If neither of the two parameters is specified, the default style of realistic_image will be used

Hint: if OpenAI Python Library is used, non-standard parameters can be passed using the extra_body argument. For example:

response = client.images.generate(
  prompt='race car on a track',
  extra_body={
    'style_id': style_id,
    'controls': {
      ...
    }
  }
)
print(response.data[0].url)

Vectorize Image

Converts a given raster image to SVG format.

POST https://external.api.recraft.ai/v1/images/vectorize

Example

response = client.post(
    path='/images/vectorize',
    cast_to=object,
    options={'headers': {'Content-Type': 'multipart/form-data'}},
    files={'file': open('image.png', 'rb')},
)
print(response['image']['url'])

Output

https://img.recraft.ai/fZm6nwEjI9Qy94LukIKbxRm4w2i5crwqu459qKg7ZWY
/rs:fit:1341:1341:0/raw:1/plain/abs://external/images/2835e19f-282b-419b-b80c-9231a3d51517

Parameters

Body of a request should be a file in PNG format and parameters passed as content type 'multipart/form-data'.

Parameter Type Description
response_format string or null, default is url The format in which the generated images are returned. Must be one of 'url' or 'b64_json'.

Remove Background

Removes background of a given raster image.

POST https://external.api.recraft.ai/v1/images/removeBackground

Example

response = client.post(
    path='/images/removeBackground',
    cast_to=object,
    options={'headers': {'Content-Type': 'multipart/form-data'}},
    files={'file': open('image.png', 'rb')},
)
print(response['image']['url'])

Output

https://img.recraft.ai/EYOLjpky-2-uClelfP61kzK-SEpIhKgLfjLFFGxmM_U
/rs:fit:0:0:0/raw:1/plain/abs://external/images/e2d0cba6-12df-4141-aa21-43bfd5889990

Parameters

Body of a request should be a file in PNG format and parameters passed as content type 'multipart/form-data'.

Parameter Type Description
response_format string or null, default is url The format in which the generated images are returned. Must be one of 'url' or 'b64_json'.

Create style

Upload a set of images to create a style reference.

POST https://external.api.recraft.ai/v1/styles

Example

response = client.post(
		path='/styles',
		cast_to=object,
		options={'headers': {'Content-Type': 'multipart/form-data'}},
		body={'style': 'digital_illustration'},
		files={'file1': open('image.png', 'rb')},
)
print(response.data[0].url)

Output

{"id": "229b2a75-05e4-4580-85f9-b47ee521a00d"} 

Request Body

Upload a set of images to create a style reference.

Parameter Type Description
style (required) string The base style of the generated images, this topic is covered above.
files (required) files Images in PNG format for using as style references. The max number of the images is 5.

Auxiliary

Controls

The generation process can be adjusted with a number of tweaks.

colors (required) An array of preferable colors
background_color Use given color as a desired background color

Colors

Color type is defined as an object with the following fields

rgb (required) An array of 3 integer values in range of 0...255 defining RGB Color Model
Example
response = client.images.generate(
  prompt='race car on a track',
  style='realistic_image',
  extra_body={
    'controls': {
      'image_type': 'realistic_image',
      'colors': [
        {'rgb': [0, 255, 0]}
      ]
    }
  }
)
print(response.data[0].url)

Guides

Generate AI images using cURL or Python and create your own styles programmatically.

Generate a Digital Illustration

curl https://external.api.recraft.ai/v1/images/generations \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $RECRAFT_API_TOKEN" \
    -d '{
		    "prompt": "two race cars on a track",
		    "style": "digital_illustration"
		}'
from openai import OpenAI

client = OpenAI(base_url='https://external.api.recraft.ai/v1', api_key=_RECRAFT_API_TOKEN)

response = client.images.generate(
  prompt='two race cars on a track',
  style='digital_illustration',
)
print(response.data[0].url)

Generate a Realistic Image with Specific Size

curl https://external.api.recraft.ai/v1/images/generations \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $RECRAFT_API_TOKEN" \
    -d '{
		    "prompt": "red point siamese cat",
		    "style": "realistic_image",
		    "size": "1280x1024"
		}'
from openai import OpenAI

client = OpenAI(base_url='https://external.api.recraft.ai/v1', api_key=_RECRAFT_API_TOKEN)

response = client.images.generate(
  prompt='red point siamese cat',
  style='realistic_image',
  size='1280x1024',
)
print(response.data[0].url)

Generate a Digital Illustration with Specific Substyle

curl https://external.api.recraft.ai/v1/images/generations \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $RECRAFT_API_TOKEN" \
    -d '{
        "prompt": "a monster with lots of hands",
        "style": "digital_illustration",
        "substyle": "hand_drawn"
    }'
from openai import OpenAI

client = OpenAI(base_url='https://external.api.recraft.ai/v1', api_key=_RECRAFT_API_TOKEN)

response = client.images.generate(
  prompt='a monster with lots of hands',
  style='digital_illustration',
  extra_body={'substyle': 'hand_drawn'},
)
print(response.data[0].url)

Create Own Style by Uploading Reference Images and Use Them for Generation

curl -X POST https://external.api.recraft.ai/v1/styles \
    -H "Content-Type: multipart/form-data" \
    -H "Authorization: Bearer $RECRAFT_API_TOKEN" \
    -F "style=digital_illustration" \
    -F "file=@image.png"

# response: {"id":"095b9f9d-f06f-4b4e-9bb2-d4f823203427"}

curl https://external.api.recraft.ai/v1/images/generations \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $RECRAFT_API_TOKEN" \
    -d '{
        "prompt": "wood potato masher",
        "style_id": "095b9f9d-f06f-4b4e-9bb2-d4f823203427"
    }'
from openai import OpenAI

client = OpenAI(base_url='https://external.api.recraft.ai/v1', api_key=_RECRAFT_API_TOKEN)

style = client.post(
    path='/styles',
    cast_to=object,
    options={'headers': {'Content-Type': 'multipart/form-data'}},
    body={'style': 'digital_illustration'},
    files={'file': open('image.png', 'rb')},
)
print(style['id'])

response = client.images.generate(
    prompt='wood potato masher',
    extra_body={'style_id': style['id']},
)
print(response.data[0].url)

Vectorize an Image in PNG format

curl -X POST https://external.api.recraft.ai/v1/images/vectorize \
    -H "Content-Type: multipart/form-data" \
    -H "Authorization: Bearer $RECRAFT_API_TOKEN" \
    -F "file=@image.png"
from openai import OpenAI

client = OpenAI(base_url='https://external.api.recraft.ai/v1', api_key=_RECRAFT_API_TOKEN)

response = client.post(
    path='/images/vectorize',
    cast_to=object,
    options={'headers': {'Content-Type': 'multipart/form-data'}},
    files={'file': open('image.png', 'rb')},
)
print(response['image']['url'])

Remove Background From a PNG Image, Get the Result in B64 JSON

curl -X POST https://external.api.recraft.ai/v1/images/removeBackground \
    -H "Content-Type: multipart/form-data" \
    -H "Authorization: Bearer $RECRAFT_API_TOKEN" \
    -F "response_format=b64_json" \
    -F "file=@image.png"
from openai import OpenAI

client = OpenAI(base_url='https://external.api.recraft.ai/v1', api_key=_RECRAFT_API_TOKEN)

style = client.post(
    path='/images/removeBackground',
    cast_to=object,
    options={'headers': {'Content-Type': 'multipart/form-data'}},
    body={'response_format': 'b64_json'},
    files={'file': open('image.png', 'rb')},
)
print(response['image']['url'])

Appendix

List of styles

Style Substyles
realistic_image (not applicable)
digital_illustration - seamless
- pixel_art
- 3d
- psychedelic
- hand_drawn
- grain
- glow
- 80s
- watercolor
- voxel
- infantile_sketch
- 2d_art_poster
- kawaii
icon - outline
- broken_line
- colored_shapes
- colored_outline
- uneven_fill
- doodle_fill
- offset_fill
- doodle_offset_fill
- outline_gradient
- colored_shapes_gradient
vector_illustration - seamless
- line_art
- doodle_line_art
- flat_2
- cartoon
- kawaii
- linocut
- engraving

List of image sizes

- 1024x1024
- 1365x1024
- 1024x1365
- 1536x1024
- 1024x1536
- 1820x1024
- 1024x1820
- 1024x2048
- 2048x1024
- 1434x1024
- 1024x1434
- 1024x1280
- 1280x1024
- 1024x1707
- 1707x1024

Policies

  • All generated images are currently stored indefinitely. However, this policy may change in the future, and you should not rely on it remaining constant.
  • Images are publicly accessible via direct links without authentication. However, since the URLs include unique image identifiers and are cryptographically signed, restoring lost links is nearly impossible.
  • Currently, image generation rates are defined on a per-user basis and set at 100 images per minute. These rates may be adjusted in the future.
Close Modal