Vertex AI 이미지 생성

Vertex AI 이미지 생성 (Image Generation)

Vertex AI의 이미지 생성을 LiteLLM에서 사용하는 방법을 알아봐요. Gemini 이미지 모델(Nano Banana 🍌)과 Imagen 모델을 모두 지원해요.

출처: 문서

본문

Vertex AI는 두 가지 유형의 이미지 생성을 지원해요:

  • Gemini 이미지 생성 모델 (Nano Banana 🍌) - generateContent API를 사용하는 대화형 이미지 생성
  • Imagen 모델 - predict API를 사용하는 전통적인 이미지 생성
속성 내용
설명 Vertex AI 이미지 생성은 Gemini 이미지 생성 모델을 모두 지원
LiteLLM 라우트 vertex_ai/
공식 문서 Google Cloud Vertex AI Image Generation ↗
Gemini 이미지 생성 문서 Gemini Image Generation ↗

빠른 시작

Gemini 이미지 생성 모델

Gemini 이미지 생성 모델은 다음과 같은 대화형 이미지 생성을 지원해요:

  • 텍스트→이미지 생성
  • 이미지 편집 (텍스트 + 이미지 → 이미지)
  • 다중 턴 이미지 다듬기
  • 고해상도 텍스트 렌더링
  • 최대 4K 해상도 (Gemini 3 Pro)

Gemini 2.5 Flash Image:

import litellm

# Generate a single image
response = await litellm.aimage_generation(
    prompt="A nano banana dish in a fancy restaurant with a Gemini theme",
    model="vertex_ai/gemini-2.5-flash-image",
    vertex_ai_project="your-project-id",
    vertex_ai_location="us-central1",
    n=1,
    size="1024x1024",
)

print(response.data[0].b64_json)  # Gemini returns base64 images

Gemini 3 Pro Image Preview (4K 출력):

import litellm

# Generate high-resolution image
response = await litellm.aimage_generation(
    prompt="Da Vinci style anatomical sketch of a dissected Monarch butterfly",
    model="vertex_ai/gemini-3-pro-image-preview",
    vertex_ai_project="your-project-id",
    vertex_ai_location="us-central1",
    n=1,
    size="1024x1024",
    # Optional: specify image size for Gemini 3 Pro
    # imageSize="4K",  # Options: "1K", "2K", "4K"
)

print(response.data[0].b64_json)

Google 검색 근거 부여

Gemini 이미지 모델(예: gemini-3.1-flash-image-preview, gemini-3-pro-image-preview)은 /v1/images/generations에서 Google 검색을 지원해요. LiteLLM은 web_search_options 또는 OpenAI 스타일 web_search 도구를 기본 generateContent 요청의 Gemini googleSearch 도구로 매핑해요.

import litellm

response = await litellm.aimage_generation(
    prompt="Generate an image of the latest iPhone design",
    model="vertex_ai/gemini-3.1-flash-image-preview",
    vertex_ai_project="your-project-id",
    vertex_ai_location="us-central1",
    web_search_options={},
)

print(response.data[0].b64_json)

OpenAI 스타일 web_search 도구 사용:

import litellm

response = await litellm.aimage_generation(
    prompt="Generate an image of the latest iPhone design",
    model="vertex_ai/gemini-3.1-flash-image-preview",
    vertex_ai_project="your-project-id",
    vertex_ai_location="us-central1",
    tools=[{"type": "web_search"}],
)

LiteLLM Proxy(/v1/images/generations) 경유:

curl -X POST 'http://localhost:4000/v1/images/generations' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ***" \
-d '{
    "model": "gemini-3.1-flash-image-preview",
    "prompt": "Generate an image of the latest iPhone design",
    "web_search_options": {}
}'

imageConfig 전달 (Gemini 모델)

Gemini 이미지 생성 모델은 전체 ImageConfig 객체를 지원해요. 어떤 /v1/images/generations 요청이든 imageConfig로 전달하면 LiteLLM이 모든 필드를 동일하게 generationConfig.imageConfig로 전달해요.

필드 타입 설명
aspectRatio string "1:1", "16:9", "9:16", "4:3", "3:4", "4:5", "5:4", "2:3", "3:2", "21:9"
imageSize string "1K", "2K", "4K" (Gemini 3 Pro 이상 지원)
personGeneration string "DONT_ALLOW", "ALLOW_ADULT", "ALLOW_ALL"
imageOutputOptions object `{"mimeType": "image/jpeg"

Python SDK로 imageConfig 전달:

import litellm

response = await litellm.aimage_generation(
    model="vertex_ai/gemini-3.1-flash-image",
    prompt="A nano banana on a desk",
    vertex_ai_project="your-project-id",
    vertex_ai_location="us-central1",
    imageConfig={
        "aspectRatio": "16:9",
        "imageSize": "2K",
        "personGeneration": "DONT_ALLOW",
        "imageOutputOptions": {
            "mimeType": "image/jpeg",
            "compressionQuality": 85,
        },
    },
)

Proxy로 imageConfig 전달:

curl -X POST 'http://localhost:4000/v1/images/generations' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ***" \
-d '{
    "model": "gemini-3.1-flash-image",
    "prompt": "A nano banana on a desk",
    "imageConfig": {
        "aspectRatio": "16:9",
        "imageSize": "2K",
        "personGeneration": "DONT_ALLOW",
        "imageOutputOptions": {
            "mimeType": "image/jpeg",
            "compressionQuality": 85
        }
    }
}'

aspectRatioimageSize의 단축키로 플랫 파라미터도 사용할 수 있어요:

response = await litellm.aimage_generation(
    model="vertex_ai/gemini-3.1-flash-image",
    prompt="A nano banana on a desk",
    aspect_ratio="16:9",   # or aspectRatio="16:9"
    image_size="2K",       # or imageSize="2K"
    vertex_ai_project="your-project-id",
    vertex_ai_location="us-central1",
)

플랫 파라미터(aspect_ratio, image_size, aspectRatio, imageSize)는 둘 다 있을 때 imageConfig 안의 같은 키를 덮어써요.

Imagen 모델

import litellm

# Generate a single image
response = await litellm.aimage_generation(
    prompt="An olympic size swimming pool with crystal clear water and modern architecture",
    model="vertex_ai/imagen-4.0-generate-001",
    vertex_ai_project="your-project-id",
    vertex_ai_location="us-central1",
    n=1,
    size="1024x1024",
)

print(response.data[0].b64_json)  # Imagen also returns base64 images

LiteLLM Proxy

1. config.yaml 구성

model_list:
  - model_name: vertex-imagen
    litellm_params:
      model: vertex_ai/imagen-4.0-generate-001
      vertex_ai_project: "your-project-id"
      vertex_ai_location: "us-central1"
      vertex_ai_credentials: "path/to/service-account.json"  # Optional if using environment auth

2. LiteLLM Proxy Server 시작

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

# RUNNING on http://0.0.0.0:4000

3. OpenAI Python SDK로 요청

from openai import OpenAI

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

# Generate image
response = client.images.generate(
    model="vertex-imagen",
    prompt="An olympic size swimming pool with crystal clear water and modern architecture",
)

print(response.data[0].url)

지원 모델

Gemini 이미지 생성 모델

  • vertex_ai/gemini-2.5-flash-image - 빠르고 효율적인 이미지 생성 (1024px 해상도)
  • vertex_ai/gemini-3.1-flash-image-preview - Google 검색 근거 부여가 있는 빠른 이미지 생성
  • vertex_ai/gemini-3-pro-image-preview - 4K 출력, Google 검색 근거 부여, thinking 모드를 가진 고급 모델
  • vertex_ai/gemini-2.0-flash-preview-image - 프리뷰 모델
  • vertex_ai/gemini-2.5-flash-image-preview - 프리뷰 모델

Imagen 모델

  • vertex_ai/imagegeneration@006 - 레거시 Imagen 모델
  • vertex_ai/imagen-4.0-generate-001 - 최신 Imagen 모델
  • vertex_ai/imagen-3.0-generate-001 - Imagen 3.0 모델

: 모든 Vertex AI 이미지 생성 모델을 지원해요. litellm 요청을 보낼 때 model=vertex_ai/을 접두사로 붙이면 돼요.

완전하고 최신의 지원 모델 목록은 https://models.litellm.ai/ 을 방문해요.

더 알아보기 (Learn more)

  • Vertex AI 이미지 생성 문서
  • Gemini 이미지 생성 문서