Generate image
Raster generation with Recraft V4.1
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",
"model": "recraftv4_1"
}'
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',
model='recraftv4_1'
)
print(response.data[0].url)
Vector generation with Recraft V4.1 Vector
curl https://external.api.recraft.ai/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-d '{
"prompt": "cat on a mat",
"model": "recraftv4_1_vector"
}'
from openai import OpenAI
client = OpenAI(base_url='https://external.api.recraft.ai/v1', api_key=_RECRAFT_API_TOKEN)
response = client.images.generate(
prompt='cat on a mat',
model='recraftv4_1_vector'
)
print(response.data[0].url)
Custom image size with Recraft V4.1 Pro
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",
"model": "recraftv4_1_pro",
"size": "2560x1664"
}'
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',
model='recraftv4_1_pro',
size='2560x1664',
)
print(response.data[0].url)
Generation with style references (Recraft V4 Styles)
curl -X POST https://external.api.recraft.ai/v1/images/generations \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-F "prompt=product hero shot, bottle on a table" \
-F "model=recraftv4_styles" \
-F "style_references=@reference.png"
curl -X POST https://external.api.recraft.ai/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-d '{
"prompt": "product hero shot, bottle on a table",
"model": "recraftv4_styles",
"style_reference_urls": ["https://example.com/reference.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/generations',
cast_to=object,
options={'headers': {'Content-Type': 'multipart/form-data'}},
body={'prompt': 'product hero shot, bottle on a table', 'model': 'recraftv4_styles'},
files={'style_references': open('reference.png', 'rb')},
)
print(response['data'][0]['url'])
print(response['style_id'])
Generation with a curated style (Recraft V3)
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": "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='Hand-drawn',
)
print(response.data[0].url)
Create style
Style creation and generation with Recraft V4 Styles
curl -X POST https://external.api.recraft.ai/v1/styles \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-F "model=recraftv4_styles" \
-F "file1=@reference-1.png"
# response: {"id":"229b2a75-05e4-4580-85f9-b47ee521a00d"}
curl https://external.api.recraft.ai/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-d '{
"prompt": "product hero shot, bottle on a table",
"model": "recraftv4_styles",
"style_id": "229b2a75-05e4-4580-85f9-b47ee521a00d"
}'
curl -X POST https://external.api.recraft.ai/v1/styles \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-d '{
"model": "recraftv4_styles",
"image_urls": ["https://example.com/reference-1.png"]
}'
# response: {"id":"229b2a75-05e4-4580-85f9-b47ee521a00d"}
curl https://external.api.recraft.ai/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-d '{
"prompt": "product hero shot, bottle on a table",
"model": "recraftv4_styles",
"style_id": "229b2a75-05e4-4580-85f9-b47ee521a00d"
}'
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={'model': 'recraftv4_styles'},
files={'file1': open('reference-1.png', 'rb')},
)
print(style['id'])
response = client.images.generate(
prompt='product hero shot, bottle on a table',
model='recraftv4_styles',
extra_body={'style_id': style['id']},
)
print(response.data[0].url)
Style creation and generation with Recraft V3
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 "model=recraftv3" \
-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",
"model": "recraftv3",
"style_id": "095b9f9d-f06f-4b4e-9bb2-d4f823203427"
}'
curl -X POST https://external.api.recraft.ai/v1/styles \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-d '{
"style": "digital_illustration",
"model": "recraftv3",
"image_urls": ["https://example.com/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",
"model": "recraftv3",
"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', 'model': 'recraftv3'},
files={'file': open('image.png', 'rb')},
)
print(style['id'])
response = client.images.generate(
prompt='wood potato masher',
model='recraftv3',
extra_body={'style_id': style['id']},
)
print(response.data[0].url)
Image to image
Image to image with a curated style (Recraft V3)
curl -X POST https://external.api.recraft.ai/v1/images/imageToImage \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-F "image=@image.png" \
-F "prompt=winter" \
-F "strength=0.2" \
-F "style=Illustration"
curl -X POST https://external.api.recraft.ai/v1/images/imageToImage \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-d '{
"image_url": "https://example.com/image.png",
"prompt": "winter",
"strength": 0.2,
"style": "Illustration"
}'
from openai import OpenAI
client = OpenAI(base_url='https://external.api.recraft.ai/v1', api_key=_RECRAFT_API_TOKEN)
response = client.post(
path='/images/imageToImage',
cast_to=object,
options={'headers': {'Content-Type': 'multipart/form-data'}},
files={
'image': open('image.png', 'rb'),
},
body={
'prompt': 'winter',
'strength': 0.2,
'style': 'Illustration',
},
)
print(response['data'][0]['url'])
Image inpainting
Inpainting with a curated style (Recraft V3)
curl -X POST https://external.api.recraft.ai/v1/images/inpaint \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-F "prompt=moon" \
-F "style=Enterprise" \
-F "image=@image.png" -F "mask=@mask.png"
curl -X POST https://external.api.recraft.ai/v1/images/inpaint \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-d '{
"prompt": "moon",
"style": "Enterprise",
"image_url": "https://example.com/image.png",
"mask_url": "https://example.com/mask.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/inpaint',
cast_to=object,
options={'headers': {'Content-Type': 'multipart/form-data'}},
files={
'image': open('image.png', 'rb'),
'mask': open('mask.png', 'rb'),
},
body={
'style': 'Enterprise',
'prompt': 'moon',
},
)
print(response['data'][0]['url'])
Image outpainting
Outpainting to a target aspect ratio
curl -X POST https://external.api.recraft.ai/v1/images/outpaint \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-F "prompt=a mountain landscape" \
-F "size=16:9" \
-F "zoom_out_percentage=25.0" \
-F "image=@image.png"
curl -X POST https://external.api.recraft.ai/v1/images/outpaint \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-d '{
"prompt": "a mountain landscape",
"size": "16:9",
"zoom_out_percentage": 25.0,
"image_url": "https://example.com/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/outpaint',
cast_to=object,
options={'headers': {'Content-Type': 'multipart/form-data'}},
files={
'image': open('image.png', 'rb'),
},
body={
'prompt': 'a mountain landscape',
'size': '16:9',
'zoom_out_percentage': 25.0,
},
)
print(response['data'][0]['url'])
Outpainting with per-side margins
curl -X POST https://external.api.recraft.ai/v1/images/outpaint \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-F "prompt=a mountain landscape" \
-F "expand_left=256" \
-F "expand_right=256" \
-F "expand_top=128" \
-F "expand_bottom=128" \
-F "image=@image.png"
curl -X POST https://external.api.recraft.ai/v1/images/outpaint \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-d '{
"prompt": "a mountain landscape",
"expand_left": 256,
"expand_right": 256,
"expand_top": 128,
"expand_bottom": 128,
"image_url": "https://example.com/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/outpaint',
cast_to=object,
options={'headers': {'Content-Type': 'multipart/form-data'}},
files={
'image': open('image.png', 'rb'),
},
body={
'prompt': 'a mountain landscape',
'expand_left': 256,
'expand_right': 256,
'expand_top': 128,
'expand_bottom': 128,
},
)
print(response['data'][0]['url'])
Vectorize image
Vectorization of a PNG image
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"
curl -X POST https://external.api.recraft.ai/v1/images/vectorize \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-d '{
"image_url": "https://example.com/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
Background removal with a Base64 JSON response
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"
curl -X POST https://external.api.recraft.ai/v1/images/removeBackground \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-d '{
"response_format": "b64_json",
"image_url": "https://example.com/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/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'])
Crisp upscale
Crisp upscale with a Base64 JSON response
curl -X POST https://external.api.recraft.ai/v1/images/crispUpscale \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-F "response_format=b64_json" \
-F "file=@image.png"
curl -X POST https://external.api.recraft.ai/v1/images/crispUpscale \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-d '{
"response_format": "b64_json",
"image_url": "https://example.com/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/crispUpscale',
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'])
Creative upscale
Creative upscale of a PNG image
curl -X POST https://external.api.recraft.ai/v1/images/creativeUpscale \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-F "file=@image.png"
curl -X POST https://external.api.recraft.ai/v1/images/creativeUpscale \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-d '{
"image_url": "https://example.com/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/creativeUpscale',
cast_to=object,
options={'headers': {'Content-Type': 'multipart/form-data'}},
files={'file': open('image.png', 'rb')},
)
print(response['image']['url'])
Remix image
Image variation with WEBP output
curl -X POST https://external.api.recraft.ai/v1/images/variateImage \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-F "response_format=url" \
-F "size=1024x1024" \
-F "n=1" \
-F "random_seed=13191922" \
-F "image_format=webp" \
-F "file=@image.png"
curl -X POST https://external.api.recraft.ai/v1/images/variateImage \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-d '{
"response_format": "url",
"size": "1024x1024",
"n": 1,
"random_seed": 13191922,
"image_format": "webp",
"image_url": "https://example.com/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/variateImage',
cast_to=object,
options={'headers': {'Content-Type': 'multipart/form-data'}},
body={"size": "1024x1024", "n": 1, "response_format": "url", "random_seed": 13191922, "image_format": "webp"},
files={'file': open('image.png', 'rb')},
)
print(response['data'][0]["url"])
Explore
Explore images
curl https://external.api.recraft.ai/v1/images/explore \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-d '{
"prompt": "race car on a track",
"model": "recraftv4"
}'
from openai import OpenAI
client = OpenAI(base_url='https://external.api.recraft.ai/v1', api_key=_RECRAFT_API_TOKEN)
response = client.post(
path='/images/explore',
cast_to=object,
body={
'prompt': 'race car on a track',
'model': 'recraftv4',
},
)
print(response['data'][0]['url'])
Explore similar
Explore similar images
curl https://external.api.recraft.ai/v1/images/explore/similar \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-d '{
"source_image_id": "c18a1988-45e7-4c00-82c4-4ad7d3dbce3a",
"similarity": 3
}'
from openai import OpenAI
client = OpenAI(base_url='https://external.api.recraft.ai/v1', api_key=_RECRAFT_API_TOKEN)
response = client.post(
path='/images/explore/similar',
cast_to=object,
body={
'source_image_id': 'c18a1988-45e7-4c00-82c4-4ad7d3dbce3a',
'similarity': 3,
},
)
print(response['data'][0]['url'])
Enhance prompt
Enhance a prompt
curl https://external.api.recraft.ai/v1/prompts/enhance \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RECRAFT_API_TOKEN" \
-d '{
"prompt": "race car on a track"
}'
from openai import OpenAI
client = OpenAI(base_url='https://external.api.recraft.ai/v1', api_key=_RECRAFT_API_TOKEN)
response = client.post(
path='/prompts/enhance',
cast_to=object,
body={'prompt': 'race car on a track'},
)
print(response['enhanced_prompt'])