인용
인용 (Citations)
Claude는 문서에 대한 질문에 답할 때 상세한 인용을 제공할 수 있어요. 각 주장을 뒷받침하는 정확한 구절을 반환하므로, 답변을 검증하고 사용자에게 출처를 표시할 수 있어요. 모든 활성 모델이 인용을 지원해요.
출처: 문서
본문
Claude는 문서에 대한 질문에 답할 때 상세한 인용을 제공할 수 있어요. 각 응답 뒤의 출처를 추적하고 검증하는 데 도움이 돼요.
모든 활성 모델이 인용을 지원해요.
팁: 인용 기능에 대한 피드백과 제안은 인용 피드백 양식을 통해 공유하세요.
다음 예시는 Messages API로 일반 텍스트 문서에서 인용을 활성화하는 방법을 보여줘요:
ant messages create <<'YAML'
model: claude-opus-5-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?
YAML
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-opus-5-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)
const client = new Anthropic();
const response = await client.messages.create({
model: "claude-opus-5-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);
var client = new AnthropicClient();
var response = await client.Messages.Create(
new()
{
Model = Model.ClaudeOpus5_5,
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);
client := anthropic.NewClient()
response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: anthropic.ModelClaudeOpus5_5,
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)
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_5)
.maxTokens(1024)
.addUserMessageOfBlockParams(
List.of(
ContentBlockParam.ofDocument(documentParam),
ContentBlockParam.ofText(textBlockParam)
)
)
.build();
Message message = client.messages().create(params);
System.out.println(message);
$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-5',
);
echo json_encode($response, JSON_PRETTY_PRINT);
client = Anthropic::Client.new
response = client.messages.create(
model: "claude-opus-5-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 response
팁: 프롬프트 기반 접근과의 비교
출처를 인용하도록 Claude에 프롬프트하는 것과 비교해, 인용 기능은 다음 이점을 제공해요:
- 비용 절감: 프롬프트 기반 접근이 Claude에게 직접 인용문을 출력하라고 요청한다면,
cited_text가 출력 토큰에 계산되지 않으므로 비용 절감을 볼 수 있어요.- 더 나은 인용 신뢰성: API가 인용을 다음 섹션에 설명된 응답 형식으로 파싱하고
cited_text를 직접 추출하므로, 인용은 제공된 문서에 대한 유효한 포인터를 포함하는 것이 보장돼요.- 개선된 인용 품질: Anthropic의 평가에서 인용 기능은 순수 프롬프트 기반 접근보다 문서에서 가장 관련성 높은 인용문을 인용할 가능성이 현저히 높아요.
인용이 동작하는 방식
이 단계들로 Claude와 인용을 통합하세요:
팁: 자동 청킹 vs 커스텀 콘텐츠
기본적으로 일반 텍스트와 PDF 문서는 자동으로 문장으로 청킹돼요. 인용 세분성을 더 제어해야 한다면(예: 불릿 포인트나 트랜스크립트) 대신 커스텀 콘텐츠 문서를 사용하세요. 자세한 내용은 문서 유형을 참고하세요.
예를 들어 RAG 청크에서 특정 문장을 Claude가 인용할 수 있게 하려면 각 RAG 청크를 일반 텍스트 문서에 넣어야 해요. 반대로 추가 청킹을 원하지 않거나 커스텀 추가 청킹을 원한다면 RAG 청크를 커스텀 콘텐츠 문서에 넣을 수 있어요.
인용 가능 vs 비인용 가능 콘텐츠
- 문서
source콘텐츠 안의 텍스트는 인용될 수 있어요. title과context는 모델에 전달되지만 인용된 콘텐츠에는 사용되지 않는 선택 필드예요.title은 길이가 제한되므로,context필드는 문서 메타데이터를 텍스트나 문자열화된 JSON으로 저장하는 데 유용해요.
인용 인덱스
- 문서 인덱스는 요청의 모든 문서 콘텐츠 블록 목록(모든 메시지에 걸쳐)에서 0-indexed예요.
- 문자 인덱스는 0-indexed이며 끝 인덱스는 제외돼요.
- 페이지 번호는 1-indexed이며 끝 페이지 번호는 제외돼요.
- 콘텐츠 블록 인덱스는 커스텀 콘텐츠 문서에 제공된
content목록에서 0-indexed이며 끝 인덱스는 제외돼요.
토큰 비용
- 인용 활성화는 시스템 프롬프트 추가와 문서 청킹 때문에 입력 토큰이 약간 증가해요.
- 하지만 인용 기능은 출력 토큰에 매우 효율적이에요. 내부적으로 모델은 표준화된 형식으로 인용을 출력하고, 이것이 인용된 텍스트와 문서 위치 인덱스로 파싱돼요.
cited_text필드는 편의를 위해 제공되며 출력 토큰에 계산되지 않아요. - 이후 대화 턴으로 다시 전달될 때
cited_text도 입력 토큰에 계산되지 않아요.
기능 호환성
인용은 프롬프트 캐싱, 토큰 계산, 배치 처리를 포함한 다른 API 기능과 함께 작동해요.
경고: 인용과 구조화된 출력은 호환되지 않아요
인용은 구조화된 출력과 함께 사용할 수 없어요. 사용자 제공 문서(
document블록 또는search_result블록)에서 인용을 활성화하고output_config.format매개변수(또는 폐기된output_format매개변수)도 포함하면 API가 400 오류를 반환해요.이는 인용이 텍스트 출력에 인용 블록을 인터리브해야 하기 때문인데, 이는 구조화된 출력의 엄격한 JSON 스키마 제약과 호환되지 않아요.
인용과 프롬프트 캐싱 사용하기
인용과 프롬프트 캐싱은 효과적으로 함께 사용할 수 있어요.
응답에서 생성된 인용 블록은 직접 캐시될 수 없지만, 그것이 참조하는 소스 문서는 캐시될 수 있어요. 성능을 최적화하려면 최상위 문서 콘텐츠 블록에 cache_control을 적용하세요.
ant messages create --model claude-opus-5-5 --max-tokens 1024 <<'YAML'
messages:
- role: user
content:
- type: document
source:
type: text
media_type: text/plain
data: This is a very long document with thousands of words...
citations:
enabled: true
cache_control:
type: ephemeral
- type: text
text: What does this document say about API features?
YAML
client = anthropic.Anthropic()
# Long document content (for example, technical documentation)
long_document = (
"This is a very long document with thousands of words..." + " ... " * 1000
) # Minimum cacheable length
response = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{
"type": "document",
"source": {
"type": "text",
"media_type": "text/plain",
"data": long_document,
},
"citations": {"enabled": True},
"cache_control": {
"type": "ephemeral"
}, # Cache the document content
},
{
"type": "text",
"text": "What does this document say about API features?",
},
],
}
],
)
print(response)
const client = new Anthropic();
// Long document content (for example, technical documentation)
const longDocument =
"This is a very long document with thousands of words..." + " ... ".repeat(1000); // Minimum cacheable length
const response = await client.messages.create({
model: "claude-opus-5-5",
max_tokens: 1024,
messages: [
{
role: "user",
content: [
{
type: "document",
source: {
type: "text",
media_type: "text/plain",
data: longDocument
},
citations: { enabled: true },
cache_control: { type: "ephemeral" } // Cache the document content
},
{
type: "text",
text: "What does this document say about API features?"
}
]
}
]
});
console.log(response);
var client = new AnthropicClient();
// Long document content (for example, technical documentation)
var longDocument =
"This is a very long document with thousands of words..."
+ string.Concat(Enumerable.Repeat(" ... ", 1000)); // Minimum cacheable length
var response = await client.Messages.Create(
new()
{
Model = Model.ClaudeOpus5_5,
MaxTokens = 1024,
Messages =
[
new()
{
Role = Role.User,
Content = new MessageParamContent(new List<ContentBlockParam>
{
new ContentBlockParam(new DocumentBlockParam(
new DocumentBlockParamSource(new PlainTextSource() { Data = longDocument })
)
{
Citations = new CitationsConfigParam { Enabled = true },
CacheControl = new CacheControlEphemeral(), // Cache the document content
}),
new ContentBlockParam(new TextBlockParam("What does this document say about API features?")),
}),
},
],
}
);
Console.WriteLine(response);
client := anthropic.NewClient()
// Long document content (for example, technical documentation)
longDocument := "This is a very long document with thousands of words..." +
strings.Repeat(" ... ", 1000) // Minimum cacheable length
response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: anthropic.ModelClaudeOpus5_5,
MaxTokens: 1024,
Messages: []anthropic.MessageParam{
anthropic.NewUserMessage(
anthropic.ContentBlockParamUnion{
OfDocument: &anthropic.DocumentBlockParam{
Source: anthropic.DocumentBlockParamSourceUnion{
OfText: &anthropic.PlainTextSourceParam{Data: longDocument},
},
Citations: anthropic.CitationsConfigParam{Enabled: anthropic.Bool(true)},
CacheControl: anthropic.NewCacheControlEphemeralParam(), // Cache the document content
},
},
anthropic.NewTextBlock("What does this document say about API features?"),
),
},
})
if err != nil {
log.Fatal(err)
}
fmt.Println(response)
AnthropicClient client = AnthropicOkHttpClient.fromEnv();
// Long document content (for example, technical documentation)
String longDocument =
"This is a very long document with thousands of words..."
+ " ... ".repeat(1000); // Minimum cacheable length
DocumentBlockParam documentParam = DocumentBlockParam.builder()
.source(PlainTextSource.builder().data(longDocument).build())
.citations(CitationsConfigParam.builder().enabled(true).build())
.cacheControl(CacheControlEphemeral.builder().build()) // Cache the document content
.build();
TextBlockParam textBlockParam = TextBlockParam.builder()
.text("What does this document say about API features?")
.build();
MessageCreateParams params = MessageCreateParams.builder()
.model(Model.CLAUDE_OPUS_5_5)
.maxTokens(1024)
.addUserMessageOfBlockParams(
List.of(
ContentBlockParam.ofDocument(documentParam),
ContentBlockParam.ofText(textBlockParam)
)
)
.build();
Message message = client.messages().create(params);
System.out.println(message);
$client = new Client();
// Long document content (for example, technical documentation)
$longDocument =
'This is a very long document with thousands of words...'
. str_repeat(' ... ', 1000); // Minimum cacheable length
$response = $client->messages->create(
maxTokens: 1024,
messages: [
[
'role' => 'user',
'content' => [
[
'type' => 'document',
'source' => [
'type' => 'text',
'media_type' => 'text/plain',
'data' => $longDocument,
],
'citations' => ['enabled' => true],
'cache_control' => ['type' => 'ephemeral'], // Cache the document content
],
[
'type' => 'text',
'text' => 'What does this document say about API features?',
],
],
],
],
model: 'claude-opus-5-5',
);
echo json_encode($response, JSON_PRETTY_PRINT);
client = Anthropic::Client.new
# Long document content (for example, technical documentation)
long_document =
"This is a very long document with thousands of words..." +
" ... " * 1000 # Minimum cacheable length
response = client.messages.create(
model: "claude-opus-5-5",
max_tokens: 1024,
messages: [
{
role: "user",
content: [
{
type: "document",
source: {
type: "text",
media_type: "text/plain",
data: long_document
},
citations: { enabled: true },
cache_control: { type: "ephemeral" } # Cache the document content
},
{
type: "text",
text: "What does this document say about API features?"
}
]
}
]
)
puts response
이 예시에서:
- 문서 콘텐츠는 문서 블록의
cache_control로 캐시돼요. - 인용이 문서에서 활성화돼요.
- Claude는 캐시된 문서 콘텐츠를 활용하면서 인용이 있는 응답을 생성할 수 있어요.
- 같은 문서를 사용하는 후속 요청은 캐시된 콘텐츠를 활용해요.
문서 유형 (Document types)
문서 유형 선택하기
인용에는 세 가지 문서 유형이 지원돼요. 문서는 메시지에 직접(베이스64, 텍스트, URL) 제공하거나 Files API를 통해 업로드하고 file_id로 참조할 수 있어요:
| 유형 | 가장 좋은 용도 | 청킹 | 인용 형식 |
|---|---|---|---|
| 일반 텍스트 | 단순한 텍스트 문서, 산문 | 문장 | 문자 인덱스 (0-indexed) |
| 텍스트 콘텐츠가 있는 PDF 파일 | 문장 | 페이지 번호 (1-indexed) | |
| 커스텀 콘텐츠 | 목록, 트랜스크립트, 특수 서식, 더 세분화된 인용 | 추가 청킹 없음 | 블록 인덱스 (0-indexed) |
참고:
document블록이 지원하지 않는 파일 유형(예: .docx와 .xlsx)은 파일을 일반 텍스트로 변환하고 콘텐츠를 메시지 콘텐츠에 직접 포함하세요. .csv와 .md 파일처럼 이미 일반 텍스트인 파일은 명시적text/plain콘텐츠 유형으로 업로드할 수도 있어요. 다른 파일 형식 작업하기 참고.
일반 텍스트 문서
일반 텍스트 문서는 자동으로 문장으로 청킹돼요. 인라인으로 또는 file_id 참조로 제공할 수 있어요:
```json
{
"type": "document",
"source": {
"type": "text",
"media_type": "text/plain",
"data": "Plain text content..."
},
"title": "Document Title",
"context": "Context about the document that will not be cited from",
"citations": { "enabled": true }
}
```
<CodeGroup>
```bash cURL
curl -X POST https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHR...KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d @- <<EOF
{
"model": "claude-opus-5-5",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": [
{
"type": "document",
"source": {"type": "file", "file_id": "$FILE_ID"},
"title": "Document Title",
"context": "Context about the document that will not be cited from",
"citations": {"enabled": true}
},
{
"type": "text",
"text": "Summarize this document."
}
]
}
]
}
EOF
```
```bash CLI
ant messages create <<YAML
model: claude-opus-5-5
max_tokens: 1024
messages:
- role: user
content:
- type: document
source:
type: file
file_id: $FILE_ID
title: Document Title
context: Context about the document that will not be cited from
citations:
enabled: true
- type: text
text: Summarize this document.
YAML
```
```python Python
cited_response = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{
"type": "document",
"source": {"type": "file", "file_id": file_id},
"title": "Document Title",
"context": "Context about the document that will not be cited from",
"citations": {"enabled": True},
},
{"type": "text", "text": "Summarize this document."},
],
}
],
)
print(cited_response)
```
```typescript TypeScript
const citedResponse = await client.messages.create({
model: "claude-opus-5-5",
max_tokens: 1024,
messages: [
{
role: "user",
content: [
{
type: "document",
source: { type: "file", file_id: uploaded.id },
title: "Document Title",
context: "Context about the document that will not be cited from",
citations: { enabled: true },
},
{
type: "text",
text: "Summarize this document.",
},
],
},
],
});
console.log(citedResponse);
```
```csharp C#
var citedResponse = await client.Messages.Create(
new MessageCreateParams
{
Model = Model.ClaudeOpus5_5,
MaxTokens = 1024,
Messages =
[
new MessageParam
{
Role = Role.User,
Content = new List<ContentBlockParam>
{
new DocumentBlockParam
{
Source = new FileDocumentSource { FileID = fileId },
Title = "Document Title",
Context = "Context about the document that will not be cited from",
Citations = new CitationsConfigParam { Enabled = true },
},
new TextBlockParam { Text = "Summarize this document." },
}
}
]
});
Console.WriteLine(citedResponse);
```
```go Go
citedMsg, err := client.Messages.New(context.Background(),
anthropic.MessageNewParams{
Model: anthropic.ModelClaudeOpus5_5,
MaxTokens: 1024,
Messages: []anthropic.MessageParam{
anthropic.NewUserMessage(
anthropic.ContentBlockParamUnion{
OfDocument: &anthropic.DocumentBlockParam{
Source: anthropic.DocumentBlockParamSourceUnion{
OfFile: &anthropic.FileDocumentSourceParam{FileID: fileID},
},
Title: anthropic.String("Document Title"),
Context: anthropic.String("Context about the document that will not be cited from"),
Citations: anthropic.CitationsConfigParam{Enabled: anthropic.Bool(true)},
},
},
anthropic.NewTextBlock("Summarize this document."),
),
},
})
if err != nil {
log.Fatal(err)
}
fmt.Println(citedMsg)
```
```java Java
MessageCreateParams citedParams = MessageCreateParams.builder()
.model(Model.CLAUDE_OPUS_5_5)
.maxTokens(1024)
.addUserMessageOfBlockParams(List.of(
ContentBlockParam.ofDocument(DocumentBlockParam.builder()
.fileSource(fileId)
.title("Document Title")
.context("Context about the document that will not be cited from")
.citations(CitationsConfigParam.builder().enabled(true).build())
.build()),
ContentBlockParam.ofText(TextBlockParam.builder()
.text("Summarize this document.")
.build())
))
.build();
Message citedMessage = client.messages().create(citedParams);
System.out.println(citedMessage);
```
```php PHP
$citedResponse = $client->messages->create(
maxTokens: 1024,
messages: [
[
'role' => 'user',
'content' => [
[
'type' => 'document',
'source' => ['type' => 'file', 'fileID' => $fileId],
'title' => 'Document Title',
'context' => 'Context about the document that will not be cited from',
'citations' => ['enabled' => true],
],
['type' => 'text', 'text' => 'Summarize this document.'],
],
],
],
model: 'claude-opus-5-5',
);
echo $citedResponse;
```
```ruby Ruby
cited_response = client.messages.create(
model: "claude-opus-5-5",
max_tokens: 1024,
messages: [
{
role: "user",
content: [
{
type: "document",
source: { type: "file", file_id: file_id },
title: "Document Title",
context: "Context about the document that will not be cited from",
citations: { enabled: true }
},
{
type: "text",
text: "Summarize this document."
}
]
}
]
)
puts cited_response
```
</CodeGroup>
PDF 문서
PDF 문서는 base64로 인코딩된 데이터, URL, 또는 file_id로 제공할 수 있어요. PDF 텍스트는 추출되어 문장으로 청킹돼요. 이미지 인용이 아직 지원되지 않으므로, 문서 스캔처럼 추출 가능한 텍스트가 없는 PDF는 인용할 수 없어요.
curl https://api.anthropic.com/v1/messages \
-H "content-type: application/json" \
-H "x-api-key: $ANTHR...KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-opus-5-5",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": [
{
"type": "document",
"source": {
"type": "base64",
"media_type": "application/pdf",
"data": "'"$PDF_BASE64"'"
},
"title": "Document Title",
"context": "Context about the document that will not be cited from",
"citations": {"enabled": true}
},
{
"type": "text",
"text": "Summarize this document."
}
]
}
]
}'
```
```bash CLI
ant messages create <<'YAML'
model: claude-opus-5-5
max_tokens: 1024
messages:
- role: user
content:
- type: document
source:
type: base64
media_type: application/pdf
data: "@/path/to/document.pdf"
title: Document Title
context: Context about the document that will not be cited from
citations:
enabled: true
- type: text
text: Summarize this document.
YAML
```
```python Python
client = anthropic.Anthropic()
pdf_base64 = base64.standard_b64encode(
pathlib.Path("/path/to/document.pdf").read_bytes()
).decode()
response = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{
"type": "document",
"source": {
"type": "base64",
"media_type": "application/pdf",
"data": pdf_base64,
},
"title": "Document Title",
"context": "Context about the document that will not be cited from",
"citations": {"enabled": True},
},
{"type": "text", "text": "Summarize this document."},
],
}
],
)
print(response)
```
```typescript TypeScript
const client = new Anthropic();
const pdfBase64 = Buffer.from(await readFile("/path/to/document.pdf")).toString("base64");
const response = await client.messages.create({
model: "claude-opus-5-5",
max_tokens: 1024,
messages: [
{
role: "user",
content: [
{
type: "document",
source: {
type: "base64",
media_type: "application/pdf",
data: pdfBase64
},
title: "Document Title",
context: "Context about the document that will not be cited from",
citations: { enabled: true }
},
{
type: "text",
text: "Summarize this document."
}
]
}
]
});
console.log(response);
```
```csharp C#
var client = new AnthropicClient();
var pdfBase64 = Convert.ToBase64String(await File.ReadAllBytesAsync("/path/to/document.pdf"));
var response = await client.Messages.Create(
new()
{
Model = Model.ClaudeOpus5_5,
MaxTokens = 1024,
Messages =
[
new()
{
Role = Role.User,
Content = new MessageParamContent(new List<ContentBlockParam>
{
new ContentBlockParam(new DocumentBlockParam(
new DocumentBlockParamSource(new Base64PdfSource() { Data = pdfBase64 })
)
{
Title = "Document Title",
Context = "Context about the document that will not be cited from",
Citations = new CitationsConfigParam { Enabled = true },
}),
new ContentBlockParam(new TextBlockParam("Summarize this document.")),
}),
},
],
}
);
Console.WriteLine(response);
```
```go Go
client := anthropic.NewClient()
pdfBytes, err := os.ReadFile("/path/to/document.pdf")
if err != nil {
log.Fatal(err)
}
pdfBase64 := base64.StdEncoding.EncodeToString(pdfBytes)
response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: anthropic.ModelClaudeOpus5_5,
MaxTokens: 1024,
Messages: []anthropic.MessageParam{
anthropic.NewUserMessage(
anthropic.ContentBlockParamUnion{
OfDocument: &anthropic.DocumentBlockParam{
Source: anthropic.DocumentBlockParamSourceUnion{
OfBase64: &anthropic.Base64PDFSourceParam{
Data: pdfBase64,
},
},
Title: anthropic.String("Document Title"),
Context: anthropic.String("Context about the document that will not be cited from"),
Citations: anthropic.CitationsConfigParam{Enabled: anthropic.Bool(true)},
},
},
anthropic.NewTextBlock("Summarize this document."),
),
},
})
if err != nil {
log.Fatal(err)
}
fmt.Println(response)
```
```java Java
AnthropicClient client = AnthropicOkHttpClient.fromEnv();
byte[] pdfBytes = Files.readAllBytes(Path.of("/path/to/document.pdf"));
String pdfBase64 = Base64.getEncoder().encodeToString(pdfBytes);
DocumentBlockParam documentParam = DocumentBlockParam.builder()
.source(Base64PdfSource.builder().data(pdfBase64).build())
.title("Document Title")
.context("Context about the document that will not be cited from")
.citations(CitationsConfigParam.builder().enabled(true).build())
.build();
MessageCreateParams params = MessageCreateParams.builder()
.model(Model.CLAUDE_OPUS_5_5)
.maxTokens(1024)
.addUserMessageOfBlockParams(
List.of(
ContentBlockParam.ofDocument(documentParam),
ContentBlockParam.ofText(TextBlockParam.builder().text("Summarize this document.").build())
)
)
.build();
Message message = client.messages().create(params);
System.out.println(message);
```
```php PHP
$client = new Client();
$pdfBase64 = base64_encode(file_get_contents('/path/to/document.pdf'));
$response = $client->messages->create(
maxTokens: 1024,
messages: [
[
'role' => 'user',
'content' => [
[
'type' => 'document',
'source' => [
'type' => 'base64',
'media_type' => 'application/pdf',
'data' => $pdfBase64,
],
'title' => 'Document Title',
'context' => 'Context about the document that will not be cited from',
'citations' => ['enabled' => true],
],
[
'type' => 'text',
'text' => 'Summarize this document.',
],
],
],
],
model: 'claude-opus-5-5',
);
echo json_encode($response, JSON_PRETTY_PRINT);
```
```ruby Ruby
client = Anthropic::Client.new
pdf_base64 = Base64.strict_encode64(File.binread("/path/to/document.pdf"))
response = client.messages.create(
model: "claude-opus-5-5",
max_tokens: 1024,
messages: [
{
role: "user",
content: [
{
type: "document",
source: {
type: "base64",
media_type: "application/pdf",
data: pdf_base64
},
title: "Document Title",
context: "Context about the document that will not be cited from",
citations: { enabled: true }
},
{
type: "text",
text: "Summarize this document."
}
]
}
]
)
puts response
```
</CodeGroup>
```bash CLI
ant messages create <<'YAML'
model: claude-opus-5-5
max_tokens: 1024
messages:
- role: user
content:
- type: document
source:
type: url
url: https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf
title: Document Title
context: Context about the document that will not be cited from
citations:
enabled: true
- type: text
text: Summarize this document.
YAML
```
```python Python
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{
"type": "document",
"source": {
"type": "url",
"url": "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf",
},
"title": "Document Title",
"context": "Context about the document that will not be cited from",
"citations": {"enabled": True},
},
{"type": "text", "text": "Summarize this document."},
],
}
],
)
print(response)
```
```typescript TypeScript
const client = new Anthropic();
const response = await client.messages.create({
model: "claude-opus-5-5",
max_tokens: 1024,
messages: [
{
role: "user",
content: [
{
type: "document",
source: {
type: "url",
url: "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"
},
title: "Document Title",
context: "Context about the document that will not be cited from",
citations: { enabled: true }
},
{
type: "text",
text: "Summarize this document."
}
]
}
]
});
console.log(response);
```
```csharp C#
var client = new AnthropicClient();
var response = await client.Messages.Create(
new()
{
Model = Model.ClaudeOpus5_5,
MaxTokens = 1024,
Messages =
[
new()
{
Role = Role.User,
Content = new MessageParamContent(new List<ContentBlockParam>
{
new ContentBlockParam(new DocumentBlockParam(
new DocumentBlockParamSource(new UrlPdfSource()
{
Url = "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf",
})
)
{
Title = "Document Title",
Context = "Context about the document that will not be cited from",
Citations = new CitationsConfigParam { Enabled = true },
}),
new ContentBlockParam(new TextBlockParam("Summarize this document.")),
}),
},
],
}
);
Console.WriteLine(response);
```
```go Go
client := anthropic.NewClient()
response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: anthropic.ModelClaudeOpus5_5,
MaxTokens: 1024,
Messages: []anthropic.MessageParam{
anthropic.NewUserMessage(
anthropic.ContentBlockParamUnion{
OfDocument: &anthropic.DocumentBlockParam{
Source: anthropic.DocumentBlockParamSourceUnion{
OfURL: &anthropic.URLPDFSourceParam{
URL: "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf",
},
},
Title: anthropic.String("Document Title"),
Context: anthropic.String("Context about the document that will not be cited from"),
Citations: anthropic.CitationsConfigParam{Enabled: anthropic.Bool(true)},
},
},
anthropic.NewTextBlock("Summarize this document."),
),
},
})
if err != nil {
log.Fatal(err)
}
fmt.Println(response)
```
```java Java
AnthropicClient client = AnthropicOkHttpClient.fromEnv();
DocumentBlockParam documentParam = DocumentBlockParam.builder()
.source(UrlPdfSource.builder()
.url("https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf")
.build())
.title("Document Title")
.context("Context about the document that will not be cited from")
.citations(CitationsConfigParam.builder().enabled(true).build())
.build();
MessageCreateParams params = MessageCreateParams.builder()
.model(Model.CLAUDE_OPUS_5_5)
.maxTokens(1024)
.addUserMessageOfBlockParams(
List.of(
ContentBlockParam.ofDocument(documentParam),
ContentBlockParam.ofText(TextBlockParam.builder().text("Summarize this document.").build())
)
)
.build();
Message message = client.messages().create(params);
System.out.println(message);
```
```php PHP
$client = new Client();
$response = $client->messages->create(
maxTokens: 1024,
messages: [
[
'role' => 'user',
'content' => [
[
'type' => 'document',
'source' => [
'type' => 'url',
'url' => 'https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf',
],
'title' => 'Document Title',
'context' => 'Context about the document that will not be cited from',
'citations' => ['enabled' => true],
],
[
'type' => 'text',
'text' => 'Summarize this document.',
],
],
],
],
model: 'claude-opus-5-5',
);
echo json_encode($response, JSON_PRETTY_PRINT);
```
```ruby Ruby
client = Anthropic::Client.new
response = client.messages.create(
model: "claude-opus-5-5",
max_tokens: 1024,
messages: [
{
role: "user",
content: [
{
type: "document",
source: {
type: "url",
url: "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"
},
title: "Document Title",
context: "Context about the document that will not be cited from",
citations: { enabled: true }
},
{
type: "text",
text: "Summarize this document."
}
]
}
]
)
puts response
```
</CodeGroup>
<CodeGroup>
```bash cURL
curl -X POST https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHR...KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d @- <<EOF
{
"model": "claude-opus-5-5",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": [
{
"type": "document",
"source": {"type": "file", "file_id": "$FILE_ID"},
"title": "Document Title",
"context": "Context about the document that will not be cited from",
"citations": {"enabled": true}
},
{
"type": "text",
"text": "Summarize this document."
}
]
}
]
}
EOF
```
```bash CLI
ant messages create <<YAML
model: claude-opus-5-5
max_tokens: 1024
messages:
- role: user
content:
- type: document
source:
type: file
file_id: $FILE_ID
title: Document Title
context: Context about the document that will not be cited from
citations:
enabled: true
- type: text
text: Summarize this document.
YAML
```
```python Python
cited_response = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{
"type": "document",
"source": {"type": "file", "file_id": file_id},
"title": "Document Title",
"context": "Context about the document that will not be cited from",
"citations": {"enabled": True},
},
{"type": "text", "text": "Summarize this document."},
],
}
],
)
print(cited_response)
```
```typescript TypeScript
const citedResponse = await client.messages.create({
model: "claude-opus-5-5",
max_tokens: 1024,
messages: [
{
role: "user",
content: [
{
type: "document",
source: { type: "file", file_id: uploaded.id },
title: "Document Title",
context: "Context about the document that will not be cited from",
citations: { enabled: true },
},
{
type: "text",
text: "Summarize this document.",
},
],
},
],
});
console.log(citedResponse);
```
```csharp C#
var citedResponse = await client.Messages.Create(
new MessageCreateParams
{
Model = Model.ClaudeOpus5_5,
MaxTokens = 1024,
Messages =
[
new MessageParam
{
Role = Role.User,
Content = new List<ContentBlockParam>
{
new DocumentBlockParam
{
Source = new FileDocumentSource { FileID = fileId },
Title = "Document Title",
Context = "Context about the document that will not be cited from",
Citations = new CitationsConfigParam { Enabled = true },
},
new TextBlockParam { Text = "Summarize this document." },
}
}
]
});
Console.WriteLine(citedResponse);
```
```go Go
citedMsg, err := client.Messages.New(context.Background(),
anthropic.MessageNewParams{
Model: anthropic.ModelClaudeOpus5_5,
MaxTokens: 1024,
Messages: []anthropic.MessageParam{
anthropic.NewUserMessage(
anthropic.ContentBlockParamUnion{
OfDocument: &anthropic.DocumentBlockParam{
Source: anthropic.DocumentBlockParamSourceUnion{
OfFile: &anthropic.FileDocumentSourceParam{FileID: fileID},
},
Title: anthropic.String("Document Title"),
Context: anthropic.String("Context about the document that will not be cited from"),
Citations: anthropic.CitationsConfigParam{Enabled: anthropic.Bool(true)},
},
},
anthropic.NewTextBlock("Summarize this document."),
),
},
})
if err != nil {
log.Fatal(err)
}
fmt.Println(citedMsg)
```
```java Java
MessageCreateParams citedParams = MessageCreateParams.builder()
.model(Model.CLAUDE_OPUS_5_5)
.maxTokens(1024)
.addUserMessageOfBlockParams(List.of(
ContentBlockParam.ofDocument(DocumentBlockParam.builder()
.fileSource(fileId)
.title("Document Title")
.context("Context about the document that will not be cited from")
.citations(CitationsConfigParam.builder().enabled(true).build())
.build()),
ContentBlockParam.ofText(TextBlockParam.builder()
.text("Summarize this document.")
.build())
))
.build();
Message citedMessage = client.messages().create(citedParams);
System.out.println(citedMessage);
```
```php PHP
$citedResponse = $client->messages->create(
maxTokens: 1024,
messages: [
[
'role' => 'user',
'content' => [
[
'type' => 'document',
'source' => ['type' => 'file', 'fileID' => $fileId],
'title' => 'Document Title',
'context' => 'Context about the document that will not be cited from',
'citations' => ['enabled' => true],
],
['type' => 'text', 'text' => 'Summarize this document.'],
],
],
],
model: 'claude-opus-5-5',
);
echo $citedResponse;
```
```ruby Ruby
cited_response = client.messages.create(
model: "claude-opus-5-5",
max_tokens: 1024,
messages: [
{
role: "user",
content: [
{
type: "document",
source: { type: "file", file_id: file_id },
title: "Document Title",
context: "Context about the document that will not be cited from",
citations: { enabled: true }
},
{
type: "text",
text: "Summarize this document."
}
]
}
]
)
puts cited_response
```
</CodeGroup>
커스텀 콘텐츠 문서
커스텀 콘텐츠 문서는 인용 세분성을 제어하게 해 줘요. 추가 청킹은 하지 않고, 제공된 콘텐츠 블록에 따라 청크가 모델에 제공돼요.
ant messages create <<'YAML'
model: claude-opus-5-5
max_tokens: 1024
messages:
- role: user
content:
- type: document
source:
type: content
content:
- type: text
text: First chunk
- type: text
text: Second chunk
title: Document Title
context: Context about the document that will not be cited from
citations:
enabled: true
- type: text
text: Summarize this document.
YAML
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{
"type": "document",
"source": {
"type": "content",
"content": [
{"type": "text", "text": "First chunk"},
{"type": "text", "text": "Second chunk"},
],
},
"title": "Document Title",
"context": "Context about the document that will not be cited from",
"citations": {"enabled": True},
},
{"type": "text", "text": "Summarize this document."},
],
}
],
)
print(response)
const client = new Anthropic();
const response = await client.messages.create({
model: "claude-opus-5-5",
max_tokens: 1024,
messages: [
{
role: "user",
content: [
{
type: "document",
source: {
type: "content",
content: [
{ type: "text", text: "First chunk" },
{ type: "text", text: "Second chunk" }
]
},
title: "Document Title",
context: "Context about the document that will not be cited from",
citations: { enabled: true }
},
{
type: "text",
text: "Summarize this document."
}
]
}
]
});
console.log(response);
var client = new AnthropicClient();
var response = await client.Messages.Create(
new()
{
Model = Model.ClaudeOpus5_5,
MaxTokens = 1024,
Messages =
[
new()
{
Role = Role.User,
Content = new MessageParamContent(new List<ContentBlockParam>
{
new ContentBlockParam(new DocumentBlockParam(
new DocumentBlockParamSource(new ContentBlockSource()
{
Content = new ContentBlockSourceContent(new List<MessageContentBlockSourceContent>
{
new TextBlockParam("First chunk"),
new TextBlockParam("Second chunk"),
}),
})
)
{
Title = "Document Title",
Context = "Context about the document that will not be cited from",
Citations = new CitationsConfigParam { Enabled = true },
}),
new ContentBlockParam(new TextBlockParam("Summarize this document.")),
}),
},
],
}
);
Console.WriteLine(response);
client := anthropic.NewClient()
response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: anthropic.ModelClaudeOpus5_5,
MaxTokens: 1024,
Messages: []anthropic.MessageParam{
anthropic.NewUserMessage(
anthropic.ContentBlockParamUnion{
OfDocument: &anthropic.DocumentBlockParam{
Source: anthropic.DocumentBlockParamSourceUnion{
OfContent: &anthropic.ContentBlockSourceParam{
Content: anthropic.ContentBlockSourceContentUnionParam{
OfContentBlockSourceContent: []anthropic.ContentBlockSourceContentItemUnionParam{
{OfText: &anthropic.TextBlockParam{Text: "First chunk"}},
{OfText: &anthropic.TextBlockParam{Text: "Second chunk"}},
},
},
},
},
Title: anthropic.String("Document Title"),
Context: anthropic.String("Context about the document that will not be cited from"),
Citations: anthropic.CitationsConfigParam{Enabled: anthropic.Bool(true)},
},
},
anthropic.NewTextBlock("Summarize this document."),
),
},
})
if err != nil {
log.Fatal(err)
}
fmt.Println(response)
AnthropicClient client = AnthropicOkHttpClient.fromEnv();
DocumentBlockParam documentParam = DocumentBlockParam.builder()
.source(ContentBlockSource.builder()
.contentOfBlockSource(
List.of(
ContentBlockSourceContent.ofText(TextBlockParam.builder().text("First chunk").build()),
ContentBlockSourceContent.ofText(TextBlockParam.builder().text("Second chunk").build())
)
)
.build())
.title("Document Title")
.context("Context about the document that will not be cited from")
.citations(CitationsConfigParam.builder().enabled(true).build())
.build();
MessageCreateParams params = MessageCreateParams.builder()
.model(Model.CLAUDE_OPUS_5_5)
.maxTokens(1024)
.addUserMessageOfBlockParams(
List.of(
ContentBlockParam.ofDocument(documentParam),
ContentBlockParam.ofText(TextBlockParam.builder().text("Summarize this document.").build())
)
)
.build();
Message message = client.messages().create(params);
System.out.println(message);
$client = new Client();
$response = $client->messages->create(
maxTokens: 1024,
messages: [
[
'role' => 'user',
'content' => [
[
'type' => 'document',
'source' => [
'type' => 'content',
'content' => [
['type' => 'text', 'text' => 'First chunk'],
['type' => 'text', 'text' => 'Second chunk'],
],
],
'title' => 'Document Title',
'context' => 'Context about the document that will not be cited from',
'citations' => ['enabled' => true],
],
[
'type' => 'text',
'text' => 'Summarize this document.',
],
],
],
],
model: 'claude-opus-5-5',
);
echo json_encode($response, JSON_PRETTY_PRINT);
client = Anthropic::Client.new
response = client.messages.create(
model: "claude-opus-5-5",
max_tokens: 1024,
messages: [
{
role: "user",
content: [
{
type: "document",
source: {
type: "content",
content: [
{ type: "text", text: "First chunk" },
{ type: "text", text: "Second chunk" }
]
},
title: "Document Title",
context: "Context about the document that will not be cited from",
citations: { enabled: true }
},
{
type: "text",
text: "Summarize this document."
}
]
}
]
)
puts response
응답 구조 (Response structure)
인용이 활성화되면 응답은 인용이 있는 여러 텍스트 블록을 포함해요:
{
"content": [
{ "type": "text", "text": "According to the document, " },
{
"type": "text",
"text": "the grass is green",
"citations": [
{
"type": "char_location",
"cited_text": "The grass is green.",
"document_index": 0,
"document_title": "Example Document",
"start_char_index": 0,
"end_char_index": 20
}
]
},
{ "type": "text", "text": " and " },
{
"type": "text",
"text": "the sky is blue",
"citations": [
{
"type": "char_location",
"cited_text": "The sky is blue.",
"document_index": 0,
"document_title": "Example Document",
"start_char_index": 20,
"end_char_index": 36
}
]
},
{
"type": "text",
"text": ". Information from page 5 states that "
},
{
"type": "text",
"text": "water is essential",
"citations": [
{
"type": "page_location",
"cited_text": "Water is essential for life.",
"document_index": 1,
"document_title": "PDF Document",
"start_page_number": 5,
"end_page_number": 6
}
]
},
{
"type": "text",
"text": ". The custom document mentions "
},
{
"type": "text",
"text": "important findings",
"citations": [
{
"type": "content_block_location",
"cited_text": "These are important findings.",
"document_index": 2,
"document_title": "Custom Content Document",
"start_block_index": 0,
"end_block_index": 1
}
]
}
]
}
스트리밍 지원
스트리밍 응답의 경우 인용은 content_block_delta 이벤트 안의 citations_delta 델타 유형으로 도착해요. 각 델타는 현재 text 콘텐츠 블록의 citations 목록에 추가할 단일 인용을 포함해요.
event: content_block_start
data: {"type": "content_block_start", "index": 0, ...}
event: content_block_delta
data: {"type": "content_block_delta", "index": 0,
"delta": {"type": "text_delta", "text": "According to..."}}
event: content_block_delta
data: {"type": "content_block_delta", "index": 0,
"delta": {"type": "citations_delta",
"citation": {
"type": "char_location",
"cited_text": "...",
"document_index": 0,
...
}}}
event: content_block_stop
data: {"type": "content_block_stop", "index": 0}
event: message_stop
data: {"type": "message_stop"}
```