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

LiteLLM supports Recraft Image Generation 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

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"