Claude Tips mascot
Claude Tips & Tricks
API Tips advanced

Use the Citations API to Eliminate Hallucinations

Enable citations to force Claude to ground every claim in source documents, with exact character-level references you can verify.

The Citations API makes Claude cite specific passages from your source documents for every claim. It cuts hallucination way down and lets you programmatically verify responses.

Basic Usage

import anthropic
client = anthropic.Anthropic()

response = client.messages.create(
    model="claude-sonnet-4-6-20260301",
    max_tokens=1024,
    citations={"enabled": True},
    messages=[{
        "role": "user",
        "content": [
            {
                "type": "document",
                "source": {
                    "type": "text",
                    "media_type": "text/plain",
                    "data": your_document_text
                },
                "title": "Q3 Financial Report"
            },
            {
                "type": "text",
                "text": "What were the key revenue drivers this quarter?"
            }
        ]
    }]
)

What You Get Back

Claude’s response interleaves text blocks with citation blocks. Each citation includes:

  • cited_text: the exact quoted passage
  • Character-level start/end positions in the source document
  • Document index if you provided multiple sources

Cost-Saving Bonus

The cited_text field does not count towards output tokens. You get source attribution essentially for free.

Best Practice

For documents over 20K tokens, ask Claude to extract word-for-word quotes first, then synthesize. This two-step approach with citations makes fabricated information rare.