본문으로 바로 가기
문서 · 이미지와 문서

이미지와 문서

이미지와 PDF를 보내는 방법

이미지

이미지를 읽는 모델에는 글과 함께 이미지를 보낼 수 있어요. https 주소나 data URL로 넣어 주세요. 어떤 모델이 읽는지는 모델별 지원에서 볼 수 있어요.

client.chat.completions.create(
    model="anthropic/claude-opus-5.5",
    messages=[{"role": "user", "content": [
        {"type": "text", "text": "이 사진에 뭐가 있나요?"},
        {"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}},
    ]}],
)
  • PNG, JPEG, GIF, WebP를 받아요. 한 장은 3.75MB까지, 한 번에 10장까지 보낼 수 있어요.
  • 이미지 한 장은 크기와 모델에 따라 100~5,300토큰쯤으로 계산돼요. 요금은 입력 토큰 가격 그대로예요.
  • https 주소는 저희가 한 번 가져와서 모델에 전해요. 로그인해야 보이는 주소는 data URL로 보내 주세요.
  • 이미지는 저장하지 않아요.

PDF 문서

PDF는 Claude 모델에 Messages API로 보낼 수 있어요. 파일을 base64로 바꿔 document 블록에 넣어요.

import anthropic, base64

client = anthropic.Anthropic(base_url="https://alprouter.alpsoft.io/api", api_key="alp-내-키")
pdf = base64.standard_b64encode(open("report.pdf", "rb").read()).decode()

message = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": [
        {"type": "document", "source": {"type": "base64", "media_type": "application/pdf", "data": pdf}},
        {"type": "text", "text": "이 문서를 세 줄로 요약해 주세요"},
    ]}],
)
  • 한 번에 문서 5개까지, 요청 전체는 20MB까지 보낼 수 있어요.
  • /chat/completions에서는 아직 PDF를 받지 않아요.