Repository Public
1---2title: PDF support3url: https://platform.claude.com/docs/en/build-with-claude/pdf-support4description: "Process PDFs with Claude: extract text, analyze charts, and understand visual content from your documents."5---67## Compatibility8- [ZDR](https://platform.claude.com/docs/en/manage-claude/api-and-data-retention): eligible (excludes [Covered Models](https://platform.claude.com/docs/en/manage-claude/api-and-data-retention#model-specific-data-retention-requirements))9- Platforms: Claude API, Claude Platform on AWS, Amazon Bedrock, Google Cloud, Microsoft Foundry1011You can ask Claude about any text, pictures, charts, and tables in PDFs you provide. Some sample use cases:1213* Analyzing financial reports and understanding charts/tables14* Extracting key information from legal documents15* Assisting with document translation16* Converting document information into structured formats1718## Before you begin1920### Check PDF requirements2122Claude works with any standard PDF. Ensure your request size meets these requirements:2324| Requirement | Limit |25| ------------------------- | -------------------------------------------------------------------------------------------------- |26| Maximum request size | 32 MB ([varies by platform](https://platform.claude.com/docs/en/api/overview#request-size-limits)) |27| Maximum pages per request | 600 (100 when the request's context window is under 1M tokens) |28| Format | Standard PDF (no passwords/encryption) |2930Both limits are on the entire request payload, including any other content sent alongside PDFs. For large PDFs, consider uploading with the [Files API](https://platform.claude.com/docs/en/build-with-claude/files) and referencing by `file_id` to keep request payloads small.3132<Tip>33 Dense PDFs (many small-font pages, complex tables, or heavy graphics) can fill the context window before reaching the page limit. Requests with large PDFs can also fail before reaching the page limit, even when using the Files API. Try splitting the document into sections; for large files, because each page is processed as an image, downsampling embedded images can also help.34</Tip>3536Because PDF support relies on Claude's vision capabilities, it is subject to the same [limitations and considerations](https://platform.claude.com/docs/en/build-with-claude/vision#limitations) as other vision tasks.3738### Supported platforms and models3940All [active models](https://platform.claude.com/docs/en/models/overview) support PDF processing. For PDF support through Amazon Bedrock's Converse API, see [Amazon Bedrock PDF support](https://platform.claude.com/docs/en/build-with-claude/pdf-support#amazon-bedrock-pdf-support).4142### Amazon Bedrock PDF support4344When using PDF support through the Converse API, part of [Claude on Amazon Bedrock (Opus 4.6 and earlier)](https://platform.claude.com/docs/en/build-with-claude/claude-on-amazon-bedrock-legacy), there are two distinct document processing modes:4546<Note>47 **Important:** To access Claude's full visual PDF understanding capabilities in the Converse API, you must enable citations. Without citations enabled, the API falls back to basic text extraction only. Learn more about [working with citations](https://platform.claude.com/docs/en/build-with-claude/citations).48</Note>4950#### Document processing modes51521. **Converse Document Chat** (Original mode - Text extraction only)5354 * Provides basic text extraction from PDFs55 * Cannot analyze images, charts, or visual layouts within PDFs56 * Uses approximately 1,000 tokens for a 3-page PDF57 * Automatically used when citations are not enabled58592. **Claude PDF Chat** (New mode - Full visual understanding)6061 * Provides complete visual analysis of PDFs62 * Can understand and analyze charts, graphs, images, and visual layouts63 * Processes each page as both text and image for comprehensive understanding64 * Uses approximately 7,000 tokens for a 3-page PDF65 * **Requires citations to be enabled** in the Converse API6667#### Key limitations6869* **Converse API:** Visual PDF analysis requires citations to be enabled. There is currently no option to use visual analysis without citations (unlike the InvokeModel API).70* **InvokeModel API:** Provides full control over PDF processing without forced citations.7172#### Common issues7374If Claude isn't seeing images or charts in your PDFs when using the Converse API, you likely need to enable the citations flag. Without it, Converse falls back to basic text extraction only.7576<Note>77 This is a known constraint with the Converse API. For applications that require visual PDF analysis without citations, consider using the InvokeModel API instead.78</Note>7980<Note>81 Plain text files such as .txt, .csv, or .md can be used directly in document blocks: upload them to the Files API with MIME type `text/plain` and reference them by `file_id`. Binary formats such as .xlsx or .docx are not supported in document blocks and must be converted to text or PDF first. See [Working with other file formats](https://platform.claude.com/docs/en/build-with-claude/files#working-with-other-file-formats).82</Note>8384## Process PDFs with Claude8586### Send your first PDF request8788Start with a simple example using the Messages API. You can provide PDFs to Claude in three ways:89901. As a URL reference to a PDF hosted online912. As a base64-encoded PDF in `document` content blocks923. By a `file_id` from the [Files API](https://platform.claude.com/docs/en/build-with-claude/files)9394<Note>95 On Amazon Bedrock and Google Cloud, only base64-encoded sources are currently available. On Microsoft Foundry, the Files API is not supported for deployments hosted on Azure.96</Note>9798#### Option 1: URL-based PDF document99100The simplest approach is to reference a PDF directly from a URL:101102<CodeGroup>103 ```bash cURL104 curl https://api.anthropic.com/v1/messages \105 -H "content-type: application/json" \106 -H "x-api-key: $ANTHROPIC_API_KEY" \107 -H "anthropic-version: 2023-06-01" \108 -d '{109 "model": "claude-opus-5",110 "max_tokens": 1024,111 "messages": [{112 "role": "user",113 "content": [{114 "type": "document",115 "source": {116 "type": "url",117 "url": "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"118 }119 },120 {121 "type": "text",122 "text": "What are the key findings in this document?"123 }]124 }]125 }'126 ```127128 ```bash CLI129 ant messages create --transform content --format yaml <<'YAML'130 model: claude-opus-5131 max_tokens: 1024132 messages:133 - role: user134 content:135 - type: document136 source:137 type: url138 url: https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf139 - type: text140 text: What are the key findings in this document?141 YAML142 ```143144 ```python Python145 client = anthropic.Anthropic()146 message = client.messages.create(147 model="claude-opus-5",148 max_tokens=1024,149 messages=[150 {151 "role": "user",152 "content": [153 {154 "type": "document",155 "source": {156 "type": "url",157 "url": "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf",158 },159 },160 {"type": "text", "text": "What are the key findings in this document?"},161 ],162 }163 ],164 )165166 print(message.content)167 ```168169 ```typescript TypeScript170 const anthropic = new Anthropic();171172 const response = await anthropic.messages.create({173 model: "claude-opus-5",174 max_tokens: 1024,175 messages: [176 {177 role: "user",178 content: [179 {180 type: "document",181 source: {182 type: "url",183 url: "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"184 }185 },186 {187 type: "text",188 text: "What are the key findings in this document?"189 }190 ]191 }192 ]193 });194195 console.log(response);196 ```197198 ```csharp C#199 var client = new AnthropicClient();200201 // Create document block with URL202 var documentParam = new DocumentBlockParam203 {204 Source = new UrlPdfSource205 {206 Url = "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf",207 },208 };209210 // Create a message with document and text content blocks211 var message = await client.Messages.Create(new MessageCreateParams212 {213 Model = Model.ClaudeOpus5,214 MaxTokens = 1024,215 Messages =216 [217 new()218 {219 Role = Role.User,220 Content = new List<ContentBlockParam>221 {222 documentParam,223 new TextBlockParam("What are the key findings in this document?"),224 },225 },226 ],227 });228229 Console.WriteLine(string.Join("\n", message.Content));230 ```231232 ```go Go233 client := anthropic.NewClient()234235 message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{236 Model: anthropic.ModelClaudeOpus5,237 MaxTokens: 1024,238 Messages: []anthropic.MessageParam{239 anthropic.NewUserMessage(240 anthropic.NewDocumentBlock(anthropic.URLPDFSourceParam{241 URL: "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf",242 }),243 anthropic.NewTextBlock("What are the key findings in this document?"),244 ),245 },246 })247 if err != nil {248 panic(err)249 }250251 fmt.Printf("%+v\n", message.Content)252 ```253254 ```java Java255 AnthropicClient client = AnthropicOkHttpClient.fromEnv();256257 // Create document block with URL258 DocumentBlockParam documentParam = DocumentBlockParam.builder()259 .source(260 UrlPdfSource.builder()261 .url(262 "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"263 )264 .build()265 )266 .build();267268 // Create a message with document and text content blocks269 MessageCreateParams params = MessageCreateParams.builder()270 .model(Model.CLAUDE_OPUS_5)271 .maxTokens(1024)272 .addUserMessageOfBlockParams(273 List.of(274 ContentBlockParam.ofDocument(documentParam),275 ContentBlockParam.ofText(276 TextBlockParam.builder()277 .text("What are the key findings in this document?")278 .build()279 )280 )281 )282 .build();283284 Message message = client.messages().create(params);285 System.out.println(message.content());286 ```287288 ```php PHP289 $client = new Client();290291 $message = $client->messages->create(292 maxTokens: 1024,293 messages: [294 [295 'role' => 'user',296 'content' => [297 [298 'type' => 'document',299 'source' => [300 'type' => 'url',301 'url' => 'https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf',302 ],303 ],304 [305 'type' => 'text',306 'text' => 'What are the key findings in this document?',307 ],308 ],309 ],310 ],311 model: 'claude-opus-5',312 );313314 echo $message;315 ```316317 ```ruby Ruby318 anthropic = Anthropic::Client.new319320 message = anthropic.messages.create(321 model: "claude-opus-5",322 max_tokens: 1024,323 messages: [324 {325 role: "user",326 content: [327 {328 type: "document",329 source: {330 type: "url",331 url: "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"332 }333 },334 {type: "text", text: "What are the key findings in this document?"}335 ]336 }337 ]338 )339340 puts(message.content)341 ```342</CodeGroup>343344The response returns Claude's analysis as text blocks in `content`, with token consumption in `usage`:345346```json Output347{348 "id": "msg_01Hfp8YuFjQ55VgWbpdHDehB",349 "type": "message",350 "role": "assistant",351 "model": "claude-opus-5",352 "content": [353 {354 "type": "text",355 "text": "This document is an addendum to the Claude 3 model card, reporting updated evaluation results. The key findings include..."356 }357 ],358 "stop_reason": "end_turn",359 "usage": {360 "input_tokens": 45000,361 "output_tokens": 300362 }363}364```365366#### Option 2: Base64-encoded PDF document367368If you need to send PDFs from your local system or when a URL isn't available:369370<CodeGroup>371 ```bash cURL372 # Method 1: Fetch and encode a remote PDF373 curl -sL "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf" | base64 | tr -d '\n' > pdf_base64.txt374375 # Method 2: Encode a local PDF file376 # base64 document.pdf | tr -d '\n' > pdf_base64.txt377378 # Create a JSON request file using the pdf_base64.txt content379 jq -n --rawfile PDF_BASE64 pdf_base64.txt '{380 "model": "claude-opus-5",381 "max_tokens": 1024,382 "messages": [{383 "role": "user",384 "content": [{385 "type": "document",386 "source": {387 "type": "base64",388 "media_type": "application/pdf",389 "data": $PDF_BASE64390 }391 },392 {393 "type": "text",394 "text": "What are the key findings in this document?"395 }]396 }]397 }' > request.json398399 # Send the API request using the JSON file400 curl https://api.anthropic.com/v1/messages \401 -H "content-type: application/json" \402 -H "x-api-key: $ANTHROPIC_API_KEY" \403 -H "anthropic-version: 2023-06-01" \404 -d @request.json405 ```406407 ```bash CLI408 ant messages create \409 --model claude-opus-5 \410 --max-tokens 1024 \411 --transform content \412 --format yaml <<'YAML'413 messages:414 - role: user415 content:416 - type: document417 source:418 type: base64419 media_type: application/pdf420 data: "@./document.pdf"421 - type: text422 text: What are the key findings in this document?423 YAML424 ```425426 ```python Python427 import base64428 import httpx2429430 # First, load and encode the PDF431 pdf_url = "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"432 pdf_data = base64.standard_b64encode(433 httpx2.get(pdf_url, follow_redirects=True).content434 ).decode("utf-8")435436 # Alternative: Load from a local file437 # with open("document.pdf", "rb") as f:438 # pdf_data = base64.standard_b64encode(f.read()).decode("utf-8")439440 # Send to Claude using base64 encoding441 client = anthropic.Anthropic()442 message = client.messages.create(443 model="claude-opus-5",444 max_tokens=1024,445 messages=[446 {447 "role": "user",448 "content": [449 {450 "type": "document",451 "source": {452 "type": "base64",453 "media_type": "application/pdf",454 "data": pdf_data,455 },456 },457 {"type": "text", "text": "What are the key findings in this document?"},458 ],459 }460 ],461 )462463 print(message.content)464 ```465466 ```typescript TypeScript467 // Method 1: Fetch and encode a remote PDF468 const pdfURL =469 "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf";470 const pdfResponse = await fetch(pdfURL);471 const arrayBuffer = await pdfResponse.arrayBuffer();472 const pdfBase64 = Buffer.from(arrayBuffer).toString("base64");473474 // Method 2: Load from a local file475 // import { readFile } from "node:fs/promises";476 // const pdfBase64 = (await readFile('document.pdf')).toString('base64');477478 // Send the API request with base64-encoded PDF479 const anthropic = new Anthropic();480 const response = await anthropic.messages.create({481 model: "claude-opus-5",482 max_tokens: 1024,483 messages: [484 {485 role: "user",486 content: [487 {488 type: "document",489 source: {490 type: "base64",491 media_type: "application/pdf",492 data: pdfBase64493 }494 },495 {496 type: "text",497 text: "What are the key findings in this document?"498 }499 ]500 }501 ]502 });503504 console.log(response);505 ```506507 ```csharp C#508 var client = new AnthropicClient();509510 // Method 1: Download and encode a remote PDF511 var pdfUrl = "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf";512 using var httpClient = new HttpClient();513 var pdfBase64 = Convert.ToBase64String(await httpClient.GetByteArrayAsync(pdfUrl));514515 // Method 2: Load from a local file516 // var pdfBase64 = Convert.ToBase64String(await File.ReadAllBytesAsync("document.pdf"));517518 // Create document block with base64 data519 var documentParam = new DocumentBlockParam520 {521 Source = new Base64PdfSource { Data = pdfBase64 },522 };523524 // Create a message with document and text content blocks525 var message = await client.Messages.Create(new MessageCreateParams526 {527 Model = Model.ClaudeOpus5,528 MaxTokens = 1024,529 Messages =530 [531 new()532 {533 Role = Role.User,534 Content = new List<ContentBlockParam>535 {536 documentParam,537 new TextBlockParam("What are the key findings in this document?"),538 },539 },540 ],541 });542543 Console.WriteLine(string.Join("\n", message.Content));544 ```545546 ```go Go547 // First, load and encode the PDF548 pdfURL := "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"549 resp, err := http.Get(pdfURL)550 if err != nil {551 panic(err)552 }553 defer resp.Body.Close()554 pdfBytes, err := io.ReadAll(resp.Body)555 if err != nil {556 panic(err)557 }558 pdfBase64 := base64.StdEncoding.EncodeToString(pdfBytes)559560 // Alternative: Load from a local file (add "os" to the imports)561 // pdfBytes, err := os.ReadFile("document.pdf")562 // pdfBase64 := base64.StdEncoding.EncodeToString(pdfBytes)563564 // Send to Claude using base64 encoding565 client := anthropic.NewClient()566 message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{567 Model: anthropic.ModelClaudeOpus5,568 MaxTokens: 1024,569 Messages: []anthropic.MessageParam{570 anthropic.NewUserMessage(571 anthropic.NewDocumentBlock(anthropic.Base64PDFSourceParam{572 Data: pdfBase64,573 }),574 anthropic.NewTextBlock("What are the key findings in this document?"),575 ),576 },577 })578 if err != nil {579 panic(err)580 }581582 fmt.Printf("%+v\n", message.Content)583 ```584585 ```java Java586 AnthropicClient client = AnthropicOkHttpClient.fromEnv();587588 // Method 1: Download and encode a remote PDF589 String pdfUrl =590 "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf";591 HttpClient httpClient = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.NORMAL).build();592 HttpRequest request = HttpRequest.newBuilder().uri(URI.create(pdfUrl)).GET().build();593594 HttpResponse<byte[]> response = httpClient.send(595 request,596 HttpResponse.BodyHandlers.ofByteArray()597 );598 String pdfBase64 = Base64.getEncoder().encodeToString(response.body());599600 // Method 2: Load from a local file601 // byte[] fileBytes = Files.readAllBytes(Path.of("document.pdf"));602 // String pdfBase64 = Base64.getEncoder().encodeToString(fileBytes);603604 // Create document block with base64 data605 DocumentBlockParam documentParam = DocumentBlockParam.builder()606 .source(Base64PdfSource.builder().data(pdfBase64).build())607 .build();608609 // Create a message with document and text content blocks610 MessageCreateParams params = MessageCreateParams.builder()611 .model(Model.CLAUDE_OPUS_5)612 .maxTokens(1024)613 .addUserMessageOfBlockParams(614 List.of(615 ContentBlockParam.ofDocument(documentParam),616 ContentBlockParam.ofText(617 TextBlockParam.builder()618 .text("What are the key findings in this document?")619 .build()620 )621 )622 )623 .build();624625 Message message = client.messages().create(params);626 System.out.println(message.content());627 ```628629 ```php PHP630 $client = new Client();631632 // First, load and encode the PDF633 $pdf_url = 'https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf';634 $pdf_data = base64_encode(file_get_contents($pdf_url));635636 // Alternative: Load from a local file637 // $pdf_data = base64_encode(file_get_contents('document.pdf'));638639 // Send to Claude using base64 encoding640 $message = $client->messages->create(641 maxTokens: 1024,642 messages: [643 [644 'role' => 'user',645 'content' => [646 [647 'type' => 'document',648 'source' => [649 'type' => 'base64',650 'media_type' => 'application/pdf',651 'data' => $pdf_data,652 ],653 ],654 [655 'type' => 'text',656 'text' => 'What are the key findings in this document?',657 ],658 ],659 ],660 ],661 model: 'claude-opus-5',662 );663664 echo $message;665 ```666667 ```ruby Ruby668 require "open-uri"669670 # First, load and encode the PDF671 pdf_url = "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"672 pdf_bytes = URI.open(pdf_url, "rb") { |f| f.read }673 pdf_data = [pdf_bytes].pack("m0") # Base64-encode without newlines674675 # Alternative: Load from a local file676 # pdf_data = [File.binread("document.pdf")].pack("m0")677678 # Send to Claude using base64 encoding679 anthropic = Anthropic::Client.new680 message = anthropic.messages.create(681 model: "claude-opus-5",682 max_tokens: 1024,683 messages: [684 {685 role: "user",686 content: [687 {688 type: "document",689 source: {690 type: "base64",691 media_type: "application/pdf",692 data: pdf_data693 }694 },695 {type: "text", text: "What are the key findings in this document?"}696 ]697 }698 ]699 )700701 puts(message.content)702 ```703</CodeGroup>704705#### Option 3: Files API706707For PDFs you'll use repeatedly, or when you want to avoid encoding overhead, use the [Files API](https://platform.claude.com/docs/en/build-with-claude/files):708709<CodeGroup>710 ```bash cURL711 # First, upload your PDF to the Files API712 FILE_ID=$(curl -sS -X POST https://api.anthropic.com/v1/files \713 -H "x-api-key: $ANTHROPIC_API_KEY" \714 -H "anthropic-version: 2023-06-01" \715 -F "file=@document.pdf" | jq -r '.id')716717 # Then use the returned file_id in your message718 curl https://api.anthropic.com/v1/messages \719 -H "content-type: application/json" \720 -H "x-api-key: $ANTHROPIC_API_KEY" \721 -H "anthropic-version: 2023-06-01" \722 -d @- <<EOF723 {724 "model": "claude-opus-5",725 "max_tokens": 1024,726 "messages": [{727 "role": "user",728 "content": [{729 "type": "document",730 "source": {731 "type": "file",732 "file_id": "$FILE_ID"733 }734 },735 {736 "type": "text",737 "text": "What are the key findings in this document?"738 }]739 }]740 }741 EOF742 ```743744 ```bash CLI745 # First, upload your PDF to the Files API746 FILE_ID=$(ant files upload \747 --file ./document.pdf \748 --transform id \749 --raw-output)750751 # Then use the returned file_id in your message752 ant messages create \753 --transform content \754 --format yaml <<YAML755 model: claude-opus-5756 max_tokens: 1024757 messages:758 - role: user759 content:760 - type: document761 source:762 type: file763 file_id: $FILE_ID764 - type: text765 text: What are the key findings in this document?766 YAML767 ```768769 ```python Python770 client = anthropic.Anthropic()771772 # Upload the PDF file773 with open("/path/to/document.pdf", "rb") as f:774 file_upload = client.files.upload(file=("document.pdf", f, "application/pdf"))775776 # Use the uploaded file in a message777 message = client.messages.create(778 model="claude-opus-5",779 max_tokens=1024,780 messages=[781 {782 "role": "user",783 "content": [784 {785 "type": "document",786 "source": {"type": "file", "file_id": file_upload.id},787 },788 {"type": "text", "text": "What are the key findings in this document?"},789 ],790 }791 ],792 )793794 print(message.content)795 ```796797 ```typescript TypeScript798 import Anthropic, { toFile } from "@anthropic-ai/sdk";799 import fs from "node:fs";800801 const anthropic = new Anthropic();802803 // Upload the PDF file804 const fileUpload = await anthropic.files.upload({805 file: await toFile(fs.createReadStream("/path/to/document.pdf"), undefined, {806 type: "application/pdf"807 })808 });809810 // Use the uploaded file in a message811 const response = await anthropic.messages.create({812 model: "claude-opus-5",813 max_tokens: 1024,814 messages: [815 {816 role: "user",817 content: [818 {819 type: "document",820 source: {821 type: "file",822 file_id: fileUpload.id823 }824 },825 {826 type: "text",827 text: "What are the key findings in this document?"828 }829 ]830 }831 ]832 });833834 console.log(response);835 ```836837 ```csharp C#838 var client = new AnthropicClient();839840 // Upload the PDF file841 var fileUpload = await client.Files.Upload(new FileUploadParams842 {843 File = new BinaryContent844 {845 Stream = File.OpenRead("/path/to/document.pdf"),846 FileName = "document.pdf",847 ContentType = new("application/pdf"),848 },849 });850851 // Use the uploaded file in a message852 var message = await client.Messages.Create(new MessageCreateParams853 {854 Model = Model.ClaudeOpus5,855 MaxTokens = 1024,856 Messages =857 [858 new()859 {860 Role = Role.User,861 Content = new List<ContentBlockParam>862 {863 new DocumentBlockParam864 {865 Source = new FileDocumentSource { FileID = fileUpload.ID },866 },867 new TextBlockParam("What are the key findings in this document?"),868 },869 },870 ],871 });872873 Console.WriteLine(string.Join("\n", message.Content));874 ```875876 ```go Go877 client := anthropic.NewClient()878879 // Upload the PDF file880 pdfFile, err := os.Open("/path/to/document.pdf")881 if err != nil {882 panic(err)883 }884 defer pdfFile.Close()885886 fileUpload, err := client.Files.Upload(context.TODO(), anthropic.FileUploadParams{887 File: anthropic.File(pdfFile, "document.pdf", "application/pdf"),888 })889 if err != nil {890 panic(err)891 }892893 // Use the uploaded file in a message894 message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{895 Model: anthropic.ModelClaudeOpus5,896 MaxTokens: 1024,897 Messages: []anthropic.MessageParam{898 anthropic.NewUserMessage(899 anthropic.NewDocumentBlock(anthropic.FileDocumentSourceParam{900 FileID: fileUpload.ID,901 }),902 anthropic.NewTextBlock("What are the key findings in this document?"),903 ),904 },905 })906 if err != nil {907 panic(err)908 }909910 fmt.Printf("%+v\n", message.Content)911 ```912913 ```java Java914 AnthropicClient client = AnthropicOkHttpClient.fromEnv();915916 // Upload the PDF file917 FileMetadata file = client918 .files()919 .upload(FileUploadParams.builder().file(Path.of("/path/to/document.pdf")).build());920921 // Use the uploaded file in a message922 MessageCreateParams params = MessageCreateParams.builder()923 .model(Model.CLAUDE_OPUS_5)924 .maxTokens(1024)925 .addUserMessageOfBlockParams(926 List.of(927 ContentBlockParam.ofDocument(928 DocumentBlockParam.builder().fileSource(file.id()).build()929 ),930 ContentBlockParam.ofText(931 TextBlockParam.builder()932 .text("What are the key findings in this document?")933 .build()934 )935 )936 )937 .build();938939 Message message = client.messages().create(params);940 System.out.println(message.content());941 ```942943 ```php PHP944 use Anthropic\Core\FileParam;945946 $client = new Client();947948 // Upload the PDF file949 $file_upload = $client->files->upload(950 file: FileParam::fromResource(fopen('/path/to/document.pdf', 'r'), contentType: 'application/pdf'),951 );952953 // Use the uploaded file in a message954 $message = $client->messages->create(955 maxTokens: 1024,956 messages: [957 [958 'role' => 'user',959 'content' => [960 [961 'type' => 'document',962 'source' => [963 'type' => 'file',964 'fileID' => $file_upload->id,965 ],966 ],967 [968 'type' => 'text',969 'text' => 'What are the key findings in this document?',970 ],971 ],972 ],973 ],974 model: 'claude-opus-5',975 );976977 echo $message;978 ```979980 ```ruby Ruby981 anthropic = Anthropic::Client.new982983 # Upload the PDF file984 file_upload = File.open("/path/to/document.pdf", "rb") do |f|985 anthropic.files.upload(986 file: Anthropic::FilePart.new(f, filename: "document.pdf", content_type: "application/pdf")987 )988 end989990 # Use the uploaded file in a message991 message = anthropic.messages.create(992 model: "claude-opus-5",993 max_tokens: 1024,994 messages: [995 {996 role: "user",997 content: [998 {999 type: "document",1000 source: {type: "file", file_id: file_upload.id}1001 },1002 {type: "text", text: "What are the key findings in this document?"}1003 ]1004 }1005 ]1006 )10071008 puts(message.content)1009 ```1010</CodeGroup>10111012### How PDF support works10131014When you send a PDF to Claude, the following steps occur:10151016<Steps>1017 <Step title="The system extracts the contents of the document.">1018 * The system converts each page of the document into an image.1019 * The text from each page is extracted and provided alongside each page's image.1020 </Step>10211022 <Step title="Claude analyzes both the text and images to better understand the document.">1023 * Documents are provided as a combination of text and images for analysis.1024 * This allows users to ask for insights on visual elements of a PDF, such as charts, diagrams, and other non-textual content.1025 </Step>10261027 <Step title="Claude responds, referencing the PDF's contents if relevant.">1028 Claude can reference both textual and visual content when it responds. You can further improve performance by integrating PDF support with:10291030 * [Use prompt caching](https://platform.claude.com/docs/en/build-with-claude/pdf-support#use-prompt-caching): To improve performance for repeated analysis.1031 * [Process document batches](https://platform.claude.com/docs/en/build-with-claude/pdf-support#process-document-batches): For high-volume document processing.1032 * [Tool use](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview): To extract specific information from documents for use as tool inputs.1033 </Step>1034</Steps>10351036### Estimate your costs10371038The token count of a PDF file depends on the total text extracted from the document and the number of pages:10391040* Text token costs: Each page typically uses 1,500–3,000 tokens per page depending on content density. Standard API pricing applies with no additional PDF fees.1041* Image token costs: Because each page is converted into an image, the same [image-based cost calculations](https://platform.claude.com/docs/en/build-with-claude/vision#evaluate-image-size) are applied.10421043You can use [token counting](https://platform.claude.com/docs/en/build-with-claude/token-counting) to estimate costs for your specific PDFs.10441045## Optimize PDF processing10461047### Improve performance10481049Follow these best practices for optimal results:10501051* Place PDFs before text in your requests1052* Use standard fonts1053* Ensure text is clear and legible1054* Rotate pages to proper upright orientation1055* Use logical page numbers (from PDF viewer) in prompts1056* Split large PDFs into chunks when needed1057* Enable prompt caching for repeated analysis10581059### Scale your implementation10601061For high-volume processing, consider these approaches:10621063#### Use prompt caching10641065Cache PDFs with [prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) to improve performance on repeated queries:10661067<CodeGroup>1068 ```bash cURL1069 curl -sL "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf" | base64 | tr -d '\n' > pdf_base64.txt1070 # Create a JSON request file using the pdf_base64.txt content1071 jq -n --rawfile PDF_BASE64 pdf_base64.txt '{1072 "model": "claude-opus-5",1073 "max_tokens": 1024,1074 "messages": [{1075 "role": "user",1076 "content": [{1077 "type": "document",1078 "source": {1079 "type": "base64",1080 "media_type": "application/pdf",1081 "data": $PDF_BASE641082 },1083 "cache_control": {1084 "type": "ephemeral"1085 }1086 },1087 {1088 "type": "text",1089 "text": "Which model has the highest human preference win rates across each use-case?"1090 }]1091 }]1092 }' > request.json10931094 # Then make the API call using the JSON file1095 curl https://api.anthropic.com/v1/messages \1096 -H "content-type: application/json" \1097 -H "x-api-key: $ANTHROPIC_API_KEY" \1098 -H "anthropic-version: 2023-06-01" \1099 -d @request.json1100 ```11011102 ```bash CLI1103 ant messages create --transform content --format yaml <<'YAML'1104 model: claude-opus-51105 max_tokens: 10241106 messages:1107 - role: user1108 content:1109 - type: document1110 source:1111 type: base641112 media_type: application/pdf1113 data: "@./document.pdf"1114 cache_control:1115 type: ephemeral1116 - type: text1117 text: Which model has the highest human preference win rates across each use-case?1118 YAML1119 ```11201121 ```python Python1122 import base641123 import httpx211241125 # First, load and encode the PDF1126 pdf_url = "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"1127 pdf_data = base64.standard_b64encode(1128 httpx2.get(pdf_url, follow_redirects=True).content1129 ).decode("utf-8")11301131 # Create a message with the cached document1132 client = anthropic.Anthropic()1133 message = client.messages.create(1134 model="claude-opus-5",1135 max_tokens=1024,1136 messages=[1137 {1138 "role": "user",1139 "content": [1140 {1141 "type": "document",1142 "source": {1143 "type": "base64",1144 "media_type": "application/pdf",1145 "data": pdf_data,1146 },1147 "cache_control": {"type": "ephemeral"},1148 },1149 {1150 "type": "text",1151 "text": "Which model has the highest human preference win rates across each use-case?",1152 },1153 ],1154 }1155 ],1156 )11571158 print(message.content)1159 ```11601161 ```typescript TypeScript1162 // First, load and encode the PDF1163 const pdfURL =1164 "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf";1165 const pdfResponse = await fetch(pdfURL);1166 const arrayBuffer = await pdfResponse.arrayBuffer();1167 const pdfBase64 = Buffer.from(arrayBuffer).toString("base64");11681169 // Create a message with the cached document1170 const anthropic = new Anthropic();1171 const response = await anthropic.messages.create({1172 model: "claude-opus-5",1173 max_tokens: 1024,1174 messages: [1175 {1176 role: "user",1177 content: [1178 {1179 type: "document",1180 source: {1181 type: "base64",1182 media_type: "application/pdf",1183 data: pdfBase641184 },1185 cache_control: { type: "ephemeral" }1186 },1187 {1188 type: "text",1189 text: "Which model has the highest human preference win rates across each use-case?"1190 }1191 ]1192 }1193 ]1194 });11951196 console.log(response);1197 ```11981199 ```csharp C#1200 var client = new AnthropicClient();12011202 // Download and encode the PDF1203 var pdfUrl = "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf";1204 using var httpClient = new HttpClient();1205 var pdfBase64 = Convert.ToBase64String(await httpClient.GetByteArrayAsync(pdfUrl));12061207 var message = await client.Messages.Create(new MessageCreateParams1208 {1209 Model = Model.ClaudeOpus5,1210 MaxTokens = 1024,1211 Messages =1212 [1213 new()1214 {1215 Role = Role.User,1216 Content = new List<ContentBlockParam>1217 {1218 new DocumentBlockParam1219 {1220 Source = new Base64PdfSource { Data = pdfBase64 },1221 CacheControl = new CacheControlEphemeral(),1222 },1223 new TextBlockParam("Which model has the highest human preference win rates across each use-case?"),1224 },1225 },1226 ],1227 });12281229 Console.WriteLine(message);1230 ```12311232 ```go Go1233 // First, load and encode the PDF1234 pdfURL := "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"1235 resp, err := http.Get(pdfURL)1236 if err != nil {1237 panic(err)1238 }1239 defer resp.Body.Close()1240 pdfBytes, err := io.ReadAll(resp.Body)1241 if err != nil {1242 panic(err)1243 }1244 pdfBase64 := base64.StdEncoding.EncodeToString(pdfBytes)12451246 // Create a document block with cache control1247 client := anthropic.NewClient()1248 message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{1249 Model: anthropic.ModelClaudeOpus5,1250 MaxTokens: 1024,1251 Messages: []anthropic.MessageParam{1252 anthropic.NewUserMessage(1253 anthropic.ContentBlockParamUnion{1254 OfDocument: &anthropic.DocumentBlockParam{1255 Source: anthropic.DocumentBlockParamSourceUnion{1256 OfBase64: &anthropic.Base64PDFSourceParam{1257 Data: pdfBase64,1258 },1259 },1260 CacheControl: anthropic.NewCacheControlEphemeralParam(),1261 },1262 },1263 anthropic.NewTextBlock("Which model has the highest human preference win rates across each use-case?"),1264 ),1265 },1266 })1267 if err != nil {1268 panic(err)1269 }12701271 fmt.Printf("%+v\n", message.Content)1272 ```12731274 ```java Java1275 AnthropicClient client = AnthropicOkHttpClient.fromEnv();12761277 // Download and encode the PDF1278 String pdfUrl =1279 "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf";1280 HttpClient httpClient = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.NORMAL).build();1281 HttpRequest request = HttpRequest.newBuilder().uri(URI.create(pdfUrl)).GET().build();12821283 HttpResponse<byte[]> response = httpClient.send(1284 request,1285 HttpResponse.BodyHandlers.ofByteArray()1286 );1287 String pdfBase64 = Base64.getEncoder().encodeToString(response.body());12881289 MessageCreateParams params = MessageCreateParams.builder()1290 .model(Model.CLAUDE_OPUS_5)1291 .maxTokens(1024)1292 .addUserMessageOfBlockParams(1293 List.of(1294 ContentBlockParam.ofDocument(1295 DocumentBlockParam.builder()1296 .source(Base64PdfSource.builder().data(pdfBase64).build())1297 .cacheControl(CacheControlEphemeral.builder().build())1298 .build()1299 ),1300 ContentBlockParam.ofText(1301 TextBlockParam.builder()1302 .text(1303 "Which model has the highest human preference win rates across each use-case?"1304 )1305 .build()1306 )1307 )1308 )1309 .build();13101311 Message message = client.messages().create(params);1312 System.out.println(message);1313 ```13141315 ```php PHP1316 $client = new Client();13171318 // Load and encode the PDF1319 $pdf_url = 'https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf';1320 $pdf_data = base64_encode(file_get_contents($pdf_url));13211322 $message = $client->messages->create(1323 maxTokens: 1024,1324 messages: [1325 [1326 'role' => 'user',1327 'content' => [1328 [1329 'type' => 'document',1330 'source' => [1331 'type' => 'base64',1332 'media_type' => 'application/pdf',1333 'data' => $pdf_data,1334 ],1335 'cache_control' => ['type' => 'ephemeral'],1336 ],1337 [1338 'type' => 'text',1339 'text' => 'Which model has the highest human preference win rates across each use-case?',1340 ],1341 ],1342 ],1343 ],1344 model: 'claude-opus-5',1345 );13461347 echo $message;1348 ```13491350 ```ruby Ruby1351 require "open-uri"13521353 # Load and encode the PDF1354 pdf_url = "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"1355 pdf_bytes = URI.open(pdf_url, "rb") { |f| f.read }1356 pdf_data = [pdf_bytes].pack("m0") # Base64-encode without newlines13571358 anthropic = Anthropic::Client.new13591360 message = anthropic.messages.create(1361 model: "claude-opus-5",1362 max_tokens: 1024,1363 messages: [1364 {1365 role: "user",1366 content: [1367 {1368 type: "document",1369 source: {1370 type: "base64",1371 media_type: "application/pdf",1372 data: pdf_data1373 },1374 cache_control: {type: "ephemeral"}1375 },1376 {1377 type: "text",1378 text: "Which model has the highest human preference win rates across each use-case?"1379 }1380 ]1381 }1382 ]1383 )13841385 puts(message.content)1386 ```1387</CodeGroup>13881389#### Process document batches13901391Use the [Message Batches API](https://platform.claude.com/docs/en/build-with-claude/batch-processing) to process many PDFs in one request:13921393<CodeGroup>1394 ```bash cURL1395 curl -sL "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf" | base64 | tr -d '\n' > pdf_base64.txt1396 # Create a JSON request file using the pdf_base64.txt content1397 jq -n --rawfile PDF_BASE64 pdf_base64.txt '{1398 "requests": [1399 {1400 "custom_id": "my-first-request",1401 "params": {1402 "model": "claude-opus-5",1403 "max_tokens": 1024,1404 "messages": [{1405 "role": "user",1406 "content": [{1407 "type": "document",1408 "source": {1409 "type": "base64",1410 "media_type": "application/pdf",1411 "data": $PDF_BASE641412 }1413 },1414 {1415 "type": "text",1416 "text": "Which model has the highest human preference win rates across each use-case?"1417 }]1418 }]1419 }1420 },1421 {1422 "custom_id": "my-second-request",1423 "params": {1424 "model": "claude-opus-5",1425 "max_tokens": 1024,1426 "messages": [{1427 "role": "user",1428 "content": [{1429 "type": "document",1430 "source": {1431 "type": "base64",1432 "media_type": "application/pdf",1433 "data": $PDF_BASE641434 }1435 },1436 {1437 "type": "text",1438 "text": "Extract 5 key insights from this document."1439 }]1440 }]1441 }1442 }]1443 }' > request.json14441445 # Then make the API call using the JSON file1446 curl https://api.anthropic.com/v1/messages/batches \1447 -H "content-type: application/json" \1448 -H "x-api-key: $ANTHROPIC_API_KEY" \1449 -H "anthropic-version: 2023-06-01" \1450 -d @request.json1451 ```14521453 ```bash CLI1454 ant messages:batches create <<'YAML'1455 requests:1456 - custom_id: my-first-request1457 params:1458 model: claude-opus-51459 max_tokens: 10241460 messages:1461 - role: user1462 content:1463 - type: document1464 source:1465 type: base641466 media_type: application/pdf1467 data: "@./document.pdf"1468 - type: text1469 text: >-1470 Which model has the highest human preference win rates1471 across each use-case?1472 - custom_id: my-second-request1473 params:1474 model: claude-opus-51475 max_tokens: 10241476 messages:1477 - role: user1478 content:1479 - type: document1480 source:1481 type: base641482 media_type: application/pdf1483 data: "@./document.pdf"1484 - type: text1485 text: Extract 5 key insights from this document.1486 YAML1487 ```14881489 ```python Python1490 import base641491 import httpx214921493 # First, load and encode the PDF1494 pdf_url = "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"1495 pdf_data = base64.standard_b64encode(1496 httpx2.get(pdf_url, follow_redirects=True).content1497 ).decode("utf-8")14981499 # Create a batch of requests that use the document1500 client = anthropic.Anthropic()1501 message_batch = client.messages.batches.create(1502 requests=[1503 {1504 "custom_id": "my-first-request",1505 "params": {1506 "model": "claude-opus-5",1507 "max_tokens": 1024,1508 "messages": [1509 {1510 "role": "user",1511 "content": [1512 {1513 "type": "document",1514 "source": {1515 "type": "base64",1516 "media_type": "application/pdf",1517 "data": pdf_data,1518 },1519 },1520 {1521 "type": "text",1522 "text": "Which model has the highest human preference win rates across each use-case?",1523 },1524 ],1525 }1526 ],1527 },1528 },1529 {1530 "custom_id": "my-second-request",1531 "params": {1532 "model": "claude-opus-5",1533 "max_tokens": 1024,1534 "messages": [1535 {1536 "role": "user",1537 "content": [1538 {1539 "type": "document",1540 "source": {1541 "type": "base64",1542 "media_type": "application/pdf",1543 "data": pdf_data,1544 },1545 },1546 {1547 "type": "text",1548 "text": "Extract 5 key insights from this document.",1549 },1550 ],1551 }1552 ],1553 },1554 },1555 ]1556 )15571558 print(message_batch)1559 ```15601561 ```typescript TypeScript1562 // First, load and encode the PDF1563 const pdfURL =1564 "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf";1565 const pdfResponse = await fetch(pdfURL);1566 const arrayBuffer = await pdfResponse.arrayBuffer();1567 const pdfBase64 = Buffer.from(arrayBuffer).toString("base64");15681569 // Create a batch of requests that use the document1570 const anthropic = new Anthropic();1571 const response = await anthropic.messages.batches.create({1572 requests: [1573 {1574 custom_id: "my-first-request",1575 params: {1576 model: "claude-opus-5",1577 max_tokens: 1024,1578 messages: [1579 {1580 role: "user",1581 content: [1582 {1583 type: "document",1584 source: {1585 type: "base64",1586 media_type: "application/pdf",1587 data: pdfBase641588 }1589 },1590 {1591 type: "text",1592 text: "Which model has the highest human preference win rates across each use-case?"1593 }1594 ]1595 }1596 ]1597 }1598 },1599 {1600 custom_id: "my-second-request",1601 params: {1602 model: "claude-opus-5",1603 max_tokens: 1024,1604 messages: [1605 {1606 role: "user",1607 content: [1608 {1609 type: "document",1610 source: {1611 type: "base64",1612 media_type: "application/pdf",1613 data: pdfBase641614 }1615 },1616 {1617 type: "text",1618 text: "Extract 5 key insights from this document."1619 }1620 ]1621 }1622 ]1623 }1624 }1625 ]1626 });16271628 console.log(response);1629 ```16301631 ```csharp C#1632 var client = new AnthropicClient();16331634 // Download and encode the PDF1635 var pdfUrl = "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf";1636 using var httpClient = new HttpClient();1637 var pdfBase64 = Convert.ToBase64String(await httpClient.GetByteArrayAsync(pdfUrl));16381639 var batch = await client.Messages.Batches.Create(new BatchCreateParams1640 {1641 Requests =1642 [1643 new()1644 {1645 CustomID = "my-first-request",1646 Params = new()1647 {1648 Model = Model.ClaudeOpus5,1649 MaxTokens = 1024,1650 Messages =1651 [1652 new()1653 {1654 Role = Role.User,1655 Content = new List<ContentBlockParam>1656 {1657 new DocumentBlockParam1658 {1659 Source = new Base64PdfSource { Data = pdfBase64 },1660 },1661 new TextBlockParam("Which model has the highest human preference win rates across each use-case?"),1662 },1663 },1664 ],1665 },1666 },1667 new()1668 {1669 CustomID = "my-second-request",1670 Params = new()1671 {1672 Model = Model.ClaudeOpus5,1673 MaxTokens = 1024,1674 Messages =1675 [1676 new()1677 {1678 Role = Role.User,1679 Content = new List<ContentBlockParam>1680 {1681 new DocumentBlockParam1682 {1683 Source = new Base64PdfSource { Data = pdfBase64 },1684 },1685 new TextBlockParam("Extract 5 key insights from this document."),1686 },1687 },1688 ],1689 },1690 },1691 ],1692 });16931694 Console.WriteLine(batch);1695 ```16961697 ```go Go1698 // First, load and encode the PDF1699 pdfURL := "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"1700 resp, err := http.Get(pdfURL)1701 if err != nil {1702 panic(err)1703 }1704 defer resp.Body.Close()1705 pdfBytes, err := io.ReadAll(resp.Body)1706 if err != nil {1707 panic(err)1708 }1709 pdfBase64 := base64.StdEncoding.EncodeToString(pdfBytes)17101711 // Create a batch of requests that use the document1712 client := anthropic.NewClient()1713 batch, err := client.Messages.Batches.New(context.TODO(), anthropic.MessageBatchNewParams{1714 Requests: []anthropic.MessageBatchNewParamsRequest{1715 {1716 CustomID: "my-first-request",1717 Params: anthropic.MessageBatchNewParamsRequestParams{1718 Model: anthropic.ModelClaudeOpus5,1719 MaxTokens: 1024,1720 Messages: []anthropic.MessageParam{1721 anthropic.NewUserMessage(1722 anthropic.NewDocumentBlock(anthropic.Base64PDFSourceParam{1723 Data: pdfBase64,1724 }),1725 anthropic.NewTextBlock("Which model has the highest human preference win rates across each use-case?"),1726 ),1727 },1728 },1729 },1730 {1731 CustomID: "my-second-request",1732 Params: anthropic.MessageBatchNewParamsRequestParams{1733 Model: anthropic.ModelClaudeOpus5,1734 MaxTokens: 1024,1735 Messages: []anthropic.MessageParam{1736 anthropic.NewUserMessage(1737 anthropic.NewDocumentBlock(anthropic.Base64PDFSourceParam{1738 Data: pdfBase64,1739 }),1740 anthropic.NewTextBlock("Extract 5 key insights from this document."),1741 ),1742 },1743 },1744 },1745 },1746 })1747 if err != nil {1748 panic(err)1749 }17501751 fmt.Printf("%+v\n", batch)1752 ```17531754 ```java Java1755 AnthropicClient client = AnthropicOkHttpClient.fromEnv();17561757 // Download and encode the PDF1758 String pdfUrl =1759 "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf";1760 HttpClient httpClient = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.NORMAL).build();1761 HttpRequest request = HttpRequest.newBuilder().uri(URI.create(pdfUrl)).GET().build();17621763 HttpResponse<byte[]> response = httpClient.send(1764 request,1765 HttpResponse.BodyHandlers.ofByteArray()1766 );1767 String pdfBase64 = Base64.getEncoder().encodeToString(response.body());17681769 BatchCreateParams params = BatchCreateParams.builder()1770 .addRequest(1771 BatchCreateParams.Request.builder()1772 .customId("my-first-request")1773 .params(1774 BatchCreateParams.Request.Params.builder()1775 .model(Model.CLAUDE_OPUS_5)1776 .maxTokens(1024)1777 .addUserMessageOfBlockParams(1778 List.of(1779 ContentBlockParam.ofDocument(1780 DocumentBlockParam.builder()1781 .source(Base64PdfSource.builder().data(pdfBase64).build())1782 .build()1783 ),1784 ContentBlockParam.ofText(1785 TextBlockParam.builder()1786 .text(1787 "Which model has the highest human preference win rates across each use-case?"1788 )1789 .build()1790 )1791 )1792 )1793 .build()1794 )1795 .build()1796 )1797 .addRequest(1798 BatchCreateParams.Request.builder()1799 .customId("my-second-request")1800 .params(1801 BatchCreateParams.Request.Params.builder()1802 .model(Model.CLAUDE_OPUS_5)1803 .maxTokens(1024)1804 .addUserMessageOfBlockParams(1805 List.of(1806 ContentBlockParam.ofDocument(1807 DocumentBlockParam.builder()1808 .source(Base64PdfSource.builder().data(pdfBase64).build())1809 .build()1810 ),1811 ContentBlockParam.ofText(1812 TextBlockParam.builder()1813 .text("Extract 5 key insights from this document.")1814 .build()1815 )1816 )1817 )1818 .build()1819 )1820 .build()1821 )1822 .build();18231824 MessageBatch batch = client.messages().batches().create(params);1825 System.out.println(batch);1826 ```18271828 ```php PHP1829 $client = new Client();18301831 // Load and encode the PDF1832 $pdf_url = 'https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf';1833 $pdf_data = base64_encode(file_get_contents($pdf_url));18341835 $batch = $client->messages->batches->create(1836 requests: [1837 [1838 'custom_id' => 'my-first-request',1839 'params' => [1840 'model' => 'claude-opus-5',1841 'max_tokens' => 1024,1842 'messages' => [1843 [1844 'role' => 'user',1845 'content' => [1846 [1847 'type' => 'document',1848 'source' => [1849 'type' => 'base64',1850 'media_type' => 'application/pdf',1851 'data' => $pdf_data,1852 ],1853 ],1854 [1855 'type' => 'text',1856 'text' => 'Which model has the highest human preference win rates across each use-case?',1857 ],1858 ],1859 ],1860 ],1861 ],1862 ],1863 [1864 'custom_id' => 'my-second-request',1865 'params' => [1866 'model' => 'claude-opus-5',1867 'max_tokens' => 1024,1868 'messages' => [1869 [1870 'role' => 'user',1871 'content' => [1872 [1873 'type' => 'document',1874 'source' => [1875 'type' => 'base64',1876 'media_type' => 'application/pdf',1877 'data' => $pdf_data,1878 ],1879 ],1880 [1881 'type' => 'text',1882 'text' => 'Extract 5 key insights from this document.',1883 ],1884 ],1885 ],1886 ],1887 ],1888 ],1889 ],1890 );18911892 echo $batch;1893 ```18941895 ```ruby Ruby1896 require "open-uri"18971898 # Load and encode the PDF1899 pdf_url = "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"1900 pdf_bytes = URI.open(pdf_url, "rb") { |f| f.read }1901 pdf_data = [pdf_bytes].pack("m0") # Base64-encode without newlines19021903 anthropic = Anthropic::Client.new19041905 message_batch = anthropic.messages.batches.create(1906 requests: [1907 {1908 custom_id: "my-first-request",1909 params: {1910 model: "claude-opus-5",1911 max_tokens: 1024,1912 messages: [1913 {1914 role: "user",1915 content: [1916 {1917 type: "document",1918 source: {1919 type: "base64",1920 media_type: "application/pdf",1921 data: pdf_data1922 }1923 },1924 {1925 type: "text",1926 text: "Which model has the highest human preference win rates across each use-case?"1927 }1928 ]1929 }1930 ]1931 }1932 },1933 {1934 custom_id: "my-second-request",1935 params: {1936 model: "claude-opus-5",1937 max_tokens: 1024,1938 messages: [1939 {1940 role: "user",1941 content: [1942 {1943 type: "document",1944 source: {1945 type: "base64",1946 media_type: "application/pdf",1947 data: pdf_data1948 }1949 },1950 {1951 type: "text",1952 text: "Extract 5 key insights from this document."1953 }1954 ]1955 }1956 ]1957 }1958 }1959 ]1960 )19611962 puts(message_batch)1963 ```1964</CodeGroup>19651966Batches process asynchronously. To check progress and retrieve results once processing ends, see [Batch processing](https://platform.claude.com/docs/en/build-with-claude/batch-processing).19671968## Next steps19691970<CardGroup cols={2}>1971 <Card title="Vision" icon="image" href="https://platform.claude.com/docs/en/build-with-claude/vision">1972 Claude's vision capabilities allow it to understand and analyze images, opening up exciting possibilities for multimodal interaction.1973 </Card>19741975 <Card title="Try PDF examples" icon="file" href="https://platform.claude.com/cookbook/multimodal-getting-started-with-vision">1976 Explore practical examples of PDF processing in the Claude Cookbook recipe.1977 </Card>19781979 <Card title="View API reference" icon="code" href="https://platform.claude.com/docs/en/api/messages/create">1980 See complete API documentation for PDF support.1981 </Card>1982</CardGroup>1983