Recraft
Recraft
AI 기반 디자인 도구인 Recraft를 LiteLLM에서 사용하는 방법을 알아봐요. 스타일과 콘텐츠를 정밀하게 제어하며 고품질 이미지를 생성하고 편집할 수 있어요.
출처: 문서
본문
개요
| 속성 | 내용 |
|---|---|
| 설명 | Recraft는 스타일과 콘텐츠를 정밀하게 제어하며 고품질 이미지를 생성하는 AI 기반 디자인 도구예요 |
| LiteLLM 라우트 | recraft/ |
| 공식 문서 | Recraft ↗ |
| 지원 연산 | /images/generations, /images/edits |
LiteLLM은 Recraft 이미지 생성과 이미지 편집 호출을 지원해요.
API Base, 키
# env variable
os.environ['RECRAFT_API_KEY'] = "your-api-key"
os.environ['RECRAFT_API_BASE'] = "https://external.api.recraft.ai" # [optional]
이미지 생성
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)
LiteLLM Proxy 서버 사용법
1. 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: os.environ/LITELLM_MASTER_KEY
2. Proxy 시작
litellm --config config.yaml
# RUNNING on http://0.0.0.0:4000
3. 테스트
curl --location 'http://0.0.0.0:4000/v1/images/generations' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ***" \
--data '{
"model": "recraft-v3",
"prompt": "A beautiful sunset over a calm ocean",
}'
지원 파라미터
Recraft는 다음 OpenAI 호환 파라미터를 지원해요:
| 파라미터 | 타입 | 설명 | 예시 |
|---|---|---|---|
n |
integer | 생성할 이미지 수 (1-4) | 1 |
response_format |
string | 응답 형식 (url 또는 b64_json) |
"url" |
size |
string | 이미지 크기 | "1024x1024" |
style |
string | 이미지 스타일/예술 방향 | "realistic" |
비-OpenAI 파라미터 사용
OpenAI가 지원하지 않는 파라미터를 요청 본문에 전달하면 LiteLLM이 자동으로 recraft로 라우팅해요. 아래 예시는 style_id 파라미터를 전달하는 예시예요.
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",
)
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)
지원되는 이미지 생성 모델
참고: 모든 recraft 모델을 LiteLLM이 지원해요. 모델 이름에 recraft/을 붙이면 litellm이 recraft로 라우팅해요.
| 모델명 | 함수 호출 |
|---|---|
| recraftv3 | image_generation(model="recraft/recraftv3", prompt="...") |
| recraftv2 | image_generation(model="recraft/recraftv2", prompt="...") |
사용 가능한 모델과 기능에 대한 자세한 내용은 https://www.recraft.ai/docs 를 참고해요.
이미지 편집
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)
LiteLLM Proxy 서버 사용법
1. 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: os.environ/LITELLM_MASTER_KEY
2. Proxy 시작
litellm --config config.yaml
# RUNNING on http://0.0.0.0:4000
3. 테스트
curl --location 'http://0.0.0.0:4000/v1/images/edits' \
--header "Authorization: Bearer ***" \
--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"'
고급 사용법 - 추가 파라미터
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)
지원되는 이미지 편집 파라미터
Recraft는 이미지 편집을 위한 다음 OpenAI 호환 파라미터를 지원해요:
| 파라미터 | 타입 | 설명 | 기본값 | 예시 |
|---|---|---|---|---|
n |
integer | 생성할 이미지 수 (1-4) | 1 |
2 |
response_format |
string | 응답 형식 (url 또는 b64_json) |
"url" |
"b64_json" |
style |
string | 이미지 스타일/예술 방향 | - | "realistic_image" |
strength |
float | 이미지를 얼마나 변형할지 (0.0-1.0) | 0.2 |
0.5 |
비-OpenAI 파라미터 사용
OpenAI API의 일부가 아닌 Recraft 전용 파라미터를 요청에 포함할 수 있어요:
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
)
from openai import OpenAI
import os
client = OpenAI(
api_key="sk-", # 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)
지원되는 이미지 편집 모델
참고: 모든 recraft 모델을 LiteLLM이 지원해요. 모델 이름에 recraft/을 붙이면 litellm이 recraft로 라우팅해요.
| 모델명 | 함수 호출 |
|---|---|
| recraftv3 | image_edit(model="recraft/recraftv3", ...) |
API 키 설정
Recraft 웹사이트에서 API 키를 받아 환경 변수로 설정해요:
export RECRAFT_API_KEY="your-api-key"
더 알아보기 (Learn more)
- Recraft 공식 문서
- LiteLLM 이미지 생성 API