← All guides

Claude API file_upload_error (invalid_request_error): 원인과 해결법

Claude API file_upload_error invalid_request_error 해결: Files API 업로드 실패 · 재시도 비효과

Claude API file_upload_error (invalid_request_error): 원인과 해결법

Claude API file_upload_error invalid_request_error는 Files API에 파일 업로드 시 형식/크기/MIME-type 오류에 발생합니다. Files API 업로드 실패이며, 재시도하지 말고 요청 자체를 수정해야 합니다. 이 글은 5가지 흔한 원인과 Python/TypeScript 코드 예시를 다룹니다.

전반적인 Claude API 에러 처리 패턴은 Claude API Error Handling 가이드를 참고하세요.


무엇을 의미하는가?

file_upload_error 에러 서브타입는 Files API에 파일 업로드 시 형식/크기/MIME-type 오류을 의미합니다. Anthropic API의 에러 응답 본문에는 error.type"invalid_request_error"로 명시되며, error.message에 구체적 사유가 옵니다.

응답 예시:

{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "..."
  }
}

흔한 원인 5가지

  1. 파일이 32MB 초과 (Files API 한도)
  2. MIME type이 application/pdf, image/* 외
  3. Beta 헤더 누락 (anthropic-beta: files-api-2025-04-14)
  4. Files API 미사용 region (Bedrock 일부 region)

해결 코드 (Python)

# Use Files API for large attachments
import anthropic

client = anthropic.Anthropic(default_headers={
    "anthropic-beta": "files-api-2025-04-14"
})

with open("doc.pdf", "rb") as f:
    file = client.files.create(file=f)
print(f"File ID: {file.id}")  # use in messages.create

response = client.messages.create(
    model="claude-sonnet-4-5", max_tokens=1024,
    messages=[{
        "role": "user",
        "content": [
            {"type": "document", "source": {"type": "file", "file_id": file.id}},
            {"type": "text", "text": "Summarize"},
        ],
    }],
)

해결 코드 (TypeScript)

const file = await client.files.create({
  file: fs.createReadStream("doc.pdf"),
});
const response = await client.messages.create({
  model: "claude-sonnet-4-5",
  max_tokens: 1024,
  messages: [{
    role: "user",
    content: [
      { type: "document", source: { type: "file", file_id: file.id } },
      { type: "text", text: "Summarize" },
    ],
  }],
}, { headers: { "anthropic-beta": "files-api-2025-04-14" } });

재시도하지 마세요

이 에러는 클라이언트 측 문제라 재시도해도 같은 결과입니다. 위 원인을 확인하고 요청을 수정한 뒤 재발송하세요.


비용 영향

이 에러는 요청이 처리되지 않았으므로 비용이 청구되지 않습니다. 단, 잘못된 모델로 요청을 반복하다가 다른 에러가 발생할 수 있으니 모니터링이 필요합니다.

자세한 비용 절감 패턴은 Claude API Cost and Prompt Caching Break-Even 또는 무료 비용 계산기를 참고하세요.


관련 에러


자주 묻는 질문

file_upload_error 에러가 떴을 때 비용이 청구되나요?

처리되지 않은 요청이므로 청구되지 않습니다. 단, 무한 재시도 루프는 다른 에러로 비용을 발생시킬 수 있습니다.

file_upload_error와 다른 에러의 차이는?

file_upload_error는 클라이언트 측 문제로 요청 수정 없이는 재시도해도 같은 결과입니다. 5xx 에러 (500/529)는 일시적 서버 이슈라 재시도가 효과적입니다.

Bedrock/Vertex에서도 같은 에러 코드인가요?

네, Anthropic의 error.type 명명 규칙은 모든 deployment (Direct API, AWS Bedrock, GCP Vertex AI)에서 동일합니다. 다만 HTTP 상태 코드는 platform 별로 wrapping되어 다를 수 있습니다 (예: Bedrock은 에러 type을 다른 prefix로 변경).


다음 단계

에러 처리 패턴 30개 + Pydantic 검증 코드Claude API Cost Optimization 마스터클래스 ($59)에 retry 미들웨어, 비용 가드레일, 에러 알림 패턴 12편 포함.

Tools and references