pdf-support changedbuild-with-claude/pdf-support
Nearest release: v2.1.328, published 7 hours after this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Recorded here
Lines+67added
Lines−58removed
From line
84
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits26to this page, all time
The whole hunk
from line 84, old and new numbered
/
from line 84
8484
8585### Send your first PDF request
8686
87Start with a simple example using the Messages API. You can provide PDFs to Claude in three ways:
87Start with an example that uses the Messages API. To give Claude a PDF, send it in a [`document` content block](https://platform.claude.com/docs/en/api/messages#document_block_param) with one of three kinds of source. Your platform determines which kinds you can use (see [Availability](https://platform.claude.com/docs/en/build-with-claude/pdf-support#feature-availability)). Among those kinds, choose by where the PDF is, how large it is, and how often you use it:
8888
891. As a URL reference to a PDF hosted online
902. As a base64-encoded PDF in `document` content blocks
913. By a `file_id` from the [Files API](https://platform.claude.com/docs/en/build-with-claude/files)
891. **A PDF hosted online:** Reference it by its URL ([Option 1: URL-based PDF document](https://platform.claude.com/docs/en/build-with-claude/pdf-support#option-1-url-based-pdf-document)).
902. **A PDF on your local system or without a URL:** Send it as base64-encoded data ([Option 2: Base64-encoded PDF document](https://platform.claude.com/docs/en/build-with-claude/pdf-support#option-2-base64-encoded-pdf-document)).
913. **A large PDF or one that you’ll use repeatedly:** Upload it with the [Files API](https://platform.claude.com/docs/en/build-with-claude/files) and reference it by its `file_id` ([Option 3: Files API](https://platform.claude.com/docs/en/build-with-claude/pdf-support#option-3-files-api)).
9292
93<Note>
94 On Claude Models on Google Cloud (Google managed) and Amazon Bedrock, only base64-encoded sources are available. On Microsoft Foundry, the Files API is not supported for deployments hosted on Azure.
95</Note>
96
9793#### Option 1: URL-based PDF document
9894
99The simplest approach is to reference a PDF directly from a URL:
95Reference the PDF by its URL:
10096
10197<CodeGroup>
10298 ```bash cURL
from line 193
197193 ```csharp C#
198194 var client = new AnthropicClient();
199195
200 // Create document block with URL
196 // Create a document block with a URL
201197 var documentParam = new DocumentBlockParam
202198 {
203199 Source = new UrlPdfSource
from line 248
252248 ```java Java
253249 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
254250
255 // Create document block with URL
251 // Create a document block with a URL
256252 DocumentBlockParam documentParam = DocumentBlockParam.builder()
257253 .source(
258254 UrlPdfSource.builder()
from line 276
280276 .build();
281277
282278 Message message = client.messages().create(params);
283 System.out.println(message.content());
279 IO.println(message.content());
284280 ```
285281
286282 ```php PHP
from line 302
306302 ],
307303 ],
308304 ],
309 model: 'claude-opus-5-5',
305 model: Model::CLAUDE_OPUS_5_5,
310306 );
311307
312308 echo $message;
from line 312
316312 anthropic = Anthropic::Client.new
317313
318314 message = anthropic.messages.create(
319 model: "claude-opus-5-5",
315 model: Anthropic::Model::CLAUDE_OPUS_5_5,
320316 max_tokens: 1024,
321317 messages: [
322318 {
from line 359
363359
364360#### Option 2: Base64-encoded PDF document
365361
366If you need to send PDFs from your local system or when a URL isn’t available:
362Send the PDF as base64-encoded data in the request itself. Most of the following examples download a sample PDF and encode it, so they need no local file. To send a local file in those examples, replace the lines that download and encode the PDF with the commented-out lines:
367363
368364<CodeGroup>
369365 ```bash cURL
from line 505
509505 // Method 2: Load from a local file
510506 // var pdfBase64 = Convert.ToBase64String(await File.ReadAllBytesAsync("document.pdf"));
511507
512 // Create document block with base64 data
508 // Create a document block with base64 data
513509 var documentParam = new DocumentBlockParam
514510 {
515511 Source = new Base64PdfSource { Data = pdfBase64 },
from line 546
550546 }
551547 pdfBase64 := base64.StdEncoding.EncodeToString(pdfBytes)
552548
553 // Alternative: Load from a local file (add "os" to the imports)
549 // Alternative: Load from a local file (in the imports, replace "io" and "net/http" with "os")
554550 // pdfBytes, err := os.ReadFile("document.pdf")
555551 // pdfBase64 := base64.StdEncoding.EncodeToString(pdfBytes)
556552
from line 595
599595 // byte[] fileBytes = Files.readAllBytes(Path.of("document.pdf"));
600596 // String pdfBase64 = Base64.getEncoder().encodeToString(fileBytes);
601597
602 // Create document block with base64 data
598 // Create a document block with base64 data
603599 DocumentBlockParam documentParam = DocumentBlockParam.builder()
604600 .source(Base64PdfSource.builder()
605601 .data(pdfBase64)
from line 619
623619 .build();
624620
625621 Message message = client.messages().create(params);
626 System.out.println(message.content());
622 IO.println(message.content());
627623 ```
628624
629625 ```php PHP
from line 627
631627
632628 // First, load and encode the PDF
633629 $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));
630 $pdf_bytes = file_get_contents($pdf_url)
631 ?: throw new \RuntimeException('Could not fetch the PDF.');
632 $pdf_data = base64_encode($pdf_bytes);
635633
636634 // Alternative: Load from a local file
637 // $pdf_data = base64_encode(file_get_contents('document.pdf'));
635 // $pdf_bytes = file_get_contents('document.pdf')
636 // ?: throw new \RuntimeException('Could not read document.pdf.');
637 // $pdf_data = base64_encode($pdf_bytes);
638638
639639 // Send to Claude using base64 encoding
640640 $message = $client->messages->create(
from line 647
647647 'type' => 'document',
648648 'source' => [
649649 'type' => 'base64',
650 'media_type' => 'application/pdf',
650 'mediaType' => 'application/pdf',
651651 'data' => $pdf_data,
652652 ],
653653 ],
from line 658
658658 ],
659659 ],
660660 ],
661 model: 'claude-opus-5-5',
661 model: Model::CLAUDE_OPUS_5_5,
662662 );
663663
664664 echo $message;
from line 669
669669
670670 # First, load and encode the PDF
671671 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 }
672 pdf_bytes = URI.open(pdf_url, "rb", &:read)
673673 pdf_data = [pdf_bytes].pack("m0") # Encode as base64 without newlines
674674
675675 # Alternative: Load from a local file
from line 933
933933 .build();
934934
935935 Message message = client.messages().create(params);
936 System.out.println(message.content());
936 IO.println(message.content());
937937 ```
938938
939939 ```php PHP
from line 942
942942 $client = new Client();
943943
944944 // Upload the PDF file
945 $document = fopen('/path/to/document.pdf', 'rb')
946 ?: throw new \RuntimeException('Could not open /path/to/document.pdf.');
947
945948 $file_upload = $client->files->upload(
946 file: FileParam::fromResource(fopen('/path/to/document.pdf', 'r'), contentType: 'application/pdf'),
949 file: FileParam::fromResource($document, contentType: 'application/pdf'),
947950 );
948951
949952 // Use the uploaded file in a message
from line 970
967970 ],
968971 ],
969972 ],
970 model: 'claude-opus-5-5',
973 model: Model::CLAUDE_OPUS_5_5,
971974 );
972975
973976 echo $message;
from line 980
977980 anthropic = Anthropic::Client.new
978981
979982 # Upload the PDF file
980 file_upload = File.open("/path/to/document.pdf", "rb") do |f|
983 file_upload = File.open("/path/to/document.pdf", "rb") do |pdf_file|
981984 anthropic.files.upload(
982 file: Anthropic::FilePart.new(f, filename: "document.pdf", content_type: "application/pdf")
985 file: Anthropic::FilePart.new(pdf_file, filename: "document.pdf", content_type: "application/pdf")
983986 )
984987 end
985988
from line 1015
10121015<Steps>
10131016 <Step title="The system extracts the contents of the document.">
10141017 * The system converts each page of the document into an image.
1015 * The text from each page is extracted and provided alongside each page’s image.
1018 * The system extracts the text from each page and provides it alongside that page’s image.
10161019 </Step>
10171020
10181021 <Step title="Claude analyzes both the text and images.">
1019 * Documents are provided as a combination of text and images for analysis.
1020 * This allows users to ask for insights on visual elements of a PDF, such as charts, diagrams, and other non-textual content.
1022 * Claude receives each document as a combination of text and images.
1023 * Because Claude receives an image of each page, you can ask for insights on visual elements of a PDF, such as charts, diagrams, and other non-textual content.
10211024 </Step>
10221025
1023 <Step title="Claude responds, referencing the PDF’s contents if relevant.">
1024 Claude can reference both textual and visual content when it responds. You can further improve performance by integrating PDF support with:
1025
1026 * [Use prompt caching](https://platform.claude.com/docs/en/build-with-claude/pdf-support#use-prompt-caching): To improve performance for repeated analysis.
1027 * [Process document batches](https://platform.claude.com/docs/en/build-with-claude/pdf-support#process-document-batches): To process documents at high volume.
1028 * [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.
1026 <Step title="Claude uses the PDF’s contents in its response if relevant.">
1027 Claude can draw on both textual and visual content in its response.
10291028 </Step>
10301029</Steps>
10311030
from line 1033
10341033The token count of a PDF file depends on the total text extracted from the document and the number of pages:
10351034
10361035* Text token costs: Each page typically uses 1,500–3,000 tokens depending on content density. Standard API pricing applies with no additional PDF fees.
1037* 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.
1036* Image token costs: Each page’s image uses at most 1,568 visual tokens on every model because the API fits page images within the Standard resolution tier’s limits. For how to count an image’s visual tokens, see [Resolution and token cost](https://platform.claude.com/docs/en/build-with-claude/vision#evaluate-image-size).
10381037
10391038You can use [token counting](https://platform.claude.com/docs/en/build-with-claude/token-counting) to estimate costs for your specific PDFs.
10401039
10411040## Optimize PDF processing
10421041
1042You can combine PDF support with other features:
1043
1044* [Use prompt caching](https://platform.claude.com/docs/en/build-with-claude/pdf-support#use-prompt-caching) to improve performance for repeated analysis.
1045* [Process document batches](https://platform.claude.com/docs/en/build-with-claude/pdf-support#process-document-batches) to handle documents at high volume.
1046* [Use tools](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview) to have Claude extract specific information from documents for use as tool inputs.
1047
10431048### Improve performance
10441049
10451050Follow these best practices for optimal results:
from line 1307
13021307 .build();
13031308
13041309 Message message = client.messages().create(params);
1305 System.out.println(message);
1310 IO.println(message);
13061311 ```
13071312
13081313 ```php PHP
from line 1315
13101315
13111316 // Load and encode the PDF
13121317 $pdf_url = 'https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf';
1313 $pdf_data = base64_encode(file_get_contents($pdf_url));
1318 $pdf_bytes = file_get_contents($pdf_url)
1319 ?: throw new \RuntimeException('Could not fetch the PDF.');
1320 $pdf_data = base64_encode($pdf_bytes);
13141321
13151322 $message = $client->messages->create(
13161323 maxTokens: 1024,
from line 1329
13221329 'type' => 'document',
13231330 'source' => [
13241331 'type' => 'base64',
1325 'media_type' => 'application/pdf',
1332 'mediaType' => 'application/pdf',
13261333 'data' => $pdf_data,
13271334 ],
1328 'cache_control' => ['type' => 'ephemeral'],
1335 'cacheControl' => ['type' => 'ephemeral'],
13291336 ],
13301337 [
13311338 'type' => 'text',
from line 1341
13341341 ],
13351342 ],
13361343 ],
1337 model: 'claude-opus-5-5',
1344 model: Model::CLAUDE_OPUS_5_5,
13381345 );
13391346
13401347 echo $message;
from line 1352
13451352
13461353 # Load and encode the PDF
13471354 pdf_url = "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"
1348 pdf_bytes = URI.open(pdf_url, "rb") { |f| f.read }
1355 pdf_bytes = URI.open(pdf_url, "rb", &:read)
13491356 pdf_data = [pdf_bytes].pack("m0") # Encode as base64 without newlines
13501357
13511358 anthropic = Anthropic::Client.new
from line 1829
18221829 .build();
18231830
18241831 MessageBatch batch = client.messages().batches().create(params);
1825 System.out.println(batch);
1832 IO.println(batch);
18261833 ```
18271834
18281835 ```php PHP
from line 1837
18301837
18311838 // Load and encode the PDF
18321839 $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));
1840 $pdf_bytes = file_get_contents($pdf_url)
1841 ?: throw new \RuntimeException('Could not fetch the PDF.');
1842 $pdf_data = base64_encode($pdf_bytes);
18341843
18351844 $batch = $client->messages->batches->create(
18361845 requests: [
18371846 [
1838 'custom_id' => 'my-first-request',
1847 'customID' => 'my-first-request',
18391848 'params' => [
1840 'model' => 'claude-opus-5-5',
1841 'max_tokens' => 1024,
1849 'model' => Model::CLAUDE_OPUS_5_5,
1850 'maxTokens' => 1024,
18421851 'messages' => [
18431852 [
18441853 'role' => 'user',
from line 1856
18471856 'type' => 'document',
18481857 'source' => [
18491858 'type' => 'base64',
1850 'media_type' => 'application/pdf',
1859 'mediaType' => 'application/pdf',
18511860 'data' => $pdf_data,
18521861 ],
18531862 ],
from line 1870
18611870 ],
18621871 ],
18631872 [
1864 'custom_id' => 'my-second-request',
1873 'customID' => 'my-second-request',
18651874 'params' => [
1866 'model' => 'claude-opus-5-5',
1867 'max_tokens' => 1024,
1875 'model' => Model::CLAUDE_OPUS_5_5,
1876 'maxTokens' => 1024,
18681877 'messages' => [
18691878 [
18701879 'role' => 'user',
from line 1882
18731882 'type' => 'document',
18741883 'source' => [
18751884 'type' => 'base64',
1876 'media_type' => 'application/pdf',
1885 'mediaType' => 'application/pdf',
18771886 'data' => $pdf_data,
18781887 ],
18791888 ],
from line 1906
18971906
18981907 # Load and encode the PDF
18991908 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 }
1909 pdf_bytes = URI.open(pdf_url, "rb", &:read)
19011910 pdf_data = [pdf_bytes].pack("m0") # Encode as base64 without newlines
19021911
19031912 anthropic = Anthropic::Client.new
from line 1978
19691978
19701979<CardGroup cols={2}>
19711980 <Card title="Vision" icon="image" href="https://platform.claude.com/docs/en/build-with-claude/vision">
1972 Claude’s vision capabilities allow it to process and analyze images, opening up exciting possibilities for multimodal interaction.
1981 Learn how to count an image’s visual tokens and which limitations PDFs share with other vision tasks.
19731982 </Card>
19741983
19751984 <Card title="Try PDF examples" icon="file" href="https://platform.claude.com/cookbook/multimodal-getting-started-with-vision">
No line in this hunk matches that.