멀티모달 이해
이미지(URL 또는 인라인 Base64 데이터 URI), PDF 및 다중 이미지 시퀀스를 최첨단 비전 모델에 전달하여 OCR, 다이어그램 분석, UI 감사 및 구조화된 데이터 추출을 수행할 수 있습니다.
OpenAI 채팅 프로토콜을 통한 이미지 입력
content를 text와 image_url 파트의 배열로 전달합니다. 빠른 분류에는 "detail": "low", 고밀도 OCR이나 코드 스크린샷 분석에는 "detail": "high"를 사용하세요.
python
import base64, os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["VANIX_API_KEY"],
base_url="https://api.vanix.io/v1",
)
with open("invoice.png", "rb") as f:
b64 = base64.b64encode(f.read()).decode("utf-8")
resp = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "Extract vendor, invoice date, and total amount as JSON."},
{
"type": "image_url",
"image_url": {
"url": f"data:image/png;base64,{b64}",
"detail": "high",
},
},
],
}
],
)
print(resp.choices[0].message.content)bash
curl https://api.vanix.io/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $VANIX_API_KEY" \
-d '{
"model": "gpt-4o",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "Summarize the architecture diagram in 3 bullets."},
{"type": "image_url", "image_url": {"url": "https://example.com/diagram.png", "detail": "high"}}
]
}]
}'네이티브 Anthropic 및 Gemini 멀티모달
- Anthropic (
/v1/messages):{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": "..."}}및 네이티브{"type": "document", "source": {"type": "base64", "media_type": "application/pdf", "data": "..."}}블록을 지원합니다. - Gemini (
/v1beta/models/*):contents[].parts내에서inlineData(image/*,application/pdf,audio/*,video/*)를 지원합니다.
이미지 페이로드 제한
입력 토큰 비용과 업로드 지연 시간을 최소화하려면 고해상도 사진의 긴 변을 <= 2048px로 리사이즈하고 JPEG/WebP(quality 85) 형식을 사용하는 것을 권장합니다.