您現在可以向 Claude 詢問您提供的 PDF 中的任何文字、圖片、圖表和表格。一些範例使用案例:
Claude 可處理任何標準 PDF。但是,使用 PDF 支援時,您應確保您的請求大小符合以下要求:
| 要求 | 限制 |
|---|---|
| 最大請求大小 | 32MB |
| 每次請求最大頁數 | 100 |
| 格式 | 標準 PDF(無密碼/加密) |
請注意,這兩個限制都是針對整個請求負載,包括與 PDF 一起發送的任何其他內容。
由於 PDF 支援依賴 Claude 的視覺功能,因此它受到與其他視覺任務相同的限制和注意事項。
PDF 支援目前透過直接 API 存取和 Google Vertex AI 提供。所有現行模型都支援 PDF 處理。
PDF 支援現已在 Amazon Bedrock 上提供,但有以下注意事項:
透過 Amazon Bedrock 的 Converse API 使用 PDF 支援時,有兩種不同的文件處理模式:
重要:要在 Converse API 中存取 Claude 的完整視覺 PDF 理解功能,您必須啟用引用。未啟用引用時,API 會退回到僅基本文字擷取。了解更多關於使用引用的資訊。
Converse 文件聊天(原始模式 - 僅文字擷取)
Claude PDF 聊天(新模式 - 完整視覺理解)
如果客戶反映使用 Converse API 時 Claude 無法看到 PDF 中的圖片或圖表,他們可能需要啟用引用標誌。沒有啟用引用時,Converse 會退回到僅基本文字擷取。
這是 Converse API 的已知限制,我們正在努力解決。對於需要不使用引用的視覺 PDF 分析的應用程式,請考慮改用 InvokeModel API。
對於非 PDF 檔案,如 .csv、.xlsx、.docx、.md 或 .txt 檔案,請參閱使用其他檔案格式。
讓我們從使用 Messages API 的簡單範例開始。您可以透過三種方式向 Claude 提供 PDF:
document 內容區塊中的 base64 編碼 PDFfile_id最簡單的方法是直接從 URL 參考 PDF:
curl https://api.anthropic.com/v1/messages \
-H "content-type: application/json" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-opus-4-6",
"max_tokens": 1024,
"messages": [{
"role": "user",
"content": [{
"type": "document",
"source": {
"type": "url",
"url": "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"
}
},
{
"type": "text",
"text": "What are the key findings in this document?"
}]
}]
}'如果您需要從本機系統發送 PDF 或 URL 不可用時:
# Method 1: Fetch and encode a remote PDF
curl -s "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf" | base64 | tr -d '\n' > pdf_base64.txt
# Method 2: Encode a local PDF file
# base64 document.pdf | tr -d '\n' > pdf_base64.txt
# Create a JSON request file using the pdf_base64.txt content
jq -n --rawfile PDF_BASE64 pdf_base64.txt '{
"model": "claude-opus-4-6",
"max_tokens": 1024,
"messages": [{
"role": "user",
"content": [{
"type": "document",
"source": {
"type": "base64",
"media_type": "application/pdf",
"data": $PDF_BASE64
}
},
{
"type": "text",
"text": "What are the key findings in this document?"
}]
}]
}' > request.json
# Send the API request using the JSON file
curl https://api.anthropic.com/v1/messages \
-H "content-type: application/json" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d @request.json對於您會重複使用的 PDF,或當您想避免編碼開銷時,請使用 Files API:
# First, upload your PDF to the Files API
curl -X POST https://api.anthropic.com/v1/files \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: files-api-2025-04-14" \
-F "[email protected]"
# Then use the returned file_id in your message
curl https://api.anthropic.com/v1/messages \
-H "content-type: application/json" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: files-api-2025-04-14" \
-d '{
"model": "claude-opus-4-6",
"max_tokens": 1024,
"messages": [{
"role": "user",
"content": [{
"type": "document",
"source": {
"type": "file",
"file_id": "file_abc123"
}
},
{
"type": "text",
"text": "What are the key findings in this document?"
}]
}]
}'當您向 Claude 發送 PDF 時,會發生以下步驟:
系統擷取文件的內容。
Claude 分析文字和圖片,以更好地理解文件。
Claude 回應,如相關則參考 PDF 的內容。
Claude 在回應時可以參考文字和視覺內容。您可以透過將 PDF 支援與以下功能整合來進一步提升效能:
PDF 檔案的 token 數量取決於從文件中擷取的總文字量以及頁數:
您可以使用 token 計算來估算您特定 PDF 的成本。
遵循以下最佳實踐以獲得最佳結果:
對於大量處理,請考慮以下方法:
快取 PDF 以提高重複查詢的效能:
# 使用 pdf_base64.txt 內容建立 JSON 請求檔案
jq -n --rawfile PDF_BASE64 pdf_base64.txt '{
"model": "claude-opus-4-6",
"max_tokens": 1024,
"messages": [{
"role": "user",
"content": [{
"type": "document",
"source": {
"type": "base64",
"media_type": "application/pdf",
"data": $PDF_BASE64
},
"cache_control": {
"type": "ephemeral"
}
},
{
"type": "text",
"text": "Which model has the highest human preference win rates across each use-case?"
}]
}]
}' > request.json
# 然後使用 JSON 檔案進行 API 呼叫
curl https://api.anthropic.com/v1/messages \
-H "content-type: application/json" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d @request.json使用 Message Batches API 進行大量工作流程:
# 使用 pdf_base64.txt 內容建立 JSON 請求檔案
jq -n --rawfile PDF_BASE64 pdf_base64.txt '
{
"requests": [
{
"custom_id": "my-first-request",
"params": {
"model": "claude-opus-4-6",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": [
{
"type": "document",
"source": {
"type": "base64",
"media_type": "application/pdf",
"data": $PDF_BASE64
}
},
{
"type": "text",
"text": "Which model has the highest human preference win rates across each use-case?"
}
]
}
]
}
},
{
"custom_id": "my-second-request",
"params": {
"model": "claude-opus-4-6",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": [
{
"type": "document",
"source": {
"type": "base64",
"media_type": "application/pdf",
"data": $PDF_BASE64
}
},
{
"type": "text",
"text": "Extract 5 key insights from this document."
}
]
}
]
}
}
]
}
' > request.json
# 然後使用 JSON 檔案進行 API 呼叫
curl https://api.anthropic.com/v1/messages/batches \
-H "content-type: application/json" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d @request.jsonWas this page helpful?