← Blog

Claude API Long Document Summarization Guide

2026-11-16 · 5 min read · SubToAPI Team

Summarizing long documents with the Claude API means solving two problems at once: fitting the content into a context window and getting a summary that actually preserves the important details instead of a generic paraphrase. This guide covers both — how to split, chunk, and reassemble long text, and how to write prompts that produce summaries you can trust for contracts, reports, transcripts, or research papers.

The short answer: for documents under roughly 150k tokens, you can often send the whole thing in a single request to a Claude model with a large context window. For anything larger — multi-hundred-page PDFs, full codebases, long legal filings — you need a chunking strategy, typically map-reduce or hierarchical summarization, combined with careful prompt design to avoid losing detail at each pass.

Step 1: Measure before you chunk

Don't guess at token counts. A rough rule of thumb is 1 token ≈ 4 characters of English text, but that breaks down for tables, code, and non-English text. Before building a pipeline, extract the raw text and count tokens properly so you know whether you're dealing with a single-call problem or a multi-pass problem.

function estimateTokens(text) {
  // crude but useful for a first pass
  return Math.ceil(text.length / 4);
}

If the estimate puts your document comfortably under the model's context window (leaving room for the prompt and the output), skip chunking entirely. Simpler pipelines fail less often.

Step 2: Single-pass summarization for documents that fit

When the whole document fits in one request, the quality of your summary depends almost entirely on prompt structure, not clever tricks. Be explicit about:

curl https://api.subtoapi.app/v1/messages \
  -H "Authorization: Bearer $SUBTOAPI_KEY" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-4",
    "max_tokens": 800,
    "messages": [
      {
        "role": "user",
        "content": "Summarize the attached report in 5 bullet points. Preserve all dates, dollar amounts, and named decisions. Omit introductory boilerplate.\n\n<document>...full text...</document>"
      }
    ]
  }'

Routing this through SubToAPI gives you an HTTPS endpoint with a standard application key (sub_live_...), so this same call works identically whether you're prototyping locally or calling it from a production backend. See /docs/messages for the full request shape.

Step 3: Map-reduce for documents that don't fit

For documents too large for a single call, map-reduce is the most reliable pattern:

  1. Split the document into chunks along natural boundaries — paragraphs, sections, or pages, not arbitrary character counts
  2. Map — summarize each chunk independently with the same prompt
  3. Reduce — combine the chunk summaries into a final summary with a second Claude call
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-sonnet-4",
      max_tokens: 400,
      messages: [{
        role: "user",
        content: `Summarize this section in 3-4 sentences, keeping 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-sonnet-4",
      max_tokens: 1000,
      messages: [{
        role: "user",
        content: `Combine these section summaries into one coherent summary, removing redundancy but keeping every distinct fact:\n\n${combined}`,
      }],
    }),
  });
  const data = await res.json();
  return data.content[0].text;
}

Keep chunk boundaries aligned with content structure — headings, scene breaks, chapter ends — rather than fixed token windows. Splitting mid-sentence or mid-argument is the most common cause of summaries that miss context or contradict each other after the reduce step.

Step 4: Watch for the "lost middle" problem

Even within a single large context window, models tend to weight the beginning and end of a document more heavily than the middle. For long single-pass summaries, mitigate this by:

Step 5: Handle streaming for long outputs

If your summary itself is long — a detailed executive summary of a 200-page report, for example — stream the response so your UI can render progressively instead of waiting on the full generation. This also makes timeouts less likely on slow connections. See /docs/streaming for the event format.

Step 6: Keep costs predictable

Map-reduce pipelines multiply your token usage — you're paying for the chunk summaries and the reduce pass on top of the original content. Track usage per document type so you can estimate cost before running a batch job over, say, a thousand PDFs. A dashboard that shows per-key usage breakdown makes this easier to catch before a bill surprises you; check /pricing for how SubToAPI's Solo, Team, and Scale plans scale with usage, or start a free trial at /signup to test a pipeline against real documents.

Practical checklist

Questions

How many pages can Claude summarize in one API call? It depends on the model's context window and how dense the text is, but as a rough guide, documents up to roughly 300–400 pages of typical prose can often fit in a single call. Beyond that, use map-reduce chunking.

Does chunking a document hurt summary quality? It can, mainly at chunk boundaries where context is split. Minimize this by splitting on natural section breaks and running a reduce pass that explicitly asks the model to remove redundancy while keeping every distinct fact.

Should I use streaming for document summarization? Yes if the output itself is long or you're displaying results in a UI — see /docs/streaming. For short summaries or background batch jobs, a standard non-streaming request via /docs/messages is simpler and fine.

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 →