Skip to main content

Recraft

https://www.recraft.ai/

Overview​

PropertyDetails
DescriptionRecraft is an AI-powered design tool that generates high-quality images with precise control over style and content.
Provider Route on LiteLLMrecraft/
Link to Provider DocRecraft ↗
Supported Operations/images/generations, /images/edits

LiteLLM supports Recraft Image Generation and Image Edit calls.

API Base, Key​

# env variable
os.environ['RECRAFT_API_KEY'] = "your-api-key"
os.environ['RECRAFT_API_BASE'] = "https://external.api.recraft.ai" # [optional]

Image Generation​

Usage - LiteLLM Python SDK​

from litellm import image_generation
import os

os.environ['RECRAFT_API_KEY'] = "your-api-key"

# recraft image generation call
response = image_generation(
model="recraft/recraftv3",
prompt="A beautiful sunset over a calm ocean",
)
print(response)

Usage - LiteLLM Proxy Server​

1. Setup config.yaml​

model_list:
- model_name: recraft-v3
litellm_params:
model: recraft/recraftv3
api_key: os.environ/RECRAFT_API_KEY
model_info:
mode: image_generation

general_settings:
master_key: sk-1234

2. Start the proxy​

litellm --config config.yaml

# RUNNING on http://0.0.0.0:4000

3. Test it​

curl --location 'http://0.0.0.0:4000/v1/images/generations' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer sk-1234' \
--data '{
"model": "recraft-v3",
"prompt": "A beautiful sunset over a calm ocean",
}'

Advanced Usage - With Additional Parameters​

from litellm import image_generation
import os

os.environ['RECRAFT_API_KEY'] = "your-api-key"

response = image_generation(
model="recraft/recraftv3",
prompt="A beautiful sunset over a calm ocean",
)
print(response)

Supported Parameters​

Recraft supports the following OpenAI-compatible parameters:

ParameterTypeDescriptionExample
nintegerNumber of images to generate (1-4)1
response_formatstringFormat of response (url or b64_json)"url"
sizestringImage dimensions"1024x1024"
stylestringImage style/artistic direction"realistic"

Using Non-OpenAI Parameters​

If you want to pass parameters that are not supported by OpenAI, you can pass them in your request body, LiteLLM will automatically route it to recraft.

In this example we will pass style_id parameter to the recraft image generation call.

Usage with LiteLLM Python SDK

from litellm import image_generation
import os

os.environ['RECRAFT_API_KEY'] = "your-api-key"

response = image_generation(
model="recraft/recraftv3",
prompt="A beautiful sunset over a calm ocean",
style_id="your-style-id",
)

Usage with LiteLLM Proxy Server + OpenAI Python SDK

from openai import OpenAI
import os

os.environ['RECRAFT_API_KEY'] = "your-api-key"

client = OpenAI(api_key=os.environ['RECRAFT_API_KEY'])

response = client.images.generate(
model="recraft/recraftv3",
prompt="A beautiful sunset over a calm ocean",
extra_body={
"style_id": "your-style-id",
},
)
print(response)

Supported Image Generation Models​

Note: All recraft models are supported by LiteLLM Just pass the model name with recraft/<model_name> and litellm will route it to recraft.

Model NameFunction Call
recraftv3image_generation(model="recraft/recraftv3", prompt="...")
recraftv2image_generation(model="recraft/recraftv2", prompt="...")

For more details on available models and features, see: https://www.recraft.ai/docs

Image Edit​

Usage - LiteLLM Python SDK​

from litellm import image_edit
import os

os.environ['RECRAFT_API_KEY'] = "your-api-key"

# Open the image file
with open("reference_image.png", "rb") as image_file:
# recraft image edit call
response = image_edit(
model="recraft/recraftv3",
prompt="Create a studio ghibli style image that combines all the reference images. Make sure the person looks like a CTO.",
image=image_file,
)
print(response)

Usage - LiteLLM Proxy Server​

1. Setup config.yaml​

model_list:
- model_name: recraft-v3
litellm_params:
model: recraft/recraftv3
api_key: os.environ/RECRAFT_API_KEY
model_info:
mode: image_edit

general_settings:
master_key: sk-1234

2. Start the proxy​

litellm --config config.yaml

# RUNNING on http://0.0.0.0:4000

3. Test it​

curl --location 'http://0.0.0.0:4000/v1/images/edits' \
--header 'Authorization: Bearer sk-1234' \
--form 'model="recraft-v3"' \
--form 'prompt="Create a studio ghibli style image that combines all the reference images. Make sure the person looks like a CTO."' \
--form 'image=@"reference_image.png"'

Advanced Usage - With Additional Parameters​

from litellm import image_edit
import os

os.environ['RECRAFT_API_KEY'] = "your-api-key"

with open("reference_image.png", "rb") as image_file:
response = image_edit(
model="recraft/recraftv3",
prompt="Create a studio ghibli style image",
image=image_file,
n=2, # Generate 2 variations
response_format="url", # Return URLs instead of base64
style="realistic_image", # Set artistic style
strength=0.5 # Control transformation strength (0-1)
)
print(response)

Supported Image Edit Parameters​

Recraft supports the following OpenAI-compatible parameters for image editing:

ParameterTypeDescriptionDefaultExample
nintegerNumber of images to generate (1-4)12
response_formatstringFormat of response (url or b64_json)"url""b64_json"
stylestringImage style/artistic direction-"realistic_image"
strengthfloatControls how much to transform the image (0.0-1.0)0.20.5

Using Non-OpenAI Parameters​

You can pass Recraft-specific parameters that are not part of the OpenAI API by including them in your request:

Usage with LiteLLM Python SDK

from litellm import image_edit
import os

os.environ['RECRAFT_API_KEY'] = "your-api-key"

with open("reference_image.png", "rb") as image_file:
response = image_edit(
model="recraft/recraftv3",
prompt="Create a studio ghibli style image",
image=image_file,
style_id="your-style-id", # Recraft-specific parameter
strength=0.7
)

Usage with LiteLLM Proxy Server + OpenAI Python SDK

from openai import OpenAI
import os

client = OpenAI(
api_key="sk-1234", # your LiteLLM proxy master key
base_url="http://0.0.0.0:4000" # your LiteLLM proxy URL
)

with open("reference_image.png", "rb") as image_file:
response = client.images.edit(
model="recraft-v3",
prompt="Create a studio ghibli style image",
image=image_file,
extra_body={
"style_id": "your-style-id",
"strength": 0.7
}
)
print(response)

Supported Image Edit Models​

Note: All recraft models are supported by LiteLLM Just pass the model name with recraft/<model_name> and litellm will route it to recraft.

Model NameFunction Call
recraftv3image_edit(model="recraft/recraftv3", ...)

API Key Setup​

Get your API key from Recraft's website and set it as an environment variable:

export RECRAFT_API_KEY="your-api-key"