📖 API Documentation

Everything you need to integrate AI-powered text summarization into your application.

🚀 Quick Start

Get started in under 5 minutes:

1. Get your API key

Sign up for free at /pricing to get your API key instantly.

2. Make your first request

curl -X POST https://api.textsummarize.io/api/summarize \\
  -H "Content-Type: application/json" \\
  -H "X-API-Key: your-api-key-here" \\
  -d '{
    "text": "Your long article or document text here...",
    "maxLength": 3
  }'

3. Get your summary

{
  "success": true,
  "data": {
    "original_length": 1250,
    "summary_length": 320,
    "compression_ratio": 26,
    "summary": "The condensed version of your text...",
    "sentence_count": 3
  },
  "usage": {
    "used": 1,
    "limit": 100,
    "remaining": 99
  }
}

🔐 Authentication

All API requests require an API key passed in the X-API-Key header.

curl -H "X-API-Key: ts_yourapikey123" ...
⚠️ Keep your API key secret! Never expose it in client-side code. Use environment variables and proxy requests through your backend.

📡 Endpoints

POST /api/summarize

Summarize text using AI-powered extractive summarization.

Request Headers

Header Value Required
X-API-Key Your API key Required
Content-Type application/json Required

Request Body

Parameter Type Description Required
text string The text to summarize (50-50,000 characters) Required
maxLength integer Maximum number of sentences in summary (1-10, default: 3) Optional
minLength integer Minimum number of sentences (default: 1) Optional

Response

{
  "success": true,
  "data": {
    "original_length": 1250,
    "summary_length": 320,
    "compression_ratio": 26,
    "summary": "The condensed version of your text...",
    "sentence_count": 3
  },
  "usage": {
    "used": 42,
    "limit": 10000,
    "remaining": 9958
  }
}

Check Usage

GET /api/usage

Check your current API usage and remaining quota.

curl https://api.textsummarize.io/api/usage \\
  -H "X-API-Key: ts_yourapikey123"

Health Check

GET /health

No authentication required. Check API status.

curl https://api.textsummarize.io/health

⚠️ Error Handling

The API uses standard HTTP status codes:

Status Meaning
200 Success
400 Bad request (invalid input)
401 Unauthorized (missing or invalid API key)
429 Rate limit exceeded (upgrade your plan)
500 Server error

Error responses include a message:

{
  "error": "Usage limit exceeded",
  "message": "You have reached your monthly API call limit",
  "upgrade": "/pricing"
}

💡 Best Practices

✅ Use environment variables
Store your API key as SUMMARIZE_API_KEY in your environment.
✅ Handle errors gracefully
Always check for error responses and implement retry logic for 429/500 errors.
✅ Batch processing
For multiple texts, send them sequentially. Each call counts toward your quota.
⚠️ Rate limiting
If you hit rate limits, consider upgrading your plan. Requests that exceed your quota return 429 status.

🔗 Code Examples

JavaScript / Node.js

const summarize = async (text) => {
  const response = await fetch('https://api.textsummarize.io/api/summarize', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-Key': process.env.SUMMARIZE_API_KEY,
    },
    body: JSON.stringify({ text, maxLength: 3 }),
  });
  const data = await response.json();
  return data.data.summary;
};

Python

import requests
import os

def summarize(text):
    response = requests.post(
        'https://api.textsummarize.io/api/summarize',
        headers={
            'Content-Type': 'application/json',
            'X-API-Key': os.environ['SUMMARIZE_API_KEY'],
        },
        json={'text': text, 'maxLength': 3}
    )
    return response.json()['data']['summary']

PHP

<?php
function summarize($text) {
    $ch = curl_init('https://api.textsummarize.io/api/summarize');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['text' => $text]));
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Content-Type: application/json',
        'X-API-Key: ' . getenv('SUMMARIZE_API_KEY'),
    ]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = json_decode(curl_exec($ch), true);
    return $response['data']['summary'];
}

Ready to get started?

View Pricing Plans →