Summarization
Extract key sentences and segments from text using prompted extractive summarization.
Endpoint
POST https://api.platform.knowledgator.com/inference/extract/summary/
Headers
| Name | Type | Description |
|---|---|---|
KnowledgatorAPI-Key | String | Your API key |
Content-Type | String | application/json |
KnowledgatorAPI-Model-ID | String | Optional model ID for using a specific fine-tuned model |
Request Body
{
"text": "Your input document here.",
"prompt": "Extract sentences that summarize the main findings.",
"threshold": 0.5
}
Parameters
text(string, required): Input document to summarize.prompt(string, optional): Task instruction to guide what to extract. Examples:"Extract sentences that summarize the main findings.""Extract key parts describing risks and limitations.""Identify the most important conclusions."
threshold(float, optional): Filtering threshold for summary spans. Default: 0.5
Response
{
"outputs": [
{
"text": "The study found significant improvements in accuracy.",
"start": 0,
"end": 56,
"score": 0.91
},
{
"text": "Further research is needed to validate these results.",
"start": 128,
"end": 181,
"score": 0.87
}
]
}
Response Fields
outputs: Array of extracted summary spanstext: Extracted summary span (sentence or segment)start: Character offset (0-based, inclusive)end: Character offset (0-based, exclusive)score: Model confidence that this span is part of the summary
Error Codes
| Status Code | Description |
|---|---|
| 200 | OK – Request successful. |
| 400 | Bad Request – Invalid or incomplete input. |
| 401 | Unauthorized – Invalid API key. |
| 404 | Not Found – Invalid endpoint. |
| 413 | Payload Too Large – Exceeds size limit. |
| 500 | Internal Server Error – Server-side issue. |
Example Usage
SDK Usage
💡 Dedicated SDK Guides: See Python SDK | TypeScript SDK
TypeScript/JavaScript
import { createClient } from '@knowledgator/typescript-sdk';
const kg = createClient('YOUR_API_KEY');
const result = await kg.extract.summary({
text: `
The study examined the effects of climate change on coastal ecosystems.
Researchers found significant coral bleaching in tropical regions.
Temperature increases of 2°C led to 40% habitat loss.
The team recommends immediate conservation efforts.
Further research is needed to validate these results across different regions.
`,
prompt: "Extract the main findings and recommendations.",
threshold: 0.5,
adapter_id: "your-lora-adapter-id" // Optional LoRA adapter
});
for (const span of result.outputs) {
console.log(`[${span.score.toFixed(2)}] ${span.text}`);
}
Python
from knowledgator import Knowledgator
kg = Knowledgator(api_key="YOUR_API_KEY")
result = kg.extract.summary(
text="""
The study examined the effects of climate change on coastal ecosystems.
Researchers found significant coral bleaching in tropical regions.
Temperature increases of 2°C led to 40% habitat loss.
The team recommends immediate conservation efforts.
Further research is needed to validate these results across different regions.
""",
prompt="Extract the main findings and recommendations.",
threshold=0.5,
adapter_id="your-lora-adapter-id" # Optional LoRA adapter
)
for summary_span in result.summary.value:
print(f"[{summary_span.score:.2f}] {summary_span.text}")
Expected SDK Output
[0.91] Researchers found significant coral bleaching in tropical regions.
[0.86] Temperature increases of 2°C led to 40% habitat loss.
[0.84] The team recommends immediate conservation efforts.
Python (requests)
import requests
url = "https://api.platform.knowledgator.com/inference/extract/summary/"
headers = {
"Content-Type": "application/json",
"KnowledgatorAPI-Key": "YOUR_API_KEY",
"KnowledgatorAPI-Model-ID": "your-model-id" # Optional
}
payload = {
"text": """
The study examined the effects of climate change on coastal ecosystems.
Researchers found significant coral bleaching in tropical regions.
Temperature increases of 2°C led to 40% habitat loss.
The team recommends immediate conservation efforts.
Further research is needed to validate these results across different regions.
""",
"prompt": "Extract the main findings and recommendations.",
"threshold": 0.5
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
cURL
curl -X POST https://api.platform.knowledgator.com/inference/extract/summary/ \
-H "Content-Type: application/json" \
-H "KnowledgatorAPI-Key: YOUR_API_KEY" \
-H "KnowledgatorAPI-Model-ID: your-model-id" \
-d '{
"text": "The study examined the effects of climate change on coastal ecosystems. Researchers found significant coral bleaching in tropical regions. Temperature increases of 2°C led to 40% habitat loss. The team recommends immediate conservation efforts. Further research is needed to validate these results across different regions.",
"prompt": "Extract the main findings and recommendations.",
"threshold": 0.5
}'
Expected Response (cURL & requests)
{
"outputs": [
{
"span": "Researchers found significant coral bleaching in tropical regions.",
"start": 82,
"end": 149,
"score": 0.91
},
{
"span": "Temperature increases of 2°C led to 40% habitat loss.",
"start": 154,
"end": 207,
"score": 0.86
},
{
"span": "The team recommends immediate conservation efforts.",
"start": 212,
"end": 263,
"score": 0.84
}
]
}
Additional Information
- Extractive vs Abstractive: This is extractive summarization - it selects existing sentences/spans rather than generating new text
- Prompt Flexibility: The prompt can guide what aspects to focus on (findings, risks, conclusions, etc.)
- Use Cases:
- Document summarization
- Key point extraction
- Meeting notes condensation
- Research paper highlights
- Legal document analysis