/images/edits

/images/edits

LiteLLM은 OpenAI의 /images/edits API 엔드포인트에 대응하는 이미지 편집 기능을 제공해요. 단일 및 다중 이미지 편집을 모두 지원해요.

출처: 문서

본문

기능 지원 참고
비용 추적 모든 지원 모델에서 작동
로깅 모든 통합에서 작동
최종 사용자 추적
폴백 지원 모델 간 작동
로드밸런싱 지원 모델 간 작동
지원 작업 이미지 편집 생성 단일 및 다중 이미지 지원
지원 LiteLLM SDK 버전 1.63.8+ Gemini 지원은 1.79.3+ 필요
지원 LiteLLM Proxy 버전 1.71.1+ Gemini 지원은 1.79.3+ 필요
지원 LLM 프로바이더 OpenAI, Gemini (Google AI Studio), Vertex AI, OpenRouter, Stability AI, AWS Bedrock (Stability), Black Forest Labs, Azure AI (FLUX), Hosted vLLM (vLLM-Omni) Gemini는 새 gemini-2.5-flash-image 제품군 지원. Vertex AI는 Gemini·Imagen 모델 모두 지원. OpenRouter는 채팅 완성을 통해 이미지 편집을 라우팅. Stability AI·Bedrock Stability는 다양한 이미지 편집 작업 지원. Black Forest Labs는 FLUX Kontext 모델 지원. Hosted vLLM은 vLLM-Omni 서버의 OpenAI 호환 /v1/images/edits로 라우팅.

⚡️모든 지원 모델과 프로바이더는 models.litellm.ai에서 확인할 수 있어요

사용법 (Usage)

LiteLLM Python SDK

기본 이미지 편집 (Basic Image Edit) — OpenAI

import litellm

# Edit an image with a prompt
response = litellm.image_edit(
    model="gpt-image-1",
    image=open("original_image.png", "rb"),
    prompt="Add a red hat to the person in the image",
    n=1,
    size="1024x1024"
)

print(response)

다중 이미지 편집 (Multiple Images Edit) — OpenAI

import litellm

# Edit multiple images with a prompt
response = litellm.image_edit(
    model="gpt-image-1",
    image=[
        open("image1.png", "rb"),
        open("image2.png", "rb"),
        open("image3.png", "rb")
    ],
    prompt="Apply vintage filter to all images",
    n=1,
    size="1024x1024"
)

print(response)

마스크로 이미지 편집 (Image Edit with Mask) — OpenAI

import litellm

# Edit an image with a mask to specify the area to edit
response = litellm.image_edit(
    model="gpt-image-1",
    image=open("original_image.png", "rb"),
    mask=open("mask_image.png", "rb"),  # Transparent areas will be edited
    prompt="Replace the background with a beach scene",
    n=2,
    size="512x512",
    response_format="url"
)

print(response)

비동기 이미지 편집 (Async Image Edit) — OpenAI

import litellm
import asyncio

async def edit_image():
    response = await litellm.aimage_edit(
        model="gpt-image-1",
        image=open("original_image.png", "rb"),
        prompt="Make the image look like a painting",
        n=1,
        size="1024x1024",
        response_format="b64_json"
    )
    return response

# Run the async function
response = asyncio.run(edit_image())
print(response)

비동기 다중 이미지 편집 (Async Multiple Images Edit) — OpenAI

import litellm
import asyncio

async def edit_multiple_images():
    response = await litellm.aimage_edit(
        model="gpt-image-1",
        image=[
            open("portrait1.png", "rb"),
            open("portrait2.png", "rb")
        ],
        prompt="Add professional lighting to the portraits",
        n=1,
        size="1024x1024",
        response_format="url"
    )
    return response

# Run the async function
response = asyncio.run(edit_multiple_images())
print(response)

사용자 지정 파라미터로 이미지 편집 (Image Edit with Custom Parameters) — OpenAI

import litellm

# Edit image with additional parameters
response = litellm.image_edit(
    model="gpt-image-1",
    image=open("portrait.png", "rb"),
    prompt="Add sunglasses and a smile",
    n=3,
    size="1024x1024",
    response_format="url",
    user="user-123",
    timeout=60,
    extra_headers={"Custom-Header": "value"}
)

print(f"Generated {len(response.data)} image variations")
for i, image_data in enumerate(response.data):
    print(f"Image {i+1}: {image_data.url}")

기본 이미지 편집 (Basic Image Edit) — Gemini

import base64
import os
from litellm import image_edit

os.environ["GEMINI_API_KEY"] = "your-api-key"

response = image_edit(
    model="gemini/gemini-2.5-flash-image",
    image=open("original_image.png", "rb"),
    prompt="Add aurora borealis to the night sky",
    size="1792x1024",  # mapped to aspectRatio=16:9 for Gemini
)

edited_image_bytes = base64.b64decode(response.data[0].b64_json)
with open("edited_image.png", "wb") as f:
    f.write(edited_image_bytes)

다중 이미지 편집 (Multiple Images Edit) — Gemini

import base64
import os
from litellm import image_edit

os.environ["GEMINI_API_KEY"] = "your-api-key"

response = image_edit(
    model="gemini/gemini-2.5-flash-image",
    image=[
        open("scene.png", "rb"),
        open("style_reference.png", "rb"),
    ],
    prompt="Blend the reference style into the scene while keeping the subject sharp.",
)

for idx, image_obj in enumerate(response.data):
    with open(f"gemini_edit_{idx}.png", "wb") as f:
        f.write(base64.b64decode(image_obj.b64_json))

기본 이미지 편집 (Basic Image Edit) — Black Forest Labs

import os
import litellm

os.environ["BFL_API_KEY"] = "your-api-key"

response = litellm.image_edit(
    model="black_forest_labs/flux-kontext-pro",
    image=open("original_image.png", "rb"),
    prompt="Add a green leaf to the scene",
)

print(response.data[0].url)

마스크로 인페인팅 (Inpainting with Mask) — Black Forest Labs

import os
import litellm

os.environ["BFL_API_KEY"] = "your-api-key"

# Use flux-pro-1.0-fill for inpainting
response = litellm.image_edit(
    model="black_forest_labs/flux-pro-1.0-fill",
    image=open("original_image.png", "rb"),
    mask=open("mask_image.png", "rb"),
    prompt="Replace with a garden",
)

print(response.data[0].url)

아웃페인팅(확장) (Outpainting (Expand)) — Black Forest Labs

import os
import litellm

os.environ["BFL_API_KEY"] = "your-api-key"

# Use flux-pro-1.0-expand to extend image borders
response = litellm.image_edit(
    model="black_forest_labs/flux-pro-1.0-expand",
    image=open("original_image.png", "rb"),
    prompt="Continue the scene with mountains",
    top=256,
    bottom=256,
)

print(response.data[0].url)

기본 이미지 편집(Gemini) (Basic Image Edit (Gemini)) — Vertex AI

import os
import litellm

# Set Vertex AI credentials
os.environ["VERTEXAI_PROJECT"] = "your-gcp-project-id"
os.environ["VERTEXAI_LOCATION"] = "us-central1"
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/path/to/service-account.json"

response = litellm.image_edit(
    model="vertex_ai/gemini-2.5-flash-image",
    image=open("original_image.png", "rb"),
    prompt="Add neon lights in the background",
    size="1024x1024",
)

print(response)

Imagen으로 이미지 편집(마스크 지원) (Image Edit with Imagen (Supports Masks)) — Vertex AI

import os
import litellm

# Set Vertex AI credentials
os.environ["VERTEXAI_PROJECT"] = "your-gcp-project-id"
os.environ["VERTEXAI_LOCATION"] = "us-central1"
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/path/to/service-account.json"

# Imagen supports mask for inpainting
response = litellm.image_edit(
    model="vertex_ai/imagen-3.0-capability-001",
    image=open("original_image.png", "rb"),
    mask=open("mask_image.png", "rb"),  # Optional: for inpainting
    prompt="Turn this into watercolor style scenery",
    n=2,  # Number of variations
    size="1024x1024",
)

print(response)

기본 이미지 편집 (Basic Image Edit) — OpenRouter

import os
from litellm import image_edit

os.environ["OPENROUTER_API_KEY"] = "your-api-key"

response = image_edit(
    model="openrouter/google/gemini-2.5-flash-image",
    image=open("original_image.png", "rb"),
    prompt="Add aurora borealis to the night sky",
)

print(response)

다중 이미지 편집 (Multiple Images Edit) — OpenRouter

import os
from litellm import image_edit

os.environ["OPENROUTER_API_KEY"] = "your-api-key"

response = image_edit(
    model="openrouter/google/gemini-2.5-flash-image",
    image=[
        open("scene.png", "rb"),
        open("style_reference.png", "rb"),
    ],
    prompt="Blend the reference style into the scene",
    size="1536x1024",   # mapped to aspect_ratio 3:2
    quality="high",      # mapped to image_size 4K
)

print(response)

기본 이미지 편집 (Basic Image Edit) — Hosted vLLM

import os
from litellm import image_edit

os.environ["HOSTED_VLLM_API_BASE"] = "http://localhost:8091"

response = image_edit(
    model="hosted_vllm/Qwen/Qwen-Image-Edit-2511",
    image=open("original_image.png", "rb"),
    prompt="Add a red hat to the person in the image",
)

print(response)

OpenAI SDK와 함께하는 LiteLLM 프록시 (LiteLLM Proxy with OpenAI SDK)

먼저 litellm proxy config.yaml에 다음을 추가해 주세요:

OpenAI 프록시 구성:

model_list:
  - model_name: gpt-image-1
    litellm_params:
      model: gpt-image-1
      api_key: os.environ/OPENAI_API_KEY

LiteLLM 프록시 서버 시작:

litellm --config /path/to/config.yaml

# RUNNING on http://0.0.0.0:4000

프록시를 통한 기본 이미지 편집 (Basic Image Edit via Proxy) — OpenAI

from openai import OpenAI

# Initialize client with your proxy URL
client = OpenAI(
    base_url="http://localhost:4000",  # Your proxy URL
    api_key="your-api-key"             # Your proxy API key
)

# Edit an image
response = client.images.edit(
    model="gpt-image-1",
    image=open("original_image.png", "rb"),
    prompt="Add a red hat to the person in the image",
    n=1,
    size="1024x1024"
)

print(response)

cURL 예시 (cURL Example)

curl -X POST "http://localhost:4000/v1/images/edits" \
  -H "Authorization: Bearer ***" \
  -F "model=gpt-image-1" \
  -F "image=@original_image.png" \
  -F "mask=@mask_image.png" \
  -F "prompt=Add a beautiful sunset in the background" \
  -F "n=1" \
  -F "size=1024x1024" \
  -F "response_format=url"

cURL 다중 이미지 예시 (cURL Multiple Images Example)

curl -X POST "http://localhost:4000/v1/images/edits" \
  -H "Authorization: Bearer ***" \
  -F "model=gpt-image-1" \
  -F "[email protected]" \
  -F "[email protected]" \
  -F "[email protected]" \
  -F "prompt=Apply artistic filter to all images" \
  -F "n=1" \
  -F "size=1024x1024" \
  -F "response_format=url"

Gemini 프록시 구성 (Gemini Proxy Configuration)

  1. Gemini 이미지 편집 모델을 config.yaml에 추가:
model_list:
  - model_name: gemini-image-edit
    litellm_params:
      model: gemini/gemini-2.5-flash-image
      api_key: os.environ/GEMINI_API_KEY
  1. LiteLLM 프록시 서버 시작:
litellm --config /path/to/config.yaml
  1. 이미지 편집 요청(Gemini 응답은 base64 전용):
curl -X POST "http://0.0.0.0:4000/v1/images/edits" \
  -H "Authorization: Bearer <YOUR-...KEY>" \
  -F "model=gemini-image-edit" \
  -F "image=@original_image.png" \
  -F "prompt=Add a warm golden-hour glow to the scene" \
  -F "size=1024x1024"

Black Forest Labs 프록시 구성 (Black Forest Labs Proxy Configuration)

  1. Black Forest Labs 이미지 편집 모델을 config.yaml에 추가:
model_list:
  - model_name: bfl-kontext-pro
    litellm_params:
      model: black_forest_labs/flux-kontext-pro
      api_key: os.environ/BFL_API_KEY
    model_info:
      mode: image_edit
  1. LiteLLM 프록시 서버 시작:
litellm --config /path/to/config.yaml
  1. 이미지 편집 요청:
curl -X POST "http://0.0.0.0:4000/v1/images/edits" \
  -H "Authorization: Bearer <YOUR-...KEY>" \
  -F "model=bfl-kontext-pro" \
  -F "image=@original_image.png" \
  -F "prompt=Add a sunset in the background"

Vertex AI 프록시 구성 (Vertex AI Proxy Configuration)

  1. Vertex AI 이미지 편집 모델을 config.yaml에 추가:
model_list:
  - model_name: vertex-gemini-image-edit
    litellm_params:
      model: vertex_ai/gemini-2.5-flash-image
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: os.environ/VERTEXAI_LOCATION
      vertex_credentials: os.environ/GOOGLE_APPLICATION_CREDENTIALS

  - model_name: vertex-imagen-image-edit
    litellm_params:
      model: vertex_ai/imagen-3.0-capability-001
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: os.environ/VERTEXAI_LOCATION
      vertex_credentials: os.environ/GOOGLE_APPLICATION_CREDENTIALS
  1. LiteLLM 프록시 서버 시작:
litellm --config /path/to/config.yaml
  1. 이미지 편집 요청:
curl -X POST "http://0.0.0.0:4000/v1/images/edits" \
  -H "Authorization: Bearer <YOUR-...KEY>" \
  -F "model=vertex-gemini-image-edit" \
  -F "image=@original_image.png" \
  -F "prompt=Add neon lights in the background" \
  -F "size=1024x1024"
  1. 마스크가 있는 Imagen 이미지 편집:
curl -X POST "http://0.0.0.0:4000/v1/images/edits" \
  -H "Authorization: Bearer <YOUR-...KEY>" \
  -F "model=vertex-imagen-image-edit" \
  -F "image=@original_image.png" \
  -F "mask=@mask_image.png" \
  -F "prompt=Turn this into watercolor style scenery" \
  -F "n=2" \
  -F "size=1024x1024"

OpenRouter 프록시 구성 (OpenRouter Proxy Configuration)

  1. OpenRouter 이미지 편집 모델을 config.yaml에 추가:
model_list:
  - model_name: openrouter-image-edit
    litellm_params:
      model: openrouter/google/gemini-2.5-flash-image
      api_key: os.environ/OPENROUTER_API_KEY
  1. LiteLLM 프록시 서버 시작:
litellm --config /path/to/config.yaml
  1. 이미지 편집 요청:
curl -X POST "http://0.0.0.0:4000/v1/images/edits" \
  -H "Authorization: Bearer <YOUR-...KEY>" \
  -F "model=openrouter-image-edit" \
  -F "image=@original_image.png" \
  -F "prompt=Make the sky a vibrant purple sunset" \
  -F "size=1024x1024"

Hosted vLLM 프록시 구성 (Hosted vLLM Proxy Configuration)

  1. vLLM-Omni 이미지 편집 모델을 config.yaml에 추가:
model_list:
  - model_name: qwen-image-edit
    litellm_params:
      model: hosted_vllm/Qwen/Qwen-Image-Edit-2511
      api_base: http://localhost:8091
    model_info:
      mode: image_edit
  1. LiteLLM 프록시 서버 시작:
litellm --config /path/to/config.yaml
  1. 이미지 편집 요청:
curl -X POST "http://0.0.0.0:4000/v1/images/edits" \
  -H "Authorization: Bearer <YOUR-...KEY>" \
  -F "model=qwen-image-edit" \
  -F "image=@original_image.png" \
  -F "prompt=Add a red hat to the person in the image"

지원되는 이미지 편집 파라미터 (Supported Image Edit Parameters)

파라미터 타입 설명 필수
image FileTypes 편집할 이미지. 유효한 PNG 파일, 4MB 미만, 정사각형이어야 함.
prompt str 원하는 이미지 편집에 대한 텍스트 설명.
model str 이미지 편집에 사용할 모델 선택(기본값 dall-e-2)
mask str 완전히 투명한 영역이 원본 이미지의 편집 위치를 나타내는 추가 이미지. 유효한 PNG 파일, 4MB 미만, image와 같은 크기여야 함. 선택
n int 생성할 이미지 수. 1과 10 사이여야 함. 선택(기본값 1)
size str 생성된 이미지의 크기. 256x256, 512x512, 1024x1024 중 하나. 선택(기본값 1024x1024)
response_format str 생성된 이미지가 반환되는 형식. url 또는 b64_json 중 하나. 선택(기본값 url)
user str 최종 사용자를 나타내는 고유 식별자. 선택

응답 형식 (Response Format)

응답은 OpenAI Images API 형식을 따릅니다:

{
    "created": 1677649800,
    "data": [
        {
            "url": "https://example.com/edited_image_1.png"
        },
        {
            "url": "https://example.com/edited_image_2.png"
        }
    ]
}

b64_json 형식의 경우:

{
    "created": 1677649800,
    "data": [
        {
            "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."
        }
    ]
}

더 알아보기 (Learn more)