Compatibility
- ZDR: eligible (excludes Covered Models)
- Platforms: Claude API, Claude Platform on AWS, Amazon Bedrock, Google Cloud, Microsoft Foundry
Claude can provide detailed citations when answering questions about documents, helping you track and verify the sources behind each response.
All active models support citations.
Share your feedback and suggestions about the citations feature using the citations feedback form.
The following example shows how to enable citations on a plain text document with the Messages API:
bash
curl https://api.anthropic.com/v1/messages \
-H "content-type: application/json" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-opus-5",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": [
{
"type": "document",
"source": {
"type": "text",
"media_type": "text/plain",
"data": "The grass is green. The sky is blue."
},
"title": "My Document",
"context": "This is a trustworthy document.",
"citations": {"enabled": true}
},
{
"type": "text",
"text": "What color is the grass and sky?"
}
]
}
]
}'bash
ant messages create <<'YAML'
model: claude-opus-5
max_tokens: 1024
messages:
- role: user
content:
- type: document
source:
type: text
media_type: text/plain
data: The grass is green. The sky is blue.
title: My Document
context: This is a trustworthy document.
citations:
enabled: true
- type: text
text: What color is the grass and sky?
YAMLpython
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-opus-5",
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{
"type": "document",
"source": {
"type": "text",
"media_type": "text/plain",
"data": "The grass is green. The sky is blue.",
},
"title": "My Document",
"context": "This is a trustworthy document.",
"citations": {"enabled": True},
},
{"type": "text", "text": "What color is the grass and sky?"},
],
}
],
)
print(response)typescript
const client = new Anthropic();
const response = await client.messages.create({
model: "claude-opus-5",
max_tokens: 1024,
messages: [
{
role: "user",
content: [
{
type: "document",
source: {
type: "text",
media_type: "text/plain",
data: "The grass is green. The sky is blue."
},
title: "My Document",
context: "This is a trustworthy document.",
citations: { enabled: true }
},
{
type: "text",
text: "What color is the grass and sky?"
}
]
}
]
});
console.log(response);csharp
var client = new AnthropicClient();
var response = await client.Messages.Create(
new()
{
Model = Model.ClaudeOpus5,
MaxTokens = 1024,
Messages =
[
new()
{
Role = Role.User,
Content = new MessageParamContent(new List<ContentBlockParam>
{
new ContentBlockParam(new DocumentBlockParam(
new DocumentBlockParamSource(new PlainTextSource()
{
Data = "The grass is green. The sky is blue.",
})
)
{
Title = "My Document",
Context = "This is a trustworthy document.",
Citations = new CitationsConfigParam { Enabled = true },
}),
new ContentBlockParam(new TextBlockParam("What color is the grass and sky?")),
}),
},
],
}
);
Console.WriteLine(response);go
client := anthropic.NewClient()
response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: anthropic.ModelClaudeOpus5,
MaxTokens: 1024,
Messages: []anthropic.MessageParam{
anthropic.NewUserMessage(
anthropic.ContentBlockParamUnion{
OfDocument: &anthropic.DocumentBlockParam{
Source: anthropic.DocumentBlockParamSourceUnion{
OfText: &anthropic.PlainTextSourceParam{
Data: "The grass is green. The sky is blue.",
},
},
Title: anthropic.String("My Document"),
Context: anthropic.String("This is a trustworthy document."),
Citations: anthropic.CitationsConfigParam{Enabled: anthropic.Bool(true)},
},
},
anthropic.NewTextBlock("What color is the grass and sky?"),
),
},
})
if err != nil {
log.Fatal(err)
}
fmt.Println(response)java
AnthropicClient client = AnthropicOkHttpClient.fromEnv();
PlainTextSource source = PlainTextSource.builder()
.data("The grass is green. The sky is blue.")
.build();
DocumentBlockParam documentParam = DocumentBlockParam.builder()
.source(source)
.title("My Document")
.context("This is a trustworthy document.")
.citations(CitationsConfigParam.builder().enabled(true).build())
.build();
TextBlockParam textBlockParam = TextBlockParam.builder()
.text("What color is the grass and sky?")
.build();
MessageCreateParams params = MessageCreateParams.builder()
.model(Model.CLAUDE_OPUS_5)
.maxTokens(1024)
.addUserMessageOfBlockParams(
List.of(
ContentBlockParam.ofDocument(documentParam),
ContentBlockParam.ofText(textBlockParam)
)
)
.build();
Message message = client.messages().create(params);
System.out.println(message);php
$client = new Client();
$response = $client->messages->create(
maxTokens: 1024,
messages: [
[
'role' => 'user',
'content' => [
[
'type' => 'document',
'source' => [
'type' => 'text',
'media_type' => 'text/plain',
'data' => 'The grass is green. The sky is blue.',
],
'title' => 'My Document',
'context' => 'This is a trustworthy document.',
'citations' => ['enabled' => true],
],
[
'type' => 'text',
'text' => 'What color is the grass and sky?',
],
],
],
],
model: 'claude-opus-5',
);
echo json_encode($response, JSON_PRETTY_PRINT);ruby
client = Anthropic::Client.new
response = client.messages.create(
model: "claude-opus-5",
max_tokens: 1024,
messages: [
{
role: "user",
content: [
{
type: "document",
source: {
type: "text",
media_type: "text/plain",
data: "The grass is green. The sky is blue."
},
title: "My Document",
context: "This is a trustworthy document.",
citations: { enabled: true }
},
{
type: "text",
text: "What color is the grass and sky?"
}
]
}
]
)
puts responseComparison with prompt-based approaches
Compared to prompting Claude to cite sources, the citations feature offers the following advantages:
- Cost savings: If your prompt-based approach asks Claude to output direct quotes, you may see cost savings because
cited_textdoes not count toward your output tokens. - Better citation reliability: Because the API parses citations into the response formats described in the following sections and extracts
cited_textdirectly, citations are guaranteed to contain valid pointers to the provided documents. - 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.