Claude API Summarization for Long Documents
Summarizing Long Documents with the Claude API
If you're trying to summarize a 50-page contract, a multi-hour meeting transcript, or a stack of research papers, the main obstacle isn't Claude's summarization quality — it's the document's length relative to the model's context window. Claude 3 and 3.5 models support context windows up to 200K tokens, which handles most single documents, but you still need a strategy for documents that exceed that limit, for controlling cost on large inputs, and for keeping summaries consistent across sections.
This guide covers the practical techniques: when to send the whole document in one call, when to chunk and use map-reduce summarization, how to structure prompts for better output, and how to handle streaming and retries so summarization jobs don't silently fail on large batches.
Single-Pass Summarization: When It's Enough
If your document fits comfortably within the context window (leaving room for the output), a single-pass call is simpler and produces more coherent summaries because the model sees everything at once.
curl https://api.subtoapi.app/v1/messages \
-H "Authorization: Bearer $SUBTOAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Summarize the following document in 5 bullet points, focusing on decisions and action items:\n\n<document text here>"
}
]
}'
A few practical notes:
- Leave headroom. A 200K-token window doesn't mean you should send 199K tokens of input — you need space for the output and for the model to "think" through the structure of a long summary.
- Be specific about output format. "Summarize this" produces vague prose. "Summarize in 5 bullet points covering decisions, risks, and open questions" produces something usable.
- Ask for extraction, not just compression. For contracts or reports, request named entities, dates, and figures explicitly — Claude will surface them more reliably if you ask by name.
Map-Reduce Summarization for Documents That Don't Fit
When a document exceeds the context window — or when you want section-level summaries before a final rollup — use a map-reduce pattern:
- Split the document into chunks, ideally along natural boundaries (headings, pages, speaker turns) rather than fixed character counts.
- Map: summarize each chunk independently.
- Reduce: feed all chunk summaries back into Claude for a final synthesis pass.
async function summarizeChunk(text) {
const res = await fetch("https://api.subtoapi.app/v1/messages", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "claude-3-5-sonnet-20241022",
max_tokens: 512,
messages: [{
role: "user",
content: `Summarize this section in 3-4 sentences, preserving any numbers, names, and dates:\n\n${text}`
}]
})
});
const data = await res.json();
return data.content[0].text;
}
async function reduceSummaries(summaries) {
const combined = summaries.join("\n\n");
const res = await fetch("https://api.subtoapi.app/v1/messages", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "claude-3-5-sonnet-20241022",
max_tokens: 1024,
messages: [{
role: "user",
content: `These are summaries of sequential sections of one document. Produce one coherent executive summary that removes redundancy and keeps chronological order:\n\n${combined}`
}]
})
});
const data = await res.json();
return data.content[0].text;
}
This pattern scales to arbitrarily long inputs because each map call is independent — you can parallelize chunk summarization and only serialize the final reduce step. Full request and response shapes are in the messages docs.
Chunking Strategy Matters More Than Chunk Size
A common mistake is splitting purely by token count, which can cut a sentence or a legal clause in half mid-thought. Better approaches:
- Split on headings or page breaks for structured documents.
- Split on speaker changes or timestamps for transcripts.
- Add 1-2 sentences of overlap between chunks so context isn't lost at the boundary.
- Pass a short "previous context" note into each map call (e.g., "This section follows a discussion about pricing") so chunk summaries stay coherent when reduced.
Handling Cost and Latency on Large Batches
Map-reduce summarization multiplies your request count, which matters for both cost and rate limits. A few things that help in production:
- Use streaming for the reduce step so your app can display the summary as it's generated rather than waiting on the full response — see streaming for implementation details.
- Cap max_tokens on map calls tightly (section summaries don't need 1000+ tokens) to reduce cost and latency per chunk.
- Batch and parallelize map calls with a concurrency limit (5-10 concurrent requests is usually safe) rather than sending them all at once.
- Track usage per document type. If you're summarizing contracts for multiple clients or teams, SubToAPI's dashboard gives you per-key usage metadata so you can see which document pipelines are consuming the most tokens without building your own logging layer.
If you're running this as a product feature — a document upload tool, a transcript summarizer, a research digest — you need an API layer that handles auth, rate limits, and usage tracking without you building it from scratch. SubToAPI turns your Claude access into a standard HTTPS API with scoped sub_live_ keys per application, so you can issue a separate key for your summarization service and see its token usage independently from the rest of your stack. Start with the quickstart or check pricing if you're evaluating plans for a team.
Prompt Patterns Worth Reusing
A few prompt templates that consistently work well for document summarization:
- Executive summary + detail: "Give me a 3-sentence executive summary, then a detailed breakdown by section."
- Extractive first pass: "List every date, dollar figure, and named party mentioned, then summarize."
- Audience-specific: "Summarize this for a non-technical stakeholder who needs to approve the budget, not the technical details."
- Structured output: Ask for JSON (
{"summary": "...", "key_points": [...], "risks": [...]}) when you need to pipe the result into another system — see tools if you want Claude to call a function with structured summary data instead of parsing free text.
Questions
Does Claude's context window mean I never need to chunk documents? No. Claude 3.5 models support up to 200K tokens, which covers most single documents, but you still need headroom for output tokens, and anything longer (books, large transcript archives) requires chunking regardless of window size.
Is map-reduce summarization worse quality than a single pass? It can lose some cross-section nuance, but with good chunk boundaries and a strong reduce prompt, quality is close to single-pass for most business documents. The main tradeoff is more API calls, not lower accuracy.
How do I keep summarization costs predictable at scale? Cap max_tokens per request, cache chunk summaries if documents don't change, and track token usage per key — SubToAPI's dashboard shows per-application usage so you can monitor a summarization pipeline's cost separately from other integrations.