提供したPDF内のテキスト、画像、チャート、表について、Claudeに質問できます。ユースケースの例は以下のとおりです。
Claudeは標準的なPDFであればどれでも処理できます。リクエストサイズが以下の要件を満たしていることを確認してください。
| 要件 | 制限 |
|---|---|
| 最大リクエストサイズ | 32 MB(プラットフォームによって異なります) |
| リクエストあたりの最大ページ数 | 600(リクエストのコンテキストウィンドウが100万トークン未満の場合は100) |
| フォーマット | 標準PDF(パスワード/暗号化なし) |
どちらの制限も、PDFと一緒に送信される他のコンテンツを含むリクエストペイロード全体に適用されます。大きなPDFの場合は、Files APIでアップロードし、file_idで参照することでリクエストペイロードを小さく保つことを検討してください。
PDFサポートはClaudeのビジョン機能に依存しているため、他のビジョンタスクと同じ制限事項と考慮事項が適用されます。
すべてのアクティブなモデルがPDF処理をサポートしています。Amazon BedrockのConverse APIを通じたPDFサポートについては、Amazon BedrockのPDFサポートを参照してください。
Claude on Amazon Bedrock(Opus 4.6以前)の一部であるConverse APIを通じてPDFサポートを使用する場合、2つの異なるドキュメント処理モードがあります。
Converse Document Chat(元のモード - テキスト抽出のみ)
Claude PDF Chat(新しいモード - 完全な視覚的理解)
Converse APIを使用しているときにClaudeがPDF内の画像やチャートを認識していない場合は、引用フラグを有効にする必要がある可能性があります。有効にしないと、Converseは基本的なテキスト抽出のみにフォールバックします。
Messages APIを使用した簡単な例から始めましょう。PDFをClaudeに提供する方法は3つあります。
documentコンテンツブロック内のbase64エンコードされたPDFとしてfile_idによって最も簡単なアプローチは、URLから直接PDFを参照することです。
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-opus-5",
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?"},
],
}
],
)
print(message.content)レスポンスは、Claudeの分析をcontent内のテキストブロックとして返し、トークン消費量をusageに含めます。
{
"id": "msg_01Hfp8YuFjQ55VgWbpdHDehB",
"type": "message",
"role": "assistant",
"model": "claude-opus-5",
"content": [
{
"type": "text",
"text": "This document is an addendum to the Claude 3 model card, reporting updated evaluation results. The key findings include..."
}
],
"stop_reason": "end_turn",
"usage": {
"input_tokens": 45000,
"output_tokens": 300
}
}ローカルシステムからPDFを送信する必要がある場合、またはURLが利用できない場合:
import base64
import httpx
# まず、PDFを読み込んでエンコードします
pdf_url = "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"
pdf_data = base64.standard_b64encode(
httpx.get(pdf_url, follow_redirects=True).content
).decode("utf-8")
# 別の方法:ローカルファイルから読み込む
# with open("document.pdf", "rb") as f:
# pdf_data = base64.standard_b64encode(f.read()).decode("utf-8")
# base64エンコーディングを使用してClaudeに送信します
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-opus-5",
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{
"type": "document",
"source": {
"type": "base64",
"media_type": "application/pdf",
"data": pdf_data,
},
},
{"type": "text", "text": "What are the key findings in this document?"},
],
}
],
)
print(message.content)繰り返し使用するPDFの場合、またはエンコードのオーバーヘッドを避けたい場合は、Files API(ベータ版)を使用します。
client = anthropic.Anthropic()
# PDFファイルをアップロードします
with open("/path/to/document.pdf", "rb") as f:
file_upload = client.beta.files.upload(file=("document.pdf", f, "application/pdf"))
# アップロードしたファイルをメッセージで使用します
message = client.beta.messages.create(
model="claude-opus-5",
max_tokens=1024,
betas=["files-api-2025-04-14"],
messages=[
{
"role": "user",
"content": [
{
"type": "document",
"source": {"type": "file", "file_id": file_upload.id},
},
{"type": "text", "text": "What are the key findings in this document?"},
],
}
],
)
print(message.content)PDFをClaudeに送信すると、以下のステップが実行されます。
システムがドキュメントの内容を抽出します。
Claudeはテキストと画像の両方を分析してドキュメントをより深く理解します。
Claudeは、関連する場合はPDFの内容を参照しながら応答します。
Claudeは応答時にテキストと視覚的コンテンツの両方を参照できます。PDFサポートを以下と統合することで、パフォーマンスをさらに向上させることができます。
PDFファイルのトークン数は、ドキュメントから抽出されたテキストの総量とページ数によって決まります。
トークンカウントを使用して、特定のPDFのコストを見積もることができます。
最適な結果を得るために、以下のベストプラクティスに従ってください。
大量処理の場合は、以下のアプローチを検討してください。
プロンプトキャッシングでPDFをキャッシュして、繰り返しクエリのパフォーマンスを向上させます。
import base64
import httpx
# まず、PDFを読み込んでエンコードします
pdf_url = "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"
pdf_data = base64.standard_b64encode(
httpx.get(pdf_url, follow_redirects=True).content
).decode("utf-8")
# キャッシュされたドキュメントを使用してメッセージを作成します
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-opus-5",
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{
"type": "document",
"source": {
"type": "base64",
"media_type": "application/pdf",
"data": pdf_data,
},
"cache_control": {"type": "ephemeral"},
},
{
"type": "text",
"text": "Which model has the highest human preference win rates across each use-case?",
},
],
}
],
)
print(message.content)Message Batches APIを使用して、1つのリクエストで多数のPDFを処理します。
import base64
import httpx
# まず、PDFを読み込んでエンコードします
pdf_url = "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"
pdf_data = base64.standard_b64encode(
httpx.get(pdf_url, follow_redirects=True).content
).decode("utf-8")
# ドキュメントを使用するリクエストのバッチを作成します
client = anthropic.Anthropic()
message_batch = client.messages.batches.create(
requests=[
{
"custom_id": "my-first-request",
"params": {
"model": "claude-opus-5",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": [
{
"type": "document",
"source": {
"type": "base64",
"media_type": "application/pdf",
"data": pdf_data,
},
},
{
"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-5",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": [
{
"type": "document",
"source": {
"type": "base64",
"media_type": "application/pdf",
"data": pdf_data,
},
},
{
"type": "text",
"text": "Extract 5 key insights from this document.",
},
],
}
],
},
},
]
)
print(message_batch)バッチは非同期で処理されます。進捗状況を確認し、処理終了後に結果を取得するには、バッチ処理を参照してください。
Claudeのビジョン機能により、画像を理解し分析できるようになり、マルチモーダルなインタラクションの魅力的な可能性が広がります。
Claude CookbookレシピでPDF処理の実践的な例を探索してください。
PDFサポートの完全なAPIドキュメントを参照してください。
| Supported platforms |
|
|---|
Was this page helpful?