Need to condense long text into concise summaries? This guide covers everything you need to know about text summarization via API, including summarization types, length control, and implementation examples.
What is Text Summarization?
Text summarization is the process of creating a shorter version of a document while preserving its key information and meaning. It helps readers quickly understand the main points without reading the entire text.
A good summary captures the essential information: who, what, when, where, why, and how.
Types of Summarization
There are two main approaches to text summarization:
| Type | Description | Pros |
|---|---|---|
| Extractive | Selects and combines existing sentences | Faithful to source, no hallucination |
| Abstractive | Generates new text paraphrasing the content | More natural, better compression |
Using the Summarization API
TinyFn provides an endpoint to summarize text:
POST https://api.tinyfn.io/v1/summarize
Headers: X-API-Key: your-api-key
Content-Type: application/json
{
"text": "Your long article or document text goes here. It can be multiple paragraphs covering various topics...",
"max_length": 100,
"type": "extractive"
}
{
"summary": "A concise summary of the main points from your text, capturing the essential information.",
"original_length": 500,
"summary_length": 85,
"compression_ratio": "83%",
"type": "extractive"
}
Parameters
| Parameter | Type | Description |
|---|---|---|
text |
string | Text to summarize (required) |
max_length |
integer | Maximum summary length in words (default: 100) |
type |
string | Summarization type: extractive or abstractive (default: extractive) |
sentences |
integer | Target number of sentences (alternative to max_length) |
Code Examples
JavaScript / Node.js
const response = await fetch('https://api.tinyfn.io/v1/summarize', {
method: 'POST',
headers: {
'X-API-Key': 'your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
text: longArticleContent,
max_length: 50,
type: 'abstractive'
})
});
const data = await response.json();
console.log('Summary:', data.summary);
console.log(`Compressed from ${data.original_length} to ${data.summary_length} words`);
Python
import requests
def summarize_text(text, max_length=100, summary_type='extractive'):
response = requests.post(
'https://api.tinyfn.io/v1/summarize',
json={
'text': text,
'max_length': max_length,
'type': summary_type
},
headers={'X-API-Key': 'your-api-key'}
)
return response.json()
# Summarize a long document
with open('document.txt', 'r') as f:
document = f.read()
result = summarize_text(document, max_length=150)
print(result['summary'])
cURL
curl -X POST "https://api.tinyfn.io/v1/summarize" \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"text": "Your long text here...", "max_length": 50}'
Common Use Cases
- News Digests: Create brief summaries of news articles
- Document Preview: Show article excerpts in listings
- Email Summaries: Summarize long email threads
- Meeting Notes: Condense transcripts into key points
- Research: Quickly understand paper abstracts
Best Practices
- Clean input: Remove irrelevant content before summarizing
- Choose appropriate length: Balance brevity with completeness
- Review summaries: Automated summaries may miss nuance
- Consider your audience: Technical vs. general audience needs differ
Try the Text Summarization API
Get your free API key and start summarizing text in seconds.
Get Free API Key