← All guides

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

Claude API batch_error invalid_request_error 해결: Batch API 요청 오류 · 재시도 비효과

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

Claude API batch_error invalid_request_error는 Batch API job 생성/조회/cancellation 시 형식 오류에 발생합니다. Batch API 요청 오류이며, 재시도하지 말고 요청 자체를 수정해야 합니다. 이 글은 5가지 흔한 원인과 Python/TypeScript 코드 예시를 다룹니다.

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


무엇을 의미하는가?

batch_error 에러 서브타입는 Batch API job 생성/조회/cancellation 시 형식 오류을 의미합니다. Anthropic API의 에러 응답 본문에는 error.type"invalid_request_error"로 명시되며, error.message에 구체적 사유가 옵니다.

응답 예시:

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

흔한 원인 5가지

  1. Batch당 10,000+ requests (한도 초과)
  2. 단일 batch 250MB 이상
  3. Custom_id 중복 (각 request 고유해야 함)
  4. 29일 만료된 batch_id 조회 시도

해결 코드 (Python)

# Validate batch before submission
def validate_batch(requests: list[dict]):
    if len(requests) > 10_000:
        raise ValueError(f"Batch too large: {len(requests)} > 10,000")
    custom_ids = set()
    for req in requests:
        if req.get("custom_id") in custom_ids:
            raise ValueError(f"Duplicate custom_id: {req['custom_id']}")
        custom_ids.add(req["custom_id"])
    total_size = sum(len(json.dumps(r)) for r in requests)
    if total_size > 250 * 1024 * 1024:
        raise ValueError(f"Batch too big: {total_size / 1e6:.1f}MB > 250MB")

해결 코드 (TypeScript)

function validateBatch(requests: any[]) {
  if (requests.length > 10_000) throw new Error(`Too many: ${requests.length}`);
  const ids = new Set<string>();
  for (const r of requests) {
    if (ids.has(r.custom_id)) throw new Error(`Duplicate: ${r.custom_id}`);
    ids.add(r.custom_id);
  }
  const size = requests.reduce((s, r) => s + JSON.stringify(r).length, 0);
  if (size > 250_000_000) throw new Error(`Too big: ${size}`);
}

재시도하지 마세요

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


비용 영향

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

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


관련 에러


자주 묻는 질문

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

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

batch_error와 다른 에러의 차이는?

batch_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