Citations in the Claude API: verbatim, precisely located and cheaper
TL;DR
Citations returns verbatim quotes with exact locations in your documents, more reliable and cheaper than prompting since cited_text doesn't count as output tokens. Pick the right document type and don't combine it with structured outputs.
A chatbot answers from internal documents, but users ask: "Where does this come from?". You can tell the model to "cite your sources" in the prompt, but those citations may point to the wrong place or even quote sentences that aren't in the document. The Claude API's Citations feature solves this at the root: the API returns verbatim quotes with their exact location in the source document, guaranteed to point to real content.
Enabling citations
{
"type": "document",
"source": {"type": "text", "media_type": "text/plain",
"data": "Returns are accepted within 30 days..."},
"title": "Sales policy",
"citations": {"enabled": true}
}
Put this document block in the user message's content along with the question. The answer comes back as several text blocks; those based on the document carry a citations array.
Three document types
| Type | Best for | Chunking | Citation location |
|---|---|---|---|
| Plain text | Ordinary prose | By sentence | Character indices (0-indexed) |
| PDFs with a text layer | By sentence | Page numbers (1-indexed) | |
| Custom content | Lists, transcripts, RAG chunks | No further chunking | Block indices (0-indexed) |
To let Claude cite individual sentences within RAG chunks, put each chunk in a plain text document. To keep chunk boundaries as they are, use custom content.
What comes back
{
"type": "text",
"text": "Customers can return items within 30 days",
"citations": [{
"type": "char_location",
"cited_text": "Returns are accepted within 30 days...",
"document_index": 0,
"start_char_index": 0, "end_char_index": 37
}]
}
Why it beats prompt-based citations
- Reliable: citations are parsed by the API and guaranteed to be valid pointers into the provided documents.
- Quality: in Anthropic's evaluations, the feature is significantly more likely to cite the most relevant passages than purely prompt-based approaches.
- Cheaper:
cited_textdoesn't count toward output tokens, nor toward input tokens when passed back in later turns. In exchange, input grows slightly due to system additions and document chunking.
Risks and caveats
- Not compatible with structured outputs: enabling citations together with
output_config.formatreturns a 400 error, because citations must be interleaved with text. - Scanned PDFs can't be cited: image citations aren't supported yet; a PDF without a text layer has nothing to cite.
- Citation ≠ correct reasoning: the quote is real, but the conclusion drawn may still be wrong; the UI should let users see the original passage.
- Combine with caching: large documents reused many times should use prompt caching to cut cost.
How to apply it
- Dev: For RAG chatbots, put chunks into citation-enabled documents instead of stuffing them into the system prompt; render
cited_textas clickable footnotes. - Tech Lead: Add an automated check: answers with no citation for important claims get flagged for review.
- PM: A "view source" feature noticeably boosts user trust for legal, policy and medical content.
Sources & references
- Citations — Claude Docs