← Blog

Claude API Long Context Document Summarization

2026-10-22 · 5 min read · SubToAPI Team

Summarizing long documents with the Claude API

If you're trying to summarize long documents with the Claude API, the short answer is: Claude's large context window (up to 200K tokens depending on model) lets you paste most documents in directly without chunking, but you still need a strategy for documents that exceed the limit, for controlling output length, and for keeping costs predictable. This guide covers both the simple case and the harder edge cases.

Most "how do I summarize a PDF with Claude" questions actually have a one-call answer: convert the document to text, send it in a single message with a clear summarization instruction, and let the long context window do the work. The complexity shows up when documents are genuinely huge (legal contracts, codebases, multi-chapter reports) or when you need structured, consistent output across many documents in a pipeline.

Why long context changes the summarization approach

Before large context windows, document summarization meant splitting text into chunks, summarizing each chunk, then summarizing the summaries ("map-reduce" summarization). This works, but it loses cross-references, repeats boilerplate, and compounds errors at each step.

With Claude's context window, you can often skip map-reduce entirely:

This matters for accuracy: summarizing in one pass means Claude sees the whole document at once and can reference earlier sections when summarizing later ones, which produces more coherent output than independently summarized chunks stitched together.

Basic single-pass summarization

For documents that fit in context, the pattern is straightforward:

curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-opus-4-5",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": "Summarize the following document in 5 bullet points, focused on action items and deadlines:\n\n[DOCUMENT TEXT]"
      }
    ]
  }'

Key points that affect summary quality:

When you do need chunking

Chunking is still necessary when:

A practical chunking approach:

function chunkBySection(text, maxTokensPerChunk = 20000) {
  // split on natural boundaries first: headings, page breaks, paragraphs
  const sections = text.split(/\n#{1,3}\s|\n\n\n/);
  const chunks = [];
  let current = "";

  for (const section of sections) {
    if ((current + section).length / 4 > maxTokensPerChunk) {
      chunks.push(current);
      current = section;
    } else {
      current += section;
    }
  }
  if (current) chunks.push(current);
  return chunks;
}

Summarize each chunk with a prompt that explicitly asks for a dense, information-preserving summary (not a short one), then combine those intermediate summaries in a final pass that produces the actual deliverable. The intermediate summaries should be longer and more detailed than your final output — you're compressing in two stages, not one.

Controlling cost on large-scale summarization

Document summarization is one of the few Claude API use cases where input tokens, not output tokens, dominate cost — a 100K-token contract costs far more to summarize than the 300-token summary it produces. A few practical levers:

If you're building a summarization feature into a product rather than running one-off scripts, routing these calls through SubToAPI gives you a single API key, streaming support for long summaries so users see output as it's generated, and per-request usage metadata so you can see exactly which documents are driving token costs. Setup takes the same shape as a direct integration — see the quickstart and messages docs — but adds team-level visibility into usage across everyone calling the API.

Streaming long summaries

For documents that produce lengthy summaries (multi-page reports summarized into multiple paragraphs), streaming improves perceived latency significantly — users see the first paragraph while the rest is still generating, rather than waiting for the entire response.

const response = 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-opus-4-5",
    max_tokens: 2048,
    stream: true,
    messages: [{ role: "user", content: `Summarize this document section by section:\n\n${documentText}` }]
  })
});

Details on handling the stream are in the streaming docs. If you're comparing plans for a team doing this at volume, the pricing page breaks down Solo, Team, and Scale tiers, and a free trial is available at signup.

Questions

Does Claude's context window mean I never need to chunk documents? No. Chunking is unnecessary for documents under the context limit, but still required for documents that exceed it, or when you need section-level rather than whole-document summaries.

How do I keep summary length consistent across many documents? Specify exact structure in the prompt (word count, bullet count, or section headings) rather than relying on Claude's default judgment, and set max_tokens to match.

What's the biggest cost driver in document summarization? Input tokens from the document itself, not the output summary. Stripping boilerplate and caching repeated instructions reduces cost more than optimizing the summary length.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →