Summarization
Turn long text — reviews, docs, threads — into short summaries your users can scan.
Summarization condenses long text into something quick to read: summarize a support thread, a set of reviews, or a long article.
Control the output
Tell Claude the format you want: a one-line summary, three bullet points, or a short paragraph. Consistent format makes summaries easy to display in your UI.
Long inputs
Claude models have large context windows, so you can pass substantial text in one request. For very long or repeated content, prompt caching (a later lesson) keeps costs down.
Example
async function summarizeReviews(reviews) {
const res = await client.messages.create({
model: "claude-opus-4-8",
max_tokens: 400,
messages: [{
role: "user",
content: `Summarize these customer reviews.\n` +
`Return exactly 3 bullet points: the top praise, the top complaint, ` +
`and one suggestion.\n\n${reviews.join("\n---\n")}`,
}],
});
return res.content.find((b) => b.type === "text")?.text ?? "";
}When to use it
- Summarise a long support thread into three bullet points so agents can quickly understand context before replying.
- Condense a 10-page terms-of-service document into a plain-language summary for non-technical users.
- Auto-generate a TL;DR for each blog post and display it above the fold to reduce bounce rate.
More examples
Summarise a support thread
Formats the thread as labelled lines so Claude can attribute each point, then asks for a bullet-point summary.
async function summariseThread(messages) {
const thread = messages.map(m => `[${m.author}]: ${m.body}`).join("\n");
const msg = await client.messages.create({
model: "claude-haiku-4-5",
max_tokens: 128,
system: "Summarise in 3 bullet points. Be concise and factual.",
messages: [{ role: "user", content: `Summarise this thread:\n${thread}` }],
});
return msg.content[0].text;
}Tiered summary for long documents
Asks for three levels of summary in one call — TL;DR, bullets, and action items — to serve different reader needs.
async function tieredSummary(text) {
const msg = await client.messages.create({
model: "claude-sonnet-4-5",
max_tokens: 512,
messages: [{
role: "user",
content: `Given this document, provide:\n1. A one-sentence TL;DR\n2. A 3-bullet summary\n3. Key action items\n\nDocument:\n${text.slice(0, 8000)}`
}],
});
return msg.content[0].text;
}Summarise product reviews
Includes star ratings in the text so Claude can weight sentiment and separate praise from complaints.
async function summariseReviews(reviews) {
const joined = reviews.map((r, i) => `Review ${i+1} (${r.rating}/5): ${r.text}`).join("\n");
const msg = await client.messages.create({
model: "claude-haiku-4-5",
max_tokens: 200,
system: "Summarise customer sentiment. Note top praise and top complaints.",
messages: [{ role: "user", content: joined }],
});
return msg.content[0].text;
}
Discussion