Skip to contents

Convenience function to create a document block with citations enabled.

Usage

claude_doc_cite(source, title = NULL, context = NULL)

Arguments

source

Either a file path (for inline) or file_id (for uploaded files).

title

Character. Optional document title.

context

Character. Optional context about the document.

Value

A content block with citations enabled.

Details

When citations are enabled, Claude's response will include citation blocks that reference specific passages. Citation locations include:

  • char_location: Character offsets in plain text

  • page_location: Page numbers in PDFs

  • content_block_location: Index in multi-block documents

For inline documents (file paths), the file is base64-encoded and included in the request. For uploaded files (file_id strings), only the reference is sent.

API Reference: https://www.anthropic.com/news/introducing-citations-api

Examples

if (FALSE) { # \dontrun{
# Inline document with citations
chat <- claude_new()
response <- chat$chat(
  claude_doc_cite("contract.pdf", title = "Service Agreement"),
  "What are the termination conditions? Cite specific clauses."
)

# Uploaded file with citations
file <- claude_file_upload("report.pdf")
chat$chat(
  claude_doc_cite(file$id, title = "Q4 Report"),
  "Summarize with citations"
)
} # }