Azure AI 이미지 편집

Azure AI 이미지 편집

Azure AI는 Black Forest Labs의 FLUX 모델로 텍스트 설명에 따라 기존 이미지를 수정하는 강력한 이미지 편집 기능을 제공해요. LiteLLM을 쓰면 azure_ai/ 라우트로 이 기능을 표준 인터페이스에서 호출할 수 있어요.

출처: 문서

본문

개요 (Overview)

속성 설명
설명 Azure AI 이미지 편집은 FLUX 모델로 텍스트 프롬프트에 따라 기존 이미지를 수정해요
LiteLLM 라우트 azure_ai/
공급자 문서 Azure AI FLUX Models
지원 작업 /images/edits

설정 (Setup)

API Key & Base URL & API Version

Azure AI Studio에서 API 키와 엔드포인트를 가져와요.

# Set your Azure AI API credentials
import os

os.environ["AZURE_AI_API_KEY"] = "your-api-key-here"
os.environ["AZURE_AI_API_BASE"] = "your-azure-ai-endpoint"  # e.g., https://your-endpoint.eastus2.inference.ai.azure.com/
os.environ["AZURE_AI_API_VERSION"] = "2025-04-01-preview"  # Example API version

지원 모델 (Supported Models)

모델 이름 설명 이미지당 비용
azure_ai/FLUX.1-Kontext-pro 편집용 향상된 컨텍스트 이해를 제공하는 FLUX 1 Kontext Pro $0.04
azure_ai/flux.2-pro 편집당 최대 8개의 참조 이미지를 지원하는 FLUX 2 Pro $0.04
azure_ai/FLUX.2-flex 편집당 최대 10개의 참조 이미지, guidance/steps 조절 가능한 FLUX 2 Flex 메가픽셀당 $0.05 (1024x1024에서 $0.052)

FLUX 2 편집은 FLUX 2 생성과 동일한 모델별 Black Forest Labs 라우트(/providers/blackforestlabs/v1/flux-2-pro 또는 /providers/blackforestlabs/v1/flux-2-flex)로 가며, 참조 이미지는 multipart 폼 대신 JSON 본문에 base64로 전송돼요. 여러 참조 이미지와 동시에 비교 편집하려면 image에 파일 목록을 전달하면 돼요. 모델 이름은 대소문자를 구분하지 않으므로 azure_ai/flux.2-flex도 동작해요.

이미지 편집 (Image Editing)

기본 이미지 편집

import os
import base64
from pathlib import Path
import litellm

# Set your API credentials
os.environ["AZURE_AI_API_KEY"] = "your-api-key-here"
os.environ["AZURE_AI_API_BASE"] = "your-azure-ai-endpoint"
os.environ["AZURE_AI_API_VERSION"] = "2025-04-01-preview"

# Edit an image with a prompt
response = litellm.image_edit(
    model="azure_ai/FLUX.1-Kontext-pro",
    image=open("path/to/your/image.png", "rb"),
    prompt="Add a winter theme with snow and cold colors",
    api_base=os.environ["AZURE_AI_API_BASE"],
    api_key=os.environ["AZURE_AI_API_KEY"],
    api_version=os.environ["AZURE_AI_API_VERSION"],
)

img_base64 = response.data[0].get("b64_json")
img_bytes = base64.b64decode(img_base64)
path = Path("edited_image.png")
path.write_bytes(img_bytes)

비동기 이미지 편집

import os
import base64
from pathlib import Path
import litellm
import asyncio

# Set your API credentials
os.environ["AZURE_AI_API_KEY"] = "your-api-key-here"
os.environ["AZURE_AI_API_BASE"] = "your-azure-ai-endpoint"
os.environ["AZURE_AI_API_VERSION"] = "2025-04-01-preview"

async def edit_image():
    # Edit image asynchronously
    response = await litellm.aimage_edit(
        model="azure_ai/FLUX.1-Kontext-pro",
        image=open("path/to/your/image.png", "rb"),
        prompt="Make this image look like a watercolor painting",
        api_base=os.environ["AZURE_AI_API_BASE"],
        api_key=os.environ["AZURE_AI_API_KEY"],
        api_version=os.environ["AZURE_AI_API_VERSION"]
    )
    img_base64 = response.data[0].get("b64_json")
    img_bytes = base64.b64decode(img_base64)
    path = Path("async_edited_image.png")
    path.write_bytes(img_bytes)

# Run the async function
asyncio.run(edit_image())

고급 파라미터 이미지 편집

import os
import base64
from pathlib import Path
import litellm

# Set your API credentials
os.environ["AZURE_AI_API_KEY"] = "your-api-key-here"
os.environ["AZURE_AI_API_BASE"] = "your-azure-ai-endpoint"
os.environ["AZURE_AI_API_VERSION"] = "2025-04-01-preview"

# Edit image with additional parameters
response = litellm.image_edit(
    model="azure_ai/FLUX.1-Kontext-pro",
    image=open("path/to/your/image.png", "rb"),
    prompt="Add magical elements like floating crystals and mystical lighting",
    api_base=os.environ["AZURE_AI_API_BASE"],
    api_key=os.environ["AZURE_AI_API_KEY"],
    api_version=os.environ["AZURE_AI_API_VERSION"],
    n=1,
)

img_base64 = response.data[0].get("b64_json")
img_bytes = base64.b64decode(img_base64)
path = Path("advanced_edited_image.png")
path.write_bytes(img_bytes)

FLUX 2 Flex 다중 참조 이미지 편집

import os
import base64
from pathlib import Path
import litellm

os.environ["AZURE_AI_API_KEY"] = "your-api-key-here"
os.environ["AZURE_AI_API_BASE"] = "your-azure-ai-endpoint"  # e.g., https://your-resource.services.ai.azure.com

# FLUX 2 Flex accepts up to 10 reference images, FLUX 2 Pro up to 8
response = litellm.image_edit(
    model="azure_ai/FLUX.2-flex",
    image=[open("subject.png", "rb"), open("style.png", "rb")],
    prompt="Render the subject from the first image in the style of the second",
    api_base=os.environ["AZURE_AI_API_BASE"],
    api_key=os.environ["AZURE_AI_API_KEY"],
    api_version="preview",
    size="1024x1024",
    guidance=4.5,
    steps=32,
)

img_bytes = base64.b64decode(response.data[0].get("b64_json"))
Path("flux2_edited_image.png").write_bytes(img_bytes)

LiteLLM Proxy Server 사용법

1. config.yaml 설정

model_list:
  - model_name: azure-flux-kontext-edit
    litellm_params:
      model: azure_ai/FLUX.1-Kontext-pro
      api_key: os.environ/AZURE_AI_API_KEY
      api_base: os.environ/AZURE_AI_API_BASE
      api_version: os.environ/AZURE_AI_API_VERSION
      model_info:
        mode: image_edit

  - model_name: azure-flux-2-flex-edit
    litellm_params:
      model: azure_ai/FLUX.2-flex
      api_key: os.environ/AZURE_AI_API_KEY
      api_base: os.environ/AZURE_AI_API_BASE
      api_version: preview
      model_info:
        mode: image_edit

general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY

2. Proxy 서버 시작

litellm --config /path/to/config.yaml
# RUNNING on http://0.0.0.0:4000

3. OpenAI Python SDK로 요청하기

OpenAI SDK:

from openai import OpenAI

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

# Edit image with FLUX Kontext Pro
response = client.images.edit(
    model="azure-flux-kontext-edit",
    image=open("path/to/your/image.png", "rb"),
    prompt="Transform this image into a beautiful oil painting style",
)

img_base64 = response.data[0].b64_json
img_bytes = base64.b64decode(img_base64)
path = Path("proxy_edited_image.png")
path.write_bytes(img_bytes)

LiteLLM SDK:

import litellm

# Edit image through proxy
response = litellm.image_edit(
    model="litellm_proxy/azure-flux-kontext-edit",
    image=open("path/to/your/image.png", "rb"),
    prompt="Add a mystical forest background with magical creatures",
    api_base="http://localhost:4000",
    api_key="sk-<your-litellm-api-key>",
)

img_base64 = response.data[0].b64_json
img_bytes = base64.b64decode(img_base64)
path = Path("proxy_edited_image.png")
path.write_bytes(img_bytes)

cURL:

curl --location 'http://localhost:4000/v1/images/edits' \
  --header "Authorization: Bearer ***" \
  --form 'model="azure-flux-kontext-edit"' \
  --form 'prompt="Convert this image to a vintage sepia tone with old-fashioned effects"' \
  --form 'image=@"path/to/your/image.png"'

지원 파라미터 (Supported Parameters)

Azure AI 이미지 편집은 다음 OpenAI 호환 파라미터를 지원해요.

파라미터 타입 설명 기본값 예시
image file 편집할 이미지 파일 필수 File 객체 또는 바이너리 데이터
prompt string 원하는 변경 사항의 텍스트 설명 필수 "Add snow and winter elements"
model string 편집에 사용할 FLUX 모델 필수 "azure_ai/FLUX.1-Kontext-pro"
n integer 생성할 편집 이미지 수 (1개만 지정 가능) 1 1
api_base string Azure AI 엔드포인트 URL 필수 "https://your-endpoint.eastus2.inference.ai.azure.com/"
api_key string Azure AI API 키 필수 환경 변수 또는 직접 값
api_version string Azure AI용 API 버전 필수 "2025-04-01-preview"

FLUX 2 Pro와 FLUX 2 Flex 편집은 FLUX 2 생성과 동일한 파라미터를 받아요: size(또는 width/height), output_format, seed, safety_tolerance, aspect_ratio, 그리고 Flex의 경우 guidance, steps. OpenAI 전용 필드인 user, quality, background, moderation, output_compression은 받아서 버리므로 해당 값을 설정하는 OpenAI SDK 클라이언트도 계속 동작해요.

시작하기 (Getting Started)

  1. Azure AI Studio에서 계정 만들기
  2. Azure AI Studio 워크스페이스에 FLUX 모델 배포하기
  3. 배포 세부 정보에서 API 키와 엔드포인트 가져오기
  4. AZURE_AI_API_KEY, AZURE_AI_API_BASE, AZURE_AI_API_VERSION 환경 변수 설정하기
  5. 원본 이미지 준비하기
  6. litellm.image_edit()로 텍스트 지시에 따라 이미지 수정하기

더 알아보기 (Learn more)