Was this page helpful?
Files API를 사용하면 Claude API에서 사용할 파일을 업로드하고 관리할 수 있으며, 각 요청마다 콘텐츠를 다시 업로드할 필요가 없습니다. 이는 코드 실행 도구를 사용하여 입력(예: 데이터 세트 및 문서)을 제공한 후 출력(예: 차트)을 다운로드할 때 특히 유용합니다. Files API를 사용하여 여러 API 호출에서 자주 사용되는 문서와 이미지를 계속 다시 업로드할 필요가 없도록 할 수도 있습니다. 이 가이드 외에도 API 참조를 직접 살펴볼 수 있습니다.
Files API는 베타 버전입니다. 피드백 양식을 통해 Files API 경험을 공유해 주세요.
This feature is not eligible for Zero Data Retention (ZDR). Data is retained according to the feature's standard retention policy.
Messages 요청에서 file_id를 참조하는 것은 주어진 파일 유형을 지원하는 모든 모델에서 지원됩니다. 예를 들어, 이미지는 모든 Claude 3+ 모델에서 지원되고, PDF는 모든 Claude 3.5+ 모델에서 지원되며, 다양한 다른 파일 유형은 Claude Haiku 4.5 및 모든 Claude 3.7+ 모델의 코드 실행 도구에서 지원됩니다.
Files API는 현재 Amazon Bedrock 또는 Google Vertex AI에서 지원되지 않습니다.
Files API는 파일 작업을 위한 간단한 한 번 업로드, 여러 번 사용 접근 방식을 제공합니다:
file_id 받기file_id를 사용하여 Messages 요청에서 파일 참조Files API를 사용하려면 베타 기능 헤더를 포함해야 합니다: anthropic-beta: files-api-2025-04-14.
향후 API 호출에서 참조할 파일을 업로드합니다:
파일 업로드의 응답에는 다음이 포함됩니다:
{
"id": "file_011CNha8iCJcU1wXNR6q4V8w",
"type": "file",
"filename": "document.pdf",
"mime_type": "application/pdf",
"size_bytes": 1024000,
"created_at": "2025-01-01T00:00:00Z",
"downloadable": false
}업로드한 후 file_id를 사용하여 파일을 참조합니다:
Files API는 다양한 콘텐츠 블록 유형에 해당하는 다양한 파일 유형을 지원합니다:
| 파일 유형 | MIME 유형 | 콘텐츠 블록 유형 | 사용 사례 |
|---|---|---|---|
application/pdf | document | 텍스트 분석, 문서 처리 | |
| 일반 텍스트 | text/plain | document | 텍스트 분석, 처리 |
| 이미지 | image/jpeg, image/png, image/gif, image/webp | image | 이미지 분석, 시각적 작업 |
| 데이터 세트, 기타 |
document 블록으로 지원되지 않는 파일 유형(.csv, .txt, .md, .docx, .xlsx)의 경우 파일을 일반 텍스트로 변환하고 콘텐츠를 메시지에 직접 포함합니다:
이미지가 포함된 .docx 파일의 경우 먼저 PDF 형식으로 변환한 후 PDF 지원을 사용하여 기본 제공 이미지 파싱을 활용합니다. 이를 통해 PDF 문서의 인용을 사용할 수 있습니다.
PDF 및 텍스트 파일의 경우 document 콘텐츠 블록을 사용합니다:
{
"type": "document",
"source": {
"type": "file",
"file_id": "file_011CNha8iCJcU1wXNR6q4V8w"
},
"title": "Document Title", // 선택 사항
"context": "Context about the document", // 선택 사항
"citations": { "enabled": true } // 선택 사항, 인용 활성화
}이미지의 경우 image 콘텐츠 블록을 사용합니다:
{
"type": "image",
"source": {
"type": "file",
"file_id": "file_011CPMxVD3fHLUhvTqtsQA5w"
}
}업로드된 파일 목록을 검색합니다:
특정 파일에 대한 정보를 검색합니다:
작업 공간에서 파일을 제거합니다:
스킬 또는 코드 실행 도구에서 생성된 파일을 다운로드합니다:
Messages API 호출 및 관련 도구 사용에서 계속 유지될 수 있습니다Files API를 통해 업로드된 파일은 DELETE /v1/files/{file_id} 엔드포인트를 사용하여 명시적으로 삭제할 때까지 보존됩니다. 파일은 여러 API 요청에서 재사용하기 위해 저장됩니다.
모든 기능에 걸친 ZDR 적격성은 API 및 데이터 보존을 참조하세요.
Files API를 사용할 때 일반적인 오류는 다음과 같습니다:
file_id가 존재하지 않거나 액세스 권한이 없습니다/v1/messages 요청에서 500 MB 일반 텍스트 파일 사용)<, >, :, ", |, ?, *, \, / 또는 유니코드 문자 0-31)를 포함합니다{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "File not found: file_011CNha8iCJcU1wXNR6q4V8w"
}
}Files API 작업은 무료입니다:
Messages 요청에서 사용된 파일 콘텐츠는 입력 토큰으로 청구됩니다. 스킬 또는 코드 실행 도구에서 생성된 파일만 다운로드할 수 있습니다.
베타 기간 동안:
uploaded = client.beta.files.upload(
file=("document.pdf", open("/path/to/document.pdf", "rb"), "application/pdf"),
)response = client.beta.messages.create(
model="claude-opus-4-6",
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "Please summarize this document for me."},
{
"type": "document",
"source": {
"type": "file",
"file_id": file_id,
},
},
],
}
],
betas=["files-api-2025-04-14"],
)
print(response)| 다양함 |
container_upload |
| 데이터 분석, 시각화 생성 |
import pandas as pd
# 예: CSV 파일 읽기
df = pd.read_csv("data.csv")
csv_content = df.to_string()
# 메시지에서 일반 텍스트로 전송
response = client.messages.create(
model="claude-opus-4-7",
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": f"Here's the CSV data:\n\n{csv_content}\n\nPlease analyze this data.",
}
],
}
],
)
print(response.content[0].text)client = anthropic.Anthropic()
files = client.beta.files.list()file = client.beta.files.retrieve_metadata(file_id)result = client.beta.files.delete(file_id)file_content = client.beta.files.download(file_id)
# Save to file
file_content.write_to_file("downloaded_file.txt")