Repository Public
1---2title: Citations3url: https://platform.claude.com/docs/en/build-with-claude/citations4description: Ground Claude's responses in your source documents. Citations return the exact passages that support each claim, so you can verify answers and surface sources to your users.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 Foundry1011Claude can provide detailed citations when answering questions about documents, helping you track and verify the sources behind each response.1213All [active models](https://platform.claude.com/docs/en/models/overview) support citations.1415<Tip>16 Share your feedback and suggestions about the citations feature using the [citations feedback form](https://forms.gle/9n9hSrKnKe3rpowH9).17</Tip>1819The following example shows how to enable citations on a plain text document with the Messages API:2021<CodeGroup>22 ```bash cURL23 curl https://api.anthropic.com/v1/messages \24 -H "content-type: application/json" \25 -H "x-api-key: $ANTHROPIC_API_KEY" \26 -H "anthropic-version: 2023-06-01" \27 -d '{28 "model": "claude-opus-5",29 "max_tokens": 1024,30 "messages": [31 {32 "role": "user",33 "content": [34 {35 "type": "document",36 "source": {37 "type": "text",38 "media_type": "text/plain",39 "data": "The grass is green. The sky is blue."40 },41 "title": "My Document",42 "context": "This is a trustworthy document.",43 "citations": {"enabled": true}44 },45 {46 "type": "text",47 "text": "What color is the grass and sky?"48 }49 ]50 }51 ]52 }'53 ```5455 ```bash CLI56 ant messages create <<'YAML'57 model: claude-opus-558 max_tokens: 102459 messages:60 - role: user61 content:62 - type: document63 source:64 type: text65 media_type: text/plain66 data: The grass is green. The sky is blue.67 title: My Document68 context: This is a trustworthy document.69 citations:70 enabled: true71 - type: text72 text: What color is the grass and sky?73 YAML74 ```7576 ```python Python77 client = anthropic.Anthropic()7879 response = client.messages.create(80 model="claude-opus-5",81 max_tokens=1024,82 messages=[83 {84 "role": "user",85 "content": [86 {87 "type": "document",88 "source": {89 "type": "text",90 "media_type": "text/plain",91 "data": "The grass is green. The sky is blue.",92 },93 "title": "My Document",94 "context": "This is a trustworthy document.",95 "citations": {"enabled": True},96 },97 {"type": "text", "text": "What color is the grass and sky?"},98 ],99 }100 ],101 )102 print(response)103 ```104105 ```typescript TypeScript106 const client = new Anthropic();107108 const response = await client.messages.create({109 model: "claude-opus-5",110 max_tokens: 1024,111 messages: [112 {113 role: "user",114 content: [115 {116 type: "document",117 source: {118 type: "text",119 media_type: "text/plain",120 data: "The grass is green. The sky is blue."121 },122 title: "My Document",123 context: "This is a trustworthy document.",124 citations: { enabled: true }125 },126 {127 type: "text",128 text: "What color is the grass and sky?"129 }130 ]131 }132 ]133 });134 console.log(response);135 ```136137 ```csharp C#138 var client = new AnthropicClient();139140 var response = await client.Messages.Create(141 new()142 {143 Model = Model.ClaudeOpus5,144 MaxTokens = 1024,145 Messages =146 [147 new()148 {149 Role = Role.User,150 Content = new MessageParamContent(new List<ContentBlockParam>151 {152 new ContentBlockParam(new DocumentBlockParam(153 new DocumentBlockParamSource(new PlainTextSource()154 {155 Data = "The grass is green. The sky is blue.",156 })157 )158 {159 Title = "My Document",160 Context = "This is a trustworthy document.",161 Citations = new CitationsConfigParam { Enabled = true },162 }),163 new ContentBlockParam(new TextBlockParam("What color is the grass and sky?")),164 }),165 },166 ],167 }168 );169170 Console.WriteLine(response);171 ```172173 ```go Go174 client := anthropic.NewClient()175176 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{177 Model: anthropic.ModelClaudeOpus5,178 MaxTokens: 1024,179 Messages: []anthropic.MessageParam{180 anthropic.NewUserMessage(181 anthropic.ContentBlockParamUnion{182 OfDocument: &anthropic.DocumentBlockParam{183 Source: anthropic.DocumentBlockParamSourceUnion{184 OfText: &anthropic.PlainTextSourceParam{185 Data: "The grass is green. The sky is blue.",186 },187 },188 Title: anthropic.String("My Document"),189 Context: anthropic.String("This is a trustworthy document."),190 Citations: anthropic.CitationsConfigParam{Enabled: anthropic.Bool(true)},191 },192 },193 anthropic.NewTextBlock("What color is the grass and sky?"),194 ),195 },196 })197 if err != nil {198 log.Fatal(err)199 }200 fmt.Println(response)201 ```202203 ```java Java204 AnthropicClient client = AnthropicOkHttpClient.fromEnv();205206 PlainTextSource source = PlainTextSource.builder()207 .data("The grass is green. The sky is blue.")208 .build();209210 DocumentBlockParam documentParam = DocumentBlockParam.builder()211 .source(source)212 .title("My Document")213 .context("This is a trustworthy document.")214 .citations(CitationsConfigParam.builder().enabled(true).build())215 .build();216217 TextBlockParam textBlockParam = TextBlockParam.builder()218 .text("What color is the grass and sky?")219 .build();220221 MessageCreateParams params = MessageCreateParams.builder()222 .model(Model.CLAUDE_OPUS_5)223 .maxTokens(1024)224 .addUserMessageOfBlockParams(225 List.of(226 ContentBlockParam.ofDocument(documentParam),227 ContentBlockParam.ofText(textBlockParam)228 )229 )230 .build();231232 Message message = client.messages().create(params);233 System.out.println(message);234 ```235236 ```php PHP237 $client = new Client();238239 $response = $client->messages->create(240 maxTokens: 1024,241 messages: [242 [243 'role' => 'user',244 'content' => [245 [246 'type' => 'document',247 'source' => [248 'type' => 'text',249 'media_type' => 'text/plain',250 'data' => 'The grass is green. The sky is blue.',251 ],252 'title' => 'My Document',253 'context' => 'This is a trustworthy document.',254 'citations' => ['enabled' => true],255 ],256 [257 'type' => 'text',258 'text' => 'What color is the grass and sky?',259 ],260 ],261 ],262 ],263 model: 'claude-opus-5',264 );265266 echo json_encode($response, JSON_PRETTY_PRINT);267 ```268269 ```ruby Ruby270 client = Anthropic::Client.new271272 response = client.messages.create(273 model: "claude-opus-5",274 max_tokens: 1024,275 messages: [276 {277 role: "user",278 content: [279 {280 type: "document",281 source: {282 type: "text",283 media_type: "text/plain",284 data: "The grass is green. The sky is blue."285 },286 title: "My Document",287 context: "This is a trustworthy document.",288 citations: { enabled: true }289 },290 {291 type: "text",292 text: "What color is the grass and sky?"293 }294 ]295 }296 ]297 )298299 puts response300 ```301</CodeGroup>302303<Tip>304 **Comparison with prompt-based approaches**305306 Compared to prompting Claude to cite sources, the citations feature offers the following advantages:307308 * **Cost savings:** If your prompt-based approach asks Claude to output direct quotes, you may see cost savings because `cited_text` does not count toward your output tokens.309 * **Better citation reliability:** Because the API parses citations into the response formats described in the following sections and extracts `cited_text` directly, citations are guaranteed to contain valid pointers to the provided documents.310 * **Improved citation quality:** In Anthropic's evaluations, the citations feature is significantly more likely to cite the most relevant quotes from documents than purely prompt-based approaches.311</Tip>312313***314315## How citations work316317Integrate citations with Claude in these steps:318319<Steps>320 <Step title="Provide document(s) and enable citations">321 * Include documents in any of the supported formats: [PDFs](https://platform.claude.com/docs/en/build-with-claude/citations#pdf-documents), [plain text](https://platform.claude.com/docs/en/build-with-claude/citations#plain-text-documents), or [custom content](https://platform.claude.com/docs/en/build-with-claude/citations#custom-content-documents) documents.322 * Set `citations.enabled=true` on each of your documents. Currently, citations must be enabled on all or none of the documents within a request.323 * Only text citations are currently supported. Image citations are not yet possible.324 </Step>325326 <Step title="Documents get processed">327 * Document contents are "chunked" to define the minimum granularity of possible citations. For example, sentence chunking lets Claude cite a single sentence or chain together multiple consecutive sentences to cite a paragraph or longer passage.328329 * **For PDFs:** Text is extracted as described in [PDF support](https://platform.claude.com/docs/en/build-with-claude/pdf-support) and content is chunked into sentences. Citing images from PDFs is not currently supported.330 * **For plain text documents:** Content is chunked into sentences that can be cited from.331 * **For custom content documents:** Your provided content blocks are used as-is and no further chunking is done.332 </Step>333334 <Step title="Claude provides cited response">335 * Responses may now include multiple text blocks where each text block can contain a claim that Claude is making and a list of citations that support the claim.336337 * Citations reference specific locations in source documents. The format of these citations is dependent on the type of document being cited from.338339 * **For PDFs:** Citations include the page number range (1-indexed).340 * **For plain text documents:** Citations include the character index range (0-indexed).341 * **For custom content documents:** Citations include the content block index range (0-indexed) corresponding to the original content list provided.342343 * Document indices are provided to indicate the reference source and are 0-indexed according to the list of all documents in your original request.344 </Step>345</Steps>346347<Tip>348 **Automatic chunking vs custom content**349350 By default, plain text and PDF documents are automatically chunked into sentences. If you need more control over citation granularity (for example, for bullet points or transcripts), use custom content documents instead. See [Document types](https://platform.claude.com/docs/en/build-with-claude/citations#document-types) for more details.351352 For example, if you want Claude to be able to cite specific sentences from your RAG chunks, you should put each RAG chunk into a plain text document. Otherwise, if you do not want any further chunking to be done, or if you want to customize any additional chunking, you can put RAG chunks into custom content document(s).353</Tip>354355### Citable versus non-citable content356357* Text found within a document's `source` content can be cited from.358* `title` and `context` are optional fields that are passed to the model but not used toward cited content.359* `title` is limited in length, so the `context` field is useful for storing document metadata as text or stringified JSON.360361### Citation indices362363* Document indices are 0-indexed from the list of all document content blocks in the request (spanning across all messages).364* Character indices are 0-indexed with exclusive end indices.365* Page numbers are 1-indexed with exclusive end page numbers.366* Content block indices are 0-indexed with exclusive end indices from the `content` list provided in the custom content document.367368### Token costs369370* Enabling citations incurs a slight increase in input tokens because of system prompt additions and document chunking.371* However, the citations feature is very efficient with output tokens. Internally, the model outputs citations in a standardized format that are then parsed into cited text and document location indices. The `cited_text` field is provided for convenience and does not count toward output tokens.372* When passed back in subsequent conversation turns, `cited_text` is also not counted toward input tokens.373374### Feature compatibility375376Citations work in conjunction with other API features including [prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching), [token counting](https://platform.claude.com/docs/en/build-with-claude/token-counting), and [batch processing](https://platform.claude.com/docs/en/build-with-claude/batch-processing).377378<Warning>379 **Citations and structured outputs are incompatible**380381 Citations cannot be used together with [structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs). If you enable citations on any user-provided document (`document` blocks or `search_result` blocks) and also include the `output_config.format` parameter (or the deprecated `output_format` parameter), the API returns a 400 error.382383 This is because citations require interleaving citation blocks with text output, which is incompatible with the strict JSON schema constraints of structured outputs.384</Warning>385386#### Using prompt caching with citations387388Citations and prompt caching can be used together effectively.389390The citation blocks generated in responses cannot be cached directly, but the source documents they reference can be cached. To optimize performance, apply `cache_control` to your top-level document content blocks.391392<CodeGroup>393 ```bash cURL394 curl https://api.anthropic.com/v1/messages \395 -H "content-type: application/json" \396 -H "x-api-key: $ANTHROPIC_API_KEY" \397 -H "anthropic-version: 2023-06-01" \398 -d '{399 "model": "claude-opus-5",400 "max_tokens": 1024,401 "messages": [402 {403 "role": "user",404 "content": [405 {406 "type": "document",407 "source": {408 "type": "text",409 "media_type": "text/plain",410 "data": "This is a very long document with thousands of words..."411 },412 "citations": {"enabled": true},413 "cache_control": {"type": "ephemeral"}414 },415 {416 "type": "text",417 "text": "What does this document say about API features?"418 }419 ]420 }421 ]422 }'423 ```424425 ```bash CLI426 ant messages create --model claude-opus-5 --max-tokens 1024 <<'YAML'427 messages:428 - role: user429 content:430 - type: document431 source:432 type: text433 media_type: text/plain434 data: This is a very long document with thousands of words...435 citations:436 enabled: true437 cache_control:438 type: ephemeral439 - type: text440 text: What does this document say about API features?441 YAML442 ```443444 ```python Python445 client = anthropic.Anthropic()446447 # Long document content (for example, technical documentation)448 long_document = (449 "This is a very long document with thousands of words..." + " ... " * 1000450 ) # Minimum cacheable length451452 response = client.messages.create(453 model="claude-opus-5",454 max_tokens=1024,455 messages=[456 {457 "role": "user",458 "content": [459 {460 "type": "document",461 "source": {462 "type": "text",463 "media_type": "text/plain",464 "data": long_document,465 },466 "citations": {"enabled": True},467 "cache_control": {468 "type": "ephemeral"469 }, # Cache the document content470 },471 {472 "type": "text",473 "text": "What does this document say about API features?",474 },475 ],476 }477 ],478 )479 print(response)480 ```481482 ```typescript TypeScript483 const client = new Anthropic();484485 // Long document content (for example, technical documentation)486 const longDocument =487 "This is a very long document with thousands of words..." + " ... ".repeat(1000); // Minimum cacheable length488489 const response = await client.messages.create({490 model: "claude-opus-5",491 max_tokens: 1024,492 messages: [493 {494 role: "user",495 content: [496 {497 type: "document",498 source: {499 type: "text",500 media_type: "text/plain",501 data: longDocument502 },503 citations: { enabled: true },504 cache_control: { type: "ephemeral" } // Cache the document content505 },506 {507 type: "text",508 text: "What does this document say about API features?"509 }510 ]511 }512 ]513 });514 console.log(response);515 ```516517 ```csharp C#518 var client = new AnthropicClient();519520 // Long document content (for example, technical documentation)521 var longDocument =522 "This is a very long document with thousands of words..."523 + string.Concat(Enumerable.Repeat(" ... ", 1000)); // Minimum cacheable length524525 var response = await client.Messages.Create(526 new()527 {528 Model = Model.ClaudeOpus5,529 MaxTokens = 1024,530 Messages =531 [532 new()533 {534 Role = Role.User,535 Content = new MessageParamContent(new List<ContentBlockParam>536 {537 new ContentBlockParam(new DocumentBlockParam(538 new DocumentBlockParamSource(new PlainTextSource() { Data = longDocument })539 )540 {541 Citations = new CitationsConfigParam { Enabled = true },542 CacheControl = new CacheControlEphemeral(), // Cache the document content543 }),544 new ContentBlockParam(new TextBlockParam("What does this document say about API features?")),545 }),546 },547 ],548 }549 );550551 Console.WriteLine(response);552 ```553554 ```go Go555 client := anthropic.NewClient()556557 // Long document content (for example, technical documentation)558 longDocument := "This is a very long document with thousands of words..." +559 strings.Repeat(" ... ", 1000) // Minimum cacheable length560561 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{562 Model: anthropic.ModelClaudeOpus5,563 MaxTokens: 1024,564 Messages: []anthropic.MessageParam{565 anthropic.NewUserMessage(566 anthropic.ContentBlockParamUnion{567 OfDocument: &anthropic.DocumentBlockParam{568 Source: anthropic.DocumentBlockParamSourceUnion{569 OfText: &anthropic.PlainTextSourceParam{Data: longDocument},570 },571 Citations: anthropic.CitationsConfigParam{Enabled: anthropic.Bool(true)},572 CacheControl: anthropic.NewCacheControlEphemeralParam(), // Cache the document content573 },574 },575 anthropic.NewTextBlock("What does this document say about API features?"),576 ),577 },578 })579 if err != nil {580 log.Fatal(err)581 }582 fmt.Println(response)583 ```584585 ```java Java586 AnthropicClient client = AnthropicOkHttpClient.fromEnv();587588 // Long document content (for example, technical documentation)589 String longDocument =590 "This is a very long document with thousands of words..."591 + " ... ".repeat(1000); // Minimum cacheable length592593 DocumentBlockParam documentParam = DocumentBlockParam.builder()594 .source(PlainTextSource.builder().data(longDocument).build())595 .citations(CitationsConfigParam.builder().enabled(true).build())596 .cacheControl(CacheControlEphemeral.builder().build()) // Cache the document content597 .build();598599 TextBlockParam textBlockParam = TextBlockParam.builder()600 .text("What does this document say about API features?")601 .build();602603 MessageCreateParams params = MessageCreateParams.builder()604 .model(Model.CLAUDE_OPUS_5)605 .maxTokens(1024)606 .addUserMessageOfBlockParams(607 List.of(608 ContentBlockParam.ofDocument(documentParam),609 ContentBlockParam.ofText(textBlockParam)610 )611 )612 .build();613614 Message message = client.messages().create(params);615 System.out.println(message);616 ```617618 ```php PHP619 $client = new Client();620621 // Long document content (for example, technical documentation)622 $longDocument =623 'This is a very long document with thousands of words...'624 . str_repeat(' ... ', 1000); // Minimum cacheable length625626 $response = $client->messages->create(627 maxTokens: 1024,628 messages: [629 [630 'role' => 'user',631 'content' => [632 [633 'type' => 'document',634 'source' => [635 'type' => 'text',636 'media_type' => 'text/plain',637 'data' => $longDocument,638 ],639 'citations' => ['enabled' => true],640 'cache_control' => ['type' => 'ephemeral'], // Cache the document content641 ],642 [643 'type' => 'text',644 'text' => 'What does this document say about API features?',645 ],646 ],647 ],648 ],649 model: 'claude-opus-5',650 );651652 echo json_encode($response, JSON_PRETTY_PRINT);653 ```654655 ```ruby Ruby656 client = Anthropic::Client.new657658 # Long document content (for example, technical documentation)659 long_document =660 "This is a very long document with thousands of words..." +661 " ... " * 1000 # Minimum cacheable length662663 response = client.messages.create(664 model: "claude-opus-5",665 max_tokens: 1024,666 messages: [667 {668 role: "user",669 content: [670 {671 type: "document",672 source: {673 type: "text",674 media_type: "text/plain",675 data: long_document676 },677 citations: { enabled: true },678 cache_control: { type: "ephemeral" } # Cache the document content679 },680 {681 type: "text",682 text: "What does this document say about API features?"683 }684 ]685 }686 ]687 )688689 puts response690 ```691</CodeGroup>692693In this example:694695* The document content is cached using `cache_control` on the document block.696* Citations are enabled on the document.697* Claude can generate responses with citations while benefiting from cached document content.698* Subsequent requests using the same document benefit from the cached content.699700## Document types701702### Choosing a document type703704Three document types are supported for citations. Documents can be provided directly in the message (base64, text, or URL) or uploaded through the [Files API](https://platform.claude.com/docs/en/build-with-claude/files) and referenced by `file_id`:705706| Type | Best for | Chunking | Citation format |707| -------------- | --------------------------------------------------------------- | ---------------------- | ----------------------------- |708| Plain text | Simple text documents, prose | Sentence | Character indices (0-indexed) |709| PDF | PDF files with text content | Sentence | Page numbers (1-indexed) |710| Custom content | Lists, transcripts, special formatting, more granular citations | No additional chunking | Block indices (0-indexed) |711712<Note>713 For file types that the `document` block doesn't support (for example, .docx and .xlsx), convert the files to plain text and include the content directly in message content. Files that are already plain text, such as .csv and .md files, can also be uploaded with an explicit `text/plain` content type. See [Working with other file formats](https://platform.claude.com/docs/en/build-with-claude/files#working-with-other-file-formats).714</Note>715716### Plain text documents717718Plain text documents are automatically chunked into sentences. You can provide them inline or by reference with their `file_id`:719720<Tabs>721 <Tab title="Inline text">722 The intro example at the top of this page shows a complete plain text request in every SDK. The document block uses a `text` source:723724 ```json725 {726 "type": "document",727 "source": {728 "type": "text",729 "media_type": "text/plain",730 "data": "Plain text content..."731 },732 "title": "Document Title",733 "context": "Context about the document that will not be cited from",734 "citations": { "enabled": true }735 }736 ```737 </Tab>738739 <Tab title="Files API">740 These examples reference a file uploaded through the [Files API](https://platform.claude.com/docs/en/build-with-claude/files) as a `document` source.741742 <CodeGroup>743 ```bash cURL744 curl -X POST https://api.anthropic.com/v1/messages \745 -H "x-api-key: $ANTHROPIC_API_KEY" \746 -H "anthropic-version: 2023-06-01" \747 -H "content-type: application/json" \748 -d @- <<EOF749 {750 "model": "claude-opus-5",751 "max_tokens": 1024,752 "messages": [753 {754 "role": "user",755 "content": [756 {757 "type": "document",758 "source": {"type": "file", "file_id": "$FILE_ID"},759 "title": "Document Title",760 "context": "Context about the document that will not be cited from",761 "citations": {"enabled": true}762 },763 {764 "type": "text",765 "text": "Summarize this document."766 }767 ]768 }769 ]770 }771 EOF772 ```773774 ```bash CLI775 ant messages create <<YAML776 model: claude-opus-5777 max_tokens: 1024778 messages:779 - role: user780 content:781 - type: document782 source:783 type: file784 file_id: $FILE_ID785 title: Document Title786 context: Context about the document that will not be cited from787 citations:788 enabled: true789 - type: text790 text: Summarize this document.791 YAML792 ```793794 ```python Python795 cited_response = client.messages.create(796 model="claude-opus-5",797 max_tokens=1024,798 messages=[799 {800 "role": "user",801 "content": [802 {803 "type": "document",804 "source": {"type": "file", "file_id": file_id},805 "title": "Document Title",806 "context": "Context about the document that will not be cited from",807 "citations": {"enabled": True},808 },809 {"type": "text", "text": "Summarize this document."},810 ],811 }812 ],813 )814 print(cited_response)815 ```816817 ```typescript TypeScript818 const citedResponse = await client.messages.create({819 model: "claude-opus-5",820 max_tokens: 1024,821 messages: [822 {823 role: "user",824 content: [825 {826 type: "document",827 source: { type: "file", file_id: uploaded.id },828 title: "Document Title",829 context: "Context about the document that will not be cited from",830 citations: { enabled: true },831 },832 {833 type: "text",834 text: "Summarize this document.",835 },836 ],837 },838 ],839 });840 console.log(citedResponse);841 ```842843 ```csharp C#844 var citedResponse = await client.Messages.Create(845 new MessageCreateParams846 {847 Model = Model.ClaudeOpus5,848 MaxTokens = 1024,849 Messages =850 [851 new MessageParam852 {853 Role = Role.User,854 Content = new List<ContentBlockParam>855 {856 new DocumentBlockParam857 {858 Source = new FileDocumentSource { FileID = fileId },859 Title = "Document Title",860 Context = "Context about the document that will not be cited from",861 Citations = new CitationsConfigParam { Enabled = true },862 },863 new TextBlockParam { Text = "Summarize this document." },864 }865 }866 ]867 });868869 Console.WriteLine(citedResponse);870 ```871872 ```go Go873 citedMsg, err := client.Messages.New(context.Background(),874 anthropic.MessageNewParams{875 Model: anthropic.ModelClaudeOpus5,876 MaxTokens: 1024,877 Messages: []anthropic.MessageParam{878 anthropic.NewUserMessage(879 anthropic.ContentBlockParamUnion{880 OfDocument: &anthropic.DocumentBlockParam{881 Source: anthropic.DocumentBlockParamSourceUnion{882 OfFile: &anthropic.FileDocumentSourceParam{FileID: fileID},883 },884 Title: anthropic.String("Document Title"),885 Context: anthropic.String("Context about the document that will not be cited from"),886 Citations: anthropic.CitationsConfigParam{Enabled: anthropic.Bool(true)},887 },888 },889 anthropic.NewTextBlock("Summarize this document."),890 ),891 },892 })893 if err != nil {894 log.Fatal(err)895 }896 fmt.Println(citedMsg)897 ```898899 ```java Java900 MessageCreateParams citedParams = MessageCreateParams.builder()901 .model(Model.CLAUDE_OPUS_5)902 .maxTokens(1024)903 .addUserMessageOfBlockParams(List.of(904 ContentBlockParam.ofDocument(DocumentBlockParam.builder()905 .fileSource(fileId)906 .title("Document Title")907 .context("Context about the document that will not be cited from")908 .citations(CitationsConfigParam.builder().enabled(true).build())909 .build()),910 ContentBlockParam.ofText(TextBlockParam.builder()911 .text("Summarize this document.")912 .build())913 ))914 .build();915916 Message citedMessage = client.messages().create(citedParams);917 System.out.println(citedMessage);918 ```919920 ```php PHP921 $citedResponse = $client->messages->create(922 maxTokens: 1024,923 messages: [924 [925 'role' => 'user',926 'content' => [927 [928 'type' => 'document',929 'source' => ['type' => 'file', 'fileID' => $fileId],930 'title' => 'Document Title',931 'context' => 'Context about the document that will not be cited from',932 'citations' => ['enabled' => true],933 ],934 ['type' => 'text', 'text' => 'Summarize this document.'],935 ],936 ],937 ],938 model: 'claude-opus-5',939 );940941 echo $citedResponse;942 ```943944 ```ruby Ruby945 cited_response = client.messages.create(946 model: "claude-opus-5",947 max_tokens: 1024,948 messages: [949 {950 role: "user",951 content: [952 {953 type: "document",954 source: { type: "file", file_id: file_id },955 title: "Document Title",956 context: "Context about the document that will not be cited from",957 citations: { enabled: true }958 },959 {960 type: "text",961 text: "Summarize this document."962 }963 ]964 }965 ]966 )967968 puts cited_response969 ```970 </CodeGroup>971 </Tab>972</Tabs>973974<Accordion title="Example plain text citation">975 ```json976 {977 "type": "char_location",978 "cited_text": "The exact text being cited", // not counted toward output tokens979 "document_index": 0,980 "document_title": "Document Title",981 "start_char_index": 0, // 0-indexed982 "end_char_index": 50 // exclusive983 }984 ```985</Accordion>986987### PDF documents988989PDF documents can be provided as base64-encoded data, a URL, or by `file_id`. PDF text is extracted and chunked into sentences. As image citations are not yet supported, PDFs that are scans of documents and do not contain extractable text are not citable.990991<Tabs>992 <Tab title="Base64">993 <CodeGroup>994 ```bash cURL995 PDF_BASE64=$(base64 /path/to/document.pdf | tr -d '\n')996997 curl https://api.anthropic.com/v1/messages \998 -H "content-type: application/json" \999 -H "x-api-key: $ANTHROPIC_API_KEY" \1000 -H "anthropic-version: 2023-06-01" \1001 -d '{1002 "model": "claude-opus-5",1003 "max_tokens": 1024,1004 "messages": [1005 {1006 "role": "user",1007 "content": [1008 {1009 "type": "document",1010 "source": {1011 "type": "base64",1012 "media_type": "application/pdf",1013 "data": "'"$PDF_BASE64"'"1014 },1015 "title": "Document Title",1016 "context": "Context about the document that will not be cited from",1017 "citations": {"enabled": true}1018 },1019 {1020 "type": "text",1021 "text": "Summarize this document."1022 }1023 ]1024 }1025 ]1026 }'1027 ```10281029 ```bash CLI1030 ant messages create <<'YAML'1031 model: claude-opus-51032 max_tokens: 10241033 messages:1034 - role: user1035 content:1036 - type: document1037 source:1038 type: base641039 media_type: application/pdf1040 data: "@/path/to/document.pdf"1041 title: Document Title1042 context: Context about the document that will not be cited from1043 citations:1044 enabled: true1045 - type: text1046 text: Summarize this document.1047 YAML1048 ```10491050 ```python Python1051 client = anthropic.Anthropic()10521053 pdf_base64 = base64.standard_b64encode(1054 pathlib.Path("/path/to/document.pdf").read_bytes()1055 ).decode()10561057 response = client.messages.create(1058 model="claude-opus-5",1059 max_tokens=1024,1060 messages=[1061 {1062 "role": "user",1063 "content": [1064 {1065 "type": "document",1066 "source": {1067 "type": "base64",1068 "media_type": "application/pdf",1069 "data": pdf_base64,1070 },1071 "title": "Document Title",1072 "context": "Context about the document that will not be cited from",1073 "citations": {"enabled": True},1074 },1075 {"type": "text", "text": "Summarize this document."},1076 ],1077 }1078 ],1079 )1080 print(response)1081 ```10821083 ```typescript TypeScript1084 const client = new Anthropic();10851086 const pdfBase64 = Buffer.from(await readFile("/path/to/document.pdf")).toString("base64");10871088 const response = await client.messages.create({1089 model: "claude-opus-5",1090 max_tokens: 1024,1091 messages: [1092 {1093 role: "user",1094 content: [1095 {1096 type: "document",1097 source: {1098 type: "base64",1099 media_type: "application/pdf",1100 data: pdfBase641101 },1102 title: "Document Title",1103 context: "Context about the document that will not be cited from",1104 citations: { enabled: true }1105 },1106 {1107 type: "text",1108 text: "Summarize this document."1109 }1110 ]1111 }1112 ]1113 });1114 console.log(response);1115 ```11161117 ```csharp C#1118 var client = new AnthropicClient();11191120 var pdfBase64 = Convert.ToBase64String(await File.ReadAllBytesAsync("/path/to/document.pdf"));11211122 var response = await client.Messages.Create(1123 new()1124 {1125 Model = Model.ClaudeOpus5,1126 MaxTokens = 1024,1127 Messages =1128 [1129 new()1130 {1131 Role = Role.User,1132 Content = new MessageParamContent(new List<ContentBlockParam>1133 {1134 new ContentBlockParam(new DocumentBlockParam(1135 new DocumentBlockParamSource(new Base64PdfSource() { Data = pdfBase64 })1136 )1137 {1138 Title = "Document Title",1139 Context = "Context about the document that will not be cited from",1140 Citations = new CitationsConfigParam { Enabled = true },1141 }),1142 new ContentBlockParam(new TextBlockParam("Summarize this document.")),1143 }),1144 },1145 ],1146 }1147 );11481149 Console.WriteLine(response);1150 ```11511152 ```go Go1153 client := anthropic.NewClient()11541155 pdfBytes, err := os.ReadFile("/path/to/document.pdf")1156 if err != nil {1157 log.Fatal(err)1158 }1159 pdfBase64 := base64.StdEncoding.EncodeToString(pdfBytes)11601161 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{1162 Model: anthropic.ModelClaudeOpus5,1163 MaxTokens: 1024,1164 Messages: []anthropic.MessageParam{1165 anthropic.NewUserMessage(1166 anthropic.ContentBlockParamUnion{1167 OfDocument: &anthropic.DocumentBlockParam{1168 Source: anthropic.DocumentBlockParamSourceUnion{1169 OfBase64: &anthropic.Base64PDFSourceParam{1170 Data: pdfBase64,1171 },1172 },1173 Title: anthropic.String("Document Title"),1174 Context: anthropic.String("Context about the document that will not be cited from"),1175 Citations: anthropic.CitationsConfigParam{Enabled: anthropic.Bool(true)},1176 },1177 },1178 anthropic.NewTextBlock("Summarize this document."),1179 ),1180 },1181 })1182 if err != nil {1183 log.Fatal(err)1184 }1185 fmt.Println(response)1186 ```11871188 ```java Java1189 AnthropicClient client = AnthropicOkHttpClient.fromEnv();11901191 byte[] pdfBytes = Files.readAllBytes(Path.of("/path/to/document.pdf"));1192 String pdfBase64 = Base64.getEncoder().encodeToString(pdfBytes);11931194 DocumentBlockParam documentParam = DocumentBlockParam.builder()1195 .source(Base64PdfSource.builder().data(pdfBase64).build())1196 .title("Document Title")1197 .context("Context about the document that will not be cited from")1198 .citations(CitationsConfigParam.builder().enabled(true).build())1199 .build();12001201 MessageCreateParams params = MessageCreateParams.builder()1202 .model(Model.CLAUDE_OPUS_5)1203 .maxTokens(1024)1204 .addUserMessageOfBlockParams(1205 List.of(1206 ContentBlockParam.ofDocument(documentParam),1207 ContentBlockParam.ofText(TextBlockParam.builder().text("Summarize this document.").build())1208 )1209 )1210 .build();12111212 Message message = client.messages().create(params);1213 System.out.println(message);1214 ```12151216 ```php PHP1217 $client = new Client();12181219 $pdfBase64 = base64_encode(file_get_contents('/path/to/document.pdf'));12201221 $response = $client->messages->create(1222 maxTokens: 1024,1223 messages: [1224 [1225 'role' => 'user',1226 'content' => [1227 [1228 'type' => 'document',1229 'source' => [1230 'type' => 'base64',1231 'media_type' => 'application/pdf',1232 'data' => $pdfBase64,1233 ],1234 'title' => 'Document Title',1235 'context' => 'Context about the document that will not be cited from',1236 'citations' => ['enabled' => true],1237 ],1238 [1239 'type' => 'text',1240 'text' => 'Summarize this document.',1241 ],1242 ],1243 ],1244 ],1245 model: 'claude-opus-5',1246 );12471248 echo json_encode($response, JSON_PRETTY_PRINT);1249 ```12501251 ```ruby Ruby1252 client = Anthropic::Client.new12531254 pdf_base64 = Base64.strict_encode64(File.binread("/path/to/document.pdf"))12551256 response = client.messages.create(1257 model: "claude-opus-5",1258 max_tokens: 1024,1259 messages: [1260 {1261 role: "user",1262 content: [1263 {1264 type: "document",1265 source: {1266 type: "base64",1267 media_type: "application/pdf",1268 data: pdf_base641269 },1270 title: "Document Title",1271 context: "Context about the document that will not be cited from",1272 citations: { enabled: true }1273 },1274 {1275 type: "text",1276 text: "Summarize this document."1277 }1278 ]1279 }1280 ]1281 )12821283 puts response1284 ```1285 </CodeGroup>1286 </Tab>12871288 <Tab title="URL">1289 <CodeGroup>1290 ```bash cURL1291 curl https://api.anthropic.com/v1/messages \1292 -H "content-type: application/json" \1293 -H "x-api-key: $ANTHROPIC_API_KEY" \1294 -H "anthropic-version: 2023-06-01" \1295 -d '{1296 "model": "claude-opus-5",1297 "max_tokens": 1024,1298 "messages": [1299 {1300 "role": "user",1301 "content": [1302 {1303 "type": "document",1304 "source": {1305 "type": "url",1306 "url": "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"1307 },1308 "title": "Document Title",1309 "context": "Context about the document that will not be cited from",1310 "citations": {"enabled": true}1311 },1312 {1313 "type": "text",1314 "text": "Summarize this document."1315 }1316 ]1317 }1318 ]1319 }'1320 ```13211322 ```bash CLI1323 ant messages create <<'YAML'1324 model: claude-opus-51325 max_tokens: 10241326 messages:1327 - role: user1328 content:1329 - type: document1330 source:1331 type: url1332 url: https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf1333 title: Document Title1334 context: Context about the document that will not be cited from1335 citations:1336 enabled: true1337 - type: text1338 text: Summarize this document.1339 YAML1340 ```13411342 ```python Python1343 client = anthropic.Anthropic()13441345 response = client.messages.create(1346 model="claude-opus-5",1347 max_tokens=1024,1348 messages=[1349 {1350 "role": "user",1351 "content": [1352 {1353 "type": "document",1354 "source": {1355 "type": "url",1356 "url": "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf",1357 },1358 "title": "Document Title",1359 "context": "Context about the document that will not be cited from",1360 "citations": {"enabled": True},1361 },1362 {"type": "text", "text": "Summarize this document."},1363 ],1364 }1365 ],1366 )1367 print(response)1368 ```13691370 ```typescript TypeScript1371 const client = new Anthropic();13721373 const response = await client.messages.create({1374 model: "claude-opus-5",1375 max_tokens: 1024,1376 messages: [1377 {1378 role: "user",1379 content: [1380 {1381 type: "document",1382 source: {1383 type: "url",1384 url: "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"1385 },1386 title: "Document Title",1387 context: "Context about the document that will not be cited from",1388 citations: { enabled: true }1389 },1390 {1391 type: "text",1392 text: "Summarize this document."1393 }1394 ]1395 }1396 ]1397 });1398 console.log(response);1399 ```14001401 ```csharp C#1402 var client = new AnthropicClient();14031404 var response = await client.Messages.Create(1405 new()1406 {1407 Model = Model.ClaudeOpus5,1408 MaxTokens = 1024,1409 Messages =1410 [1411 new()1412 {1413 Role = Role.User,1414 Content = new MessageParamContent(new List<ContentBlockParam>1415 {1416 new ContentBlockParam(new DocumentBlockParam(1417 new DocumentBlockParamSource(new UrlPdfSource()1418 {1419 Url = "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf",1420 })1421 )1422 {1423 Title = "Document Title",1424 Context = "Context about the document that will not be cited from",1425 Citations = new CitationsConfigParam { Enabled = true },1426 }),1427 new ContentBlockParam(new TextBlockParam("Summarize this document.")),1428 }),1429 },1430 ],1431 }1432 );14331434 Console.WriteLine(response);1435 ```14361437 ```go Go1438 client := anthropic.NewClient()14391440 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{1441 Model: anthropic.ModelClaudeOpus5,1442 MaxTokens: 1024,1443 Messages: []anthropic.MessageParam{1444 anthropic.NewUserMessage(1445 anthropic.ContentBlockParamUnion{1446 OfDocument: &anthropic.DocumentBlockParam{1447 Source: anthropic.DocumentBlockParamSourceUnion{1448 OfURL: &anthropic.URLPDFSourceParam{1449 URL: "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf",1450 },1451 },1452 Title: anthropic.String("Document Title"),1453 Context: anthropic.String("Context about the document that will not be cited from"),1454 Citations: anthropic.CitationsConfigParam{Enabled: anthropic.Bool(true)},1455 },1456 },1457 anthropic.NewTextBlock("Summarize this document."),1458 ),1459 },1460 })1461 if err != nil {1462 log.Fatal(err)1463 }1464 fmt.Println(response)1465 ```14661467 ```java Java1468 AnthropicClient client = AnthropicOkHttpClient.fromEnv();14691470 DocumentBlockParam documentParam = DocumentBlockParam.builder()1471 .source(UrlPdfSource.builder()1472 .url("https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf")1473 .build())1474 .title("Document Title")1475 .context("Context about the document that will not be cited from")1476 .citations(CitationsConfigParam.builder().enabled(true).build())1477 .build();14781479 MessageCreateParams params = MessageCreateParams.builder()1480 .model(Model.CLAUDE_OPUS_5)1481 .maxTokens(1024)1482 .addUserMessageOfBlockParams(1483 List.of(1484 ContentBlockParam.ofDocument(documentParam),1485 ContentBlockParam.ofText(TextBlockParam.builder().text("Summarize this document.").build())1486 )1487 )1488 .build();14891490 Message message = client.messages().create(params);1491 System.out.println(message);1492 ```14931494 ```php PHP1495 $client = new Client();14961497 $response = $client->messages->create(1498 maxTokens: 1024,1499 messages: [1500 [1501 'role' => 'user',1502 'content' => [1503 [1504 'type' => 'document',1505 'source' => [1506 'type' => 'url',1507 'url' => 'https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf',1508 ],1509 'title' => 'Document Title',1510 'context' => 'Context about the document that will not be cited from',1511 'citations' => ['enabled' => true],1512 ],1513 [1514 'type' => 'text',1515 'text' => 'Summarize this document.',1516 ],1517 ],1518 ],1519 ],1520 model: 'claude-opus-5',1521 );15221523 echo json_encode($response, JSON_PRETTY_PRINT);1524 ```15251526 ```ruby Ruby1527 client = Anthropic::Client.new15281529 response = client.messages.create(1530 model: "claude-opus-5",1531 max_tokens: 1024,1532 messages: [1533 {1534 role: "user",1535 content: [1536 {1537 type: "document",1538 source: {1539 type: "url",1540 url: "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"1541 },1542 title: "Document Title",1543 context: "Context about the document that will not be cited from",1544 citations: { enabled: true }1545 },1546 {1547 type: "text",1548 text: "Summarize this document."1549 }1550 ]1551 }1552 ]1553 )15541555 puts response1556 ```1557 </CodeGroup>1558 </Tab>15591560 <Tab title="Files API">1561 These examples reference a file uploaded through the [Files API](https://platform.claude.com/docs/en/build-with-claude/files) as a `document` source.15621563 <CodeGroup>1564 ```bash cURL1565 curl -X POST https://api.anthropic.com/v1/messages \1566 -H "x-api-key: $ANTHROPIC_API_KEY" \1567 -H "anthropic-version: 2023-06-01" \1568 -H "content-type: application/json" \1569 -d @- <<EOF1570 {1571 "model": "claude-opus-5",1572 "max_tokens": 1024,1573 "messages": [1574 {1575 "role": "user",1576 "content": [1577 {1578 "type": "document",1579 "source": {"type": "file", "file_id": "$FILE_ID"},1580 "title": "Document Title",1581 "context": "Context about the document that will not be cited from",1582 "citations": {"enabled": true}1583 },1584 {1585 "type": "text",1586 "text": "Summarize this document."1587 }1588 ]1589 }1590 ]1591 }1592 EOF1593 ```15941595 ```bash CLI1596 ant messages create <<YAML1597 model: claude-opus-51598 max_tokens: 10241599 messages:1600 - role: user1601 content:1602 - type: document1603 source:1604 type: file1605 file_id: $FILE_ID1606 title: Document Title1607 context: Context about the document that will not be cited from1608 citations:1609 enabled: true1610 - type: text1611 text: Summarize this document.1612 YAML1613 ```16141615 ```python Python1616 cited_response = client.messages.create(1617 model="claude-opus-5",1618 max_tokens=1024,1619 messages=[1620 {1621 "role": "user",1622 "content": [1623 {1624 "type": "document",1625 "source": {"type": "file", "file_id": file_id},1626 "title": "Document Title",1627 "context": "Context about the document that will not be cited from",1628 "citations": {"enabled": True},1629 },1630 {"type": "text", "text": "Summarize this document."},1631 ],1632 }1633 ],1634 )1635 print(cited_response)1636 ```16371638 ```typescript TypeScript1639 const citedResponse = await client.messages.create({1640 model: "claude-opus-5",1641 max_tokens: 1024,1642 messages: [1643 {1644 role: "user",1645 content: [1646 {1647 type: "document",1648 source: { type: "file", file_id: uploaded.id },1649 title: "Document Title",1650 context: "Context about the document that will not be cited from",1651 citations: { enabled: true },1652 },1653 {1654 type: "text",1655 text: "Summarize this document.",1656 },1657 ],1658 },1659 ],1660 });1661 console.log(citedResponse);1662 ```16631664 ```csharp C#1665 var citedResponse = await client.Messages.Create(1666 new MessageCreateParams1667 {1668 Model = Model.ClaudeOpus5,1669 MaxTokens = 1024,1670 Messages =1671 [1672 new MessageParam1673 {1674 Role = Role.User,1675 Content = new List<ContentBlockParam>1676 {1677 new DocumentBlockParam1678 {1679 Source = new FileDocumentSource { FileID = fileId },1680 Title = "Document Title",1681 Context = "Context about the document that will not be cited from",1682 Citations = new CitationsConfigParam { Enabled = true },1683 },1684 new TextBlockParam { Text = "Summarize this document." },1685 }1686 }1687 ]1688 });16891690 Console.WriteLine(citedResponse);1691 ```16921693 ```go Go1694 citedMsg, err := client.Messages.New(context.Background(),1695 anthropic.MessageNewParams{1696 Model: anthropic.ModelClaudeOpus5,1697 MaxTokens: 1024,1698 Messages: []anthropic.MessageParam{1699 anthropic.NewUserMessage(1700 anthropic.ContentBlockParamUnion{1701 OfDocument: &anthropic.DocumentBlockParam{1702 Source: anthropic.DocumentBlockParamSourceUnion{1703 OfFile: &anthropic.FileDocumentSourceParam{FileID: fileID},1704 },1705 Title: anthropic.String("Document Title"),1706 Context: anthropic.String("Context about the document that will not be cited from"),1707 Citations: anthropic.CitationsConfigParam{Enabled: anthropic.Bool(true)},1708 },1709 },1710 anthropic.NewTextBlock("Summarize this document."),1711 ),1712 },1713 })1714 if err != nil {1715 log.Fatal(err)1716 }1717 fmt.Println(citedMsg)1718 ```17191720 ```java Java1721 MessageCreateParams citedParams = MessageCreateParams.builder()1722 .model(Model.CLAUDE_OPUS_5)1723 .maxTokens(1024)1724 .addUserMessageOfBlockParams(List.of(1725 ContentBlockParam.ofDocument(DocumentBlockParam.builder()1726 .fileSource(fileId)1727 .title("Document Title")1728 .context("Context about the document that will not be cited from")1729 .citations(CitationsConfigParam.builder().enabled(true).build())1730 .build()),1731 ContentBlockParam.ofText(TextBlockParam.builder()1732 .text("Summarize this document.")1733 .build())1734 ))1735 .build();17361737 Message citedMessage = client.messages().create(citedParams);1738 System.out.println(citedMessage);1739 ```17401741 ```php PHP1742 $citedResponse = $client->messages->create(1743 maxTokens: 1024,1744 messages: [1745 [1746 'role' => 'user',1747 'content' => [1748 [1749 'type' => 'document',1750 'source' => ['type' => 'file', 'fileID' => $fileId],1751 'title' => 'Document Title',1752 'context' => 'Context about the document that will not be cited from',1753 'citations' => ['enabled' => true],1754 ],1755 ['type' => 'text', 'text' => 'Summarize this document.'],1756 ],1757 ],1758 ],1759 model: 'claude-opus-5',1760 );17611762 echo $citedResponse;1763 ```17641765 ```ruby Ruby1766 cited_response = client.messages.create(1767 model: "claude-opus-5",1768 max_tokens: 1024,1769 messages: [1770 {1771 role: "user",1772 content: [1773 {1774 type: "document",1775 source: { type: "file", file_id: file_id },1776 title: "Document Title",1777 context: "Context about the document that will not be cited from",1778 citations: { enabled: true }1779 },1780 {1781 type: "text",1782 text: "Summarize this document."1783 }1784 ]1785 }1786 ]1787 )17881789 puts cited_response1790 ```1791 </CodeGroup>1792 </Tab>1793</Tabs>17941795<Accordion title="Example PDF citation">1796 ```json1797 {1798 "type": "page_location",1799 "cited_text": "The exact text being cited", // not counted toward output tokens1800 "document_index": 0,1801 "document_title": "Document Title",1802 "start_page_number": 1, // 1-indexed1803 "end_page_number": 2 // exclusive1804 }1805 ```1806</Accordion>18071808### Custom content documents18091810Custom content documents give you control over citation granularity. No additional chunking is done and chunks are provided to the model according to the content blocks provided.18111812<CodeGroup>1813 ```bash cURL1814 curl https://api.anthropic.com/v1/messages \1815 -H "content-type: application/json" \1816 -H "x-api-key: $ANTHROPIC_API_KEY" \1817 -H "anthropic-version: 2023-06-01" \1818 -d '{1819 "model": "claude-opus-5",1820 "max_tokens": 1024,1821 "messages": [1822 {1823 "role": "user",1824 "content": [1825 {1826 "type": "document",1827 "source": {1828 "type": "content",1829 "content": [1830 {"type": "text", "text": "First chunk"},1831 {"type": "text", "text": "Second chunk"}1832 ]1833 },1834 "title": "Document Title",1835 "context": "Context about the document that will not be cited from",1836 "citations": {"enabled": true}1837 },1838 {1839 "type": "text",1840 "text": "Summarize this document."1841 }1842 ]1843 }1844 ]1845 }'1846 ```18471848 ```bash CLI1849 ant messages create <<'YAML'1850 model: claude-opus-51851 max_tokens: 10241852 messages:1853 - role: user1854 content:1855 - type: document1856 source:1857 type: content1858 content:1859 - type: text1860 text: First chunk1861 - type: text1862 text: Second chunk1863 title: Document Title1864 context: Context about the document that will not be cited from1865 citations:1866 enabled: true1867 - type: text1868 text: Summarize this document.1869 YAML1870 ```18711872 ```python Python1873 client = anthropic.Anthropic()18741875 response = client.messages.create(1876 model="claude-opus-5",1877 max_tokens=1024,1878 messages=[1879 {1880 "role": "user",1881 "content": [1882 {1883 "type": "document",1884 "source": {1885 "type": "content",1886 "content": [1887 {"type": "text", "text": "First chunk"},1888 {"type": "text", "text": "Second chunk"},1889 ],1890 },1891 "title": "Document Title",1892 "context": "Context about the document that will not be cited from",1893 "citations": {"enabled": True},1894 },1895 {"type": "text", "text": "Summarize this document."},1896 ],1897 }1898 ],1899 )1900 print(response)1901 ```19021903 ```typescript TypeScript1904 const client = new Anthropic();19051906 const response = await client.messages.create({1907 model: "claude-opus-5",1908 max_tokens: 1024,1909 messages: [1910 {1911 role: "user",1912 content: [1913 {1914 type: "document",1915 source: {1916 type: "content",1917 content: [1918 { type: "text", text: "First chunk" },1919 { type: "text", text: "Second chunk" }1920 ]1921 },1922 title: "Document Title",1923 context: "Context about the document that will not be cited from",1924 citations: { enabled: true }1925 },1926 {1927 type: "text",1928 text: "Summarize this document."1929 }1930 ]1931 }1932 ]1933 });1934 console.log(response);1935 ```19361937 ```csharp C#1938 var client = new AnthropicClient();19391940 var response = await client.Messages.Create(1941 new()1942 {1943 Model = Model.ClaudeOpus5,1944 MaxTokens = 1024,1945 Messages =1946 [1947 new()1948 {1949 Role = Role.User,1950 Content = new MessageParamContent(new List<ContentBlockParam>1951 {1952 new ContentBlockParam(new DocumentBlockParam(1953 new DocumentBlockParamSource(new ContentBlockSource()1954 {1955 Content = new ContentBlockSourceContent(new List<MessageContentBlockSourceContent>1956 {1957 new TextBlockParam("First chunk"),1958 new TextBlockParam("Second chunk"),1959 }),1960 })1961 )1962 {1963 Title = "Document Title",1964 Context = "Context about the document that will not be cited from",1965 Citations = new CitationsConfigParam { Enabled = true },1966 }),1967 new ContentBlockParam(new TextBlockParam("Summarize this document.")),1968 }),1969 },1970 ],1971 }1972 );19731974 Console.WriteLine(response);1975 ```19761977 ```go Go1978 client := anthropic.NewClient()19791980 response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{1981 Model: anthropic.ModelClaudeOpus5,1982 MaxTokens: 1024,1983 Messages: []anthropic.MessageParam{1984 anthropic.NewUserMessage(1985 anthropic.ContentBlockParamUnion{1986 OfDocument: &anthropic.DocumentBlockParam{1987 Source: anthropic.DocumentBlockParamSourceUnion{1988 OfContent: &anthropic.ContentBlockSourceParam{1989 Content: anthropic.ContentBlockSourceContentUnionParam{1990 OfContentBlockSourceContent: []anthropic.ContentBlockSourceContentItemUnionParam{1991 {OfText: &anthropic.TextBlockParam{Text: "First chunk"}},1992 {OfText: &anthropic.TextBlockParam{Text: "Second chunk"}},1993 },1994 },1995 },1996 },1997 Title: anthropic.String("Document Title"),1998 Context: anthropic.String("Context about the document that will not be cited from"),1999 Citations: anthropic.CitationsConfigParam{Enabled: anthropic.Bool(true)},2000 },2001 },2002 anthropic.NewTextBlock("Summarize this document."),2003 ),2004 },2005 })2006 if err != nil {2007 log.Fatal(err)2008 }2009 fmt.Println(response)2010 ```20112012 ```java Java2013 AnthropicClient client = AnthropicOkHttpClient.fromEnv();20142015 DocumentBlockParam documentParam = DocumentBlockParam.builder()2016 .source(ContentBlockSource.builder()2017 .contentOfBlockSource(2018 List.of(2019 ContentBlockSourceContent.ofText(TextBlockParam.builder().text("First chunk").build()),2020 ContentBlockSourceContent.ofText(TextBlockParam.builder().text("Second chunk").build())2021 )2022 )2023 .build())2024 .title("Document Title")2025 .context("Context about the document that will not be cited from")2026 .citations(CitationsConfigParam.builder().enabled(true).build())2027 .build();20282029 MessageCreateParams params = MessageCreateParams.builder()2030 .model(Model.CLAUDE_OPUS_5)2031 .maxTokens(1024)2032 .addUserMessageOfBlockParams(2033 List.of(2034 ContentBlockParam.ofDocument(documentParam),2035 ContentBlockParam.ofText(TextBlockParam.builder().text("Summarize this document.").build())2036 )2037 )2038 .build();20392040 Message message = client.messages().create(params);2041 System.out.println(message);2042 ```20432044 ```php PHP2045 $client = new Client();20462047 $response = $client->messages->create(2048 maxTokens: 1024,2049 messages: [2050 [2051 'role' => 'user',2052 'content' => [2053 [2054 'type' => 'document',2055 'source' => [2056 'type' => 'content',2057 'content' => [2058 ['type' => 'text', 'text' => 'First chunk'],2059 ['type' => 'text', 'text' => 'Second chunk'],2060 ],2061 ],2062 'title' => 'Document Title',2063 'context' => 'Context about the document that will not be cited from',2064 'citations' => ['enabled' => true],2065 ],2066 [2067 'type' => 'text',2068 'text' => 'Summarize this document.',2069 ],2070 ],2071 ],2072 ],2073 model: 'claude-opus-5',2074 );20752076 echo json_encode($response, JSON_PRETTY_PRINT);2077 ```20782079 ```ruby Ruby2080 client = Anthropic::Client.new20812082 response = client.messages.create(2083 model: "claude-opus-5",2084 max_tokens: 1024,2085 messages: [2086 {2087 role: "user",2088 content: [2089 {2090 type: "document",2091 source: {2092 type: "content",2093 content: [2094 { type: "text", text: "First chunk" },2095 { type: "text", text: "Second chunk" }2096 ]2097 },2098 title: "Document Title",2099 context: "Context about the document that will not be cited from",2100 citations: { enabled: true }2101 },2102 {2103 type: "text",2104 text: "Summarize this document."2105 }2106 ]2107 }2108 ]2109 )21102111 puts response2112 ```2113</CodeGroup>21142115<Accordion title="Example citation">2116 ```json2117 {2118 "type": "content_block_location",2119 "cited_text": "The exact text being cited", // not counted toward output tokens2120 "document_index": 0,2121 "document_title": "Document Title",2122 "start_block_index": 0, // 0-indexed2123 "end_block_index": 1 // exclusive2124 }2125 ```2126</Accordion>21272128***21292130## Response structure21312132When citations are enabled, responses include multiple text blocks with citations:21332134```json2135{2136 "content": [2137 { "type": "text", "text": "According to the document, " },2138 {2139 "type": "text",2140 "text": "the grass is green",2141 "citations": [2142 {2143 "type": "char_location",2144 "cited_text": "The grass is green.",2145 "document_index": 0,2146 "document_title": "Example Document",2147 "start_char_index": 0,2148 "end_char_index": 202149 }2150 ]2151 },2152 { "type": "text", "text": " and " },2153 {2154 "type": "text",2155 "text": "the sky is blue",2156 "citations": [2157 {2158 "type": "char_location",2159 "cited_text": "The sky is blue.",2160 "document_index": 0,2161 "document_title": "Example Document",2162 "start_char_index": 20,2163 "end_char_index": 362164 }2165 ]2166 },2167 {2168 "type": "text",2169 "text": ". Information from page 5 states that "2170 },2171 {2172 "type": "text",2173 "text": "water is essential",2174 "citations": [2175 {2176 "type": "page_location",2177 "cited_text": "Water is essential for life.",2178 "document_index": 1,2179 "document_title": "PDF Document",2180 "start_page_number": 5,2181 "end_page_number": 62182 }2183 ]2184 },2185 {2186 "type": "text",2187 "text": ". The custom document mentions "2188 },2189 {2190 "type": "text",2191 "text": "important findings",2192 "citations": [2193 {2194 "type": "content_block_location",2195 "cited_text": "These are important findings.",2196 "document_index": 2,2197 "document_title": "Custom Content Document",2198 "start_block_index": 0,2199 "end_block_index": 12200 }2201 ]2202 }2203 ]2204}2205```22062207### Streaming support22082209For streaming responses, citations arrive as a `citations_delta` delta type inside `content_block_delta` events. Each delta contains a single citation to add to the `citations` list on the current `text` content block.22102211<AccordionGroup>2212 <Accordion title="Example streaming events">2213 ```sse2214 event: message_start2215 data: {"type": "message_start", ...}22162217 event: content_block_start2218 data: {"type": "content_block_start", "index": 0, ...}22192220 event: content_block_delta2221 data: {"type": "content_block_delta", "index": 0,2222 "delta": {"type": "text_delta", "text": "According to..."}}22232224 event: content_block_delta2225 data: {"type": "content_block_delta", "index": 0,2226 "delta": {"type": "citations_delta",2227 "citation": {2228 "type": "char_location",2229 "cited_text": "...",2230 "document_index": 0,2231 ...2232 }}}22332234 event: content_block_stop2235 data: {"type": "content_block_stop", "index": 0}22362237 event: message_stop2238 data: {"type": "message_stop"}2239 ```2240 </Accordion>2241</AccordionGroup>22422243## Next steps22442245<CardGroup cols={2}>2246 <Card title="Streaming messages" icon="wifi-high" href="https://platform.claude.com/docs/en/build-with-claude/streaming">2247 Handle the `citations_delta` delta type alongside text deltas to render cited responses as they stream.2248 </Card>22492250 <Card title="Search results" icon="book-bookmark" href="https://platform.claude.com/docs/en/build-with-claude/search-results">2251 Pass search results from your RAG pipeline as first-class content blocks with built-in citation support.2252 </Card>22532254 <Card title="PDF support" icon="file" href="https://platform.claude.com/docs/en/build-with-claude/pdf-support">2255 Learn how Claude extracts text from PDFs and how page-based citations map back to your source files.2256 </Card>22572258 <Card title="Files API" icon="hard-drives" href="https://platform.claude.com/docs/en/build-with-claude/files">2259 Upload documents once and reference them by `file_id` across multiple citation requests.2260 </Card>2261</CardGroup>2262