C.W.K.
Stream
Lesson 02 of 06 · published

Vision: Claude한테 이미지 보내기

~14 min · vision, images, multimodal

Level 0Observer
0 XP0/64 lessons0/13 achievements
0/150 XP to next level150 XP to go0% complete

이미지 보내는 두 가지

이미지 입력은 image 타입 콘텐츠 블록으로. 블록이 base64 바이트(source: {type: 'base64', media_type: 'image/png', data: ...}) 또는 URL(source: {type: 'url', url: ...}) 운반. 로컬 파일엔 base64; 이미 CDN의 자산엔 URL.

이미지 토큰 비용

이미지가 dimension에서 derived된 대략 토큰 수로 청구. 큰 이미지가 더 비싸. Aggressively resize — 1024-wide 사진이 보통 OCR이나 객체 description에 충분; 4K는 낭비된 토큰. Anthropic docs가 변환 공식 발행.

Vision이 잘하는 것

강함 — chart·table OCR, diagram 해석, 장면 description, UI 스크린샷, 문서 레이아웃, 스크린샷 안 코드. 약함 — 정확 픽셀 좌표, 비슷한 아이템 다수 카운팅, fine-grained spatial reasoning. 강점 매치하게 프롬프트 frame.

원칙: 질문에 답하는 가장 작은 이미지 보내. Resize는 한 줄 비용 win.

Code

Base64로 로컬 PNG 보내기·python
import base64, pathlib

data = base64.standard_b64encode(pathlib.Path("chart.png").read_bytes()).decode()

resp = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "image", "source": {
                    "type": "base64",
                    "media_type": "image/png",
                    "data": data,
                }},
                {"type": "text", "text": "Read off the y-axis values for the bars."},
            ],
        }
    ],
)
보내기 전 resize·python
from PIL import Image
import io, base64

img = Image.open("photo.jpg")
img.thumbnail((1024, 1024))  # long side에 1024 bound
buf = io.BytesIO()
img.save(buf, format="JPEG", quality=85)
data = base64.standard_b64encode(buf.getvalue()).decode()
# 이제 `data`를 image source로 보내

External links

Exercise

프로젝트의 vision 기능 골라. Long side에 1024 bound된 resize 단계 추가. 10 샘플 입력에 대해 토큰 사용량과 답 quality 비교.
Hint
1024에서 quality 눈에 띄게 떨어지면 1536이나 2048로 — but 거의 더 높이 X. 대부분 작업 신경 안 써.

Progress

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

댓글 0

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

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