citations changedbuild-with-claude/citations
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−63removed
From line
259
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 259, old and new numbered
/
from line 259
259259 .build();
260260
261261 Message message = client.messages().create(params);
262 System.out.println(message);
262 IO.println(message);
263263 ```
264264
265265 ```php PHP
from line 275
275275 'type' => 'document',
276276 'source' => [
277277 'type' => 'text',
278 'media_type' => 'text/plain',
278 'mediaType' => 'text/plain',
279279 'data' => 'The grass is green. The sky is blue.',
280280 ],
281281 'title' => 'My Document',
from line 343
343343
344344## How citations work
345345
346Integrate citations with Claude in these steps:
346Citations work in three stages:
347347
348348<Steps>
349 <Step title="Provide document(s) and enable citations">
349 <Step title="You provide documents and enable citations">
350350 * 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.
351 * Set `citations.enabled=true` on each of your documents. Currently, citations must be enabled on all or none of the documents within a request.
352 * Only text citations are currently supported. Image citations are not yet possible.
351 * Set `citations.enabled=true` on each of your documents. A request can’t mix documents that have citations enabled with documents that don’t.
352 * Claude can cite text but not images.
353353 </Step>
354354
355 <Step title="Documents get processed">
355 <Step title="The API processes the documents">
356356 * 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.
357357
358 * **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.
359 * **For plain text documents:** Content is chunked into sentences that can be cited from.
360 * **For custom content documents:** Your provided content blocks are used as-is and no further chunking is done.
358 * **For PDFs:** The API extracts text as described in [PDF support](https://platform.claude.com/docs/en/build-with-claude/pdf-support) and chunks it into sentences. Claude can’t cite images in PDFs.
359 * **For plain text documents:** The API chunks the content into sentences.
360 * **For custom content documents:** The API uses your content blocks as they are and does no further chunking.
361361 </Step>
362362
363 <Step title="Claude provides cited response">
364 * Responses might 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.
363 <Step title="Claude responds with citations">
364 * A response might include multiple text blocks. Each text block can contain a claim that Claude makes and a list of citations that support it.
365365
366 * Citations reference specific locations in source documents. The format of these citations is dependent on the type of document being cited from.
366 * Citations reference specific locations in source documents. A citation’s format depends on the type of document that Claude cites.
367367
368368 * **For PDFs:** Citations include the page number range (1-indexed).
369369 * **For plain text documents:** Citations include the character index range (0-indexed).
from line 374
374374</Steps>
375375
376376<Tip>
377 **Automatic chunking vs custom content**
377 **Automatic chunking versus custom content**
378378
379379 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.
380380
from line 402
402402
403403## Feature compatibility
404404
405Citations 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).
405Citations work 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).
406406
407407<Warning>
408408 **Citations and structured outputs are incompatible**
from line 473
473473
474474### Using prompt caching with citations
475475
476Citations and prompt caching can be used together effectively.
477
478476The 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.
479477
480478<CodeGroup>
from line 701
703701 .build();
704702
705703 Message message = client.messages().create(params);
706 System.out.println(message);
704 IO.println(message);
707705 ```
708706
709707 ```php PHP
from line 722
724722 'type' => 'document',
725723 'source' => [
726724 'type' => 'text',
727 'media_type' => 'text/plain',
725 'mediaType' => 'text/plain',
728726 'data' => $longDocument,
729727 ],
730728 'citations' => ['enabled' => true],
731 'cache_control' => ['type' => 'ephemeral'], // Cache the document content
729 'cacheControl' => ['type' => 'ephemeral'], // Cache the document content
732730 ],
733731 [
734732 'type' => 'text',
from line 808
810808
811809<Tabs>
812810 <Tab title="Inline text">
813 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:
811 For a complete plain text request, see the first example on this page. The document block uses a `text` source:
814812
815813 ```json
816814 {
from line 826
828826 </Tab>
829827
830828 <Tab title="Files API">
831 These examples reference a file uploaded through the [Files API](https://platform.claude.com/docs/en/build-with-claude/files) as a `document` source.
829 In these examples, the `source` of a `document` block references a file uploaded through the [Files API](https://platform.claude.com/docs/en/build-with-claude/files). The file ID in each example is the `id` that the upload returns (see [Uploading a file](https://platform.claude.com/docs/en/build-with-claude/files#uploading-a-file)).
832830
833831 <CodeGroup>
834832 ```bash cURL
from line 1002
10041002 .build();
10051003
10061004 Message citedMessage = client.messages().create(citedParams);
1007 System.out.println(citedMessage);
1005 IO.println(citedMessage);
10081006 ```
10091007
10101008 ```php PHP
from line 1023
10251023 ],
10261024 ],
10271025 ],
1028 model: 'claude-opus-5-5',
1026 model: Model::CLAUDE_OPUS_5_5,
10291027 );
10301028
10311029 echo $citedResponse;
from line 1074
10761074
10771075### PDF documents
10781076
1079PDF documents can be provided as base64-encoded data, as 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.
1077You can provide PDF documents as base64-encoded data, as a URL, or by `file_id`. The API extracts their text and chunks it into sentences.
10801078
1079Claude can’t cite images, so it can’t cite a PDF that is a scan of a document and has no extractable text.
1080
10811081<Tabs>
10821082 <Tab title="Base64">
10831083 <CodeGroup>
from line 1088
10881088 -H "content-type: application/json" \
10891089 -H "x-api-key: $ANTHROPIC_API_KEY" \
10901090 -H "anthropic-version: 2026-10-21" \
1091 -d '{
1092 "model": "claude-opus-5-5",
1093 "max_tokens": 1024,
1094 "messages": [
1095 {
1096 "role": "user",
1097 "content": [
1098 {
1099 "type": "document",
1100 "source": {
1101 "type": "base64",
1102 "media_type": "application/pdf",
1103 "data": "'"$PDF_BASE64"'"
1104 },
1105 "title": "Document Title",
1106 "context": "Context about the document that will not be cited from",
1107 "citations": {"enabled": true}
1091 -d @- <<EOF
1092 {
1093 "model": "claude-opus-5-5",
1094 "max_tokens": 1024,
1095 "messages": [
1096 {
1097 "role": "user",
1098 "content": [
1099 {
1100 "type": "document",
1101 "source": {
1102 "type": "base64",
1103 "media_type": "application/pdf",
1104 "data": "$PDF_BASE64"
11081105 },
1109 {
1110 "type": "text",
1111 "text": "Summarize this document."
1112 }
1113 ]
1114 }
1115 ]
1116 }'
1106 "title": "Document Title",
1107 "context": "Context about the document that will not be cited from",
1108 "citations": {"enabled": true}
1109 },
1110 {
1111 "type": "text",
1112 "text": "Summarize this document."
1113 }
1114 ]
1115 }
1116 ]
1117 }
1118 EOF
11171119 ```
11181120
11191121 ```bash CLI
from line 1307
13051307 .build();
13061308
13071309 Message message = client.messages().create(params);
1308 System.out.println(message);
1310 IO.println(message);
13091311 ```
13101312
13111313 ```php PHP
13121314 $client = new Client();
13131315
1314 $pdfBase64 = base64_encode(file_get_contents('/path/to/document.pdf'));
1316 $pdfBytes = file_get_contents('/path/to/document.pdf')
1317 ?: throw new \RuntimeException('Could not read /path/to/document.pdf.');
1318 $pdfBase64 = base64_encode($pdfBytes);
13151319
13161320 $response = $client->messages->create(
13171321 maxTokens: 1024,
from line 1327
13231327 'type' => 'document',
13241328 'source' => [
13251329 'type' => 'base64',
1326 'media_type' => 'application/pdf',
1330 'mediaType' => 'application/pdf',
13271331 'data' => $pdfBase64,
13281332 ],
13291333 'title' => 'Document Title',
from line 1341
13371341 ],
13381342 ],
13391343 ],
1340 model: 'claude-opus-5-5',
1344 model: Model::CLAUDE_OPUS_5_5,
13411345 );
13421346
13431347 echo json_encode($response, JSON_PRETTY_PRINT);
from line 1590
15861590 .build();
15871591
15881592 Message message = client.messages().create(params);
1589 System.out.println(message);
1593 IO.println(message);
15901594 ```
15911595
15921596 ```php PHP
from line 1619
16151619 ],
16161620 ],
16171621 ],
1618 model: 'claude-opus-5-5',
1622 model: Model::CLAUDE_OPUS_5_5,
16191623 );
16201624
16211625 echo json_encode($response, JSON_PRETTY_PRINT);
from line 1629
16251629 client = Anthropic::Client.new
16261630
16271631 response = client.messages.create(
1628 model: "claude-opus-5-5",
1632 model: Anthropic::Model::CLAUDE_OPUS_5_5,
16291633 max_tokens: 1024,
16301634 messages: [
16311635 {
from line 1660
16561660 </Tab>
16571661
16581662 <Tab title="Files API">
1659 These examples reference a file uploaded through the [Files API](https://platform.claude.com/docs/en/build-with-claude/files) as a `document` source.
1663 In these examples, the `source` of a `document` block references a file uploaded through the [Files API](https://platform.claude.com/docs/en/build-with-claude/files). The file ID in each example is the `id` that the upload returns (see [Uploading a file](https://platform.claude.com/docs/en/build-with-claude/files#uploading-a-file)).
16601664
16611665 <CodeGroup>
16621666 ```bash cURL
from line 1836
18321836 .build();
18331837
18341838 Message citedMessage = client.messages().create(citedParams);
1835 System.out.println(citedMessage);
1839 IO.println(citedMessage);
18361840 ```
18371841
18381842 ```php PHP
from line 1857
18531857 ],
18541858 ],
18551859 ],
1856 model: 'claude-opus-5-5',
1860 model: Model::CLAUDE_OPUS_5_5,
18571861 );
18581862
18591863 echo $citedResponse;
from line 1908
19041908
19051909### Custom content documents
19061910
1907Custom 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.
1911Custom content documents give you control over citation granularity. In the document’s `source`, `type` is `content`, and the `content` field holds a list of content blocks. The API does no further chunking: each text block that you provide is one chunk, the smallest unit that Claude can cite.
19081912
19091913<CodeGroup>
19101914 ```bash cURL
from line 2146
21422146 .build();
21432147
21442148 Message message = client.messages().create(params);
2145 System.out.println(message);
2149 IO.println(message);
21462150 ```
21472151
21482152 ```php PHP
No line in this hunk matches that.