본문 바로가기
C.W.K.
Stream
Lesson 01 of 05 · published

Image 보내기 — URL vs base64

~22 min · vision, images, input

Level 0Tokenizer
0 XP0/54 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

vision 모델은 이미지를 URL 또는 base64 로 받아. Responses API 에서는 input_image type 을, Chat Completions 에서는 image_url 을 사용해. 같은 픽셀과 detail 설정이라면 전달 방식이 달라도 비용은 같아.

이미 공개된 곳에 있다면 URL

이미지가 S3, R2, CDN 같은 공개 host 에 있다면 URL 이 간단해. request body 가 작고 모델이 URL 에서 직접 가져올 수 있어.

로컬이나 private 이미지라면 base64

로컬 개발 파일, 외부에서 접근할 수 없는 이미지, 방금 생성한 이미지는 base64.b64encode 로 encoding 하고 data:image/jpeg;base64,... URI 로 보내. 별도 공개 host 와 인증을 준비하지 않아도 돼.

detail 수준을 함께 정해

detail: 'low' | 'high' | 'auto' 중에서 골라. low 는 85 token 고정, high 는 32×32 patch 수에 따라 수백~수천 token 을 쓸 수 있고, auto 는 모델이 결정해. 대략적인 이미지 이해에는 low, OCR 이나 빽빽한 chart 에는 high 가 알맞아.

Code

URL 로 image (Responses)·python
response = client.responses.create(
    model="gpt-4.1",
    input=[{
        "role": "user",
        "content": [
            {"type": "input_text", "text": "What is in this image?"},
            {
                "type": "input_image",
                "image_url": "https://example.com/photo.jpg",
                "detail": "high",  # "low", "high", "auto"
            },
        ],
    }],
)
Base64 로 image (Responses)·python
import base64

def encode_image(path: str) -> str:
    with open(path, "rb") as f:
        return base64.b64encode(f.read()).decode("utf-8")

b64 = encode_image("photo.jpg")

response = client.responses.create(
    model="gpt-4.1",
    input=[{
        "role": "user",
        "content": [
            {"type": "input_text", "text": "Describe this image in detail."},
            {"type": "input_image", "image_url": f"data:image/jpeg;base64,{b64}", "detail": "high"},
        ],
    }],
)
Image (Chat Completions shape)·python
completion = client.chat.completions.create(
    model="gpt-4o",
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": "What's in this image?"},
            {"type": "image_url", "image_url": {"url": "https://example.com/image.jpg", "detail": "auto"}},
        ],
    }],
)

External links

Exercise

같은 이미지를 URL 과 base64 로 각각 보내 token usage 가 같은지 확인해. 이어서 3MB 이미지를 detail=low 와 detail=high 로 보내 비용을 비교해.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.