Compress Endpoint

Text compression API documentation

Overview

The /compress endpoint compresses text while preserving semantic meaning.

Endpoint Details

  • URL: https://api.tinytoken.org/compress
  • Method: POST
  • Authentication: Required (Bearer token)
  • Content-Type: application/json

API Key

All requests to the /compress endpoint require an API key for authentication. You can obtain your API key by signing up at tinytoken.org. Keep your API key secure and do not share it publicly.

Include your API key in the Authorization header as follows:

Authorization: Bearer your_api_key_here

Authentication

Authorization: Bearer your_api_key_here

Request Parameters

Required

Parameter Type Description
text string Text to compress

Optional

Parameter Type Default Description
quality float null Target similarity score (0.0-1.0). Takes precedence over auto_quality
auto_quality boolean false Automatically calculates quality based on text length
Warning: Quality values above 0.985 are not recommended as they provide minimal compression.

Request Examples

Basic compression

{
  "text": "Your text here..."
}

With auto quality

{
  "text": "Your text here...",
  "auto_quality": true
}

With specific quality

{
  "text": "Your text here...",
  "quality": 0.95
}

Response

200 OK Success

{
  "compressed_text": "hello there how are you doing",
  "original_length": 7,
  "compressed_length": 6,
  "compression_ratio": 0.143,
  "quality_score": 0.96,
  "auto_calculated_quality": 0.954,
  "processing_time_ms": 92
}
Field Type Description
compressed_text string The compressed version of the input text
original_length integer Length of the original text
compressed_length integer Length of the compressed text
compression_ratio float Ratio of compressed length to original length
quality_score float Semantic similarity score between original and compressed text (0-1)
auto_calculated_quality float Quality threshold automatically calculated by the system
processing_time_ms integer Time taken to process the request in milliseconds

Error Responses

400 Bad Request

{
  "error": "Missing required field: text",
  "code": "MISSING_FIELD"
}

Error codes: INVALID_JSON, MISSING_FIELD, TEXT_TOO_LONG, EMPTY_TEXT

401 Unauthorized

{
  "error": "Invalid API key",
  "code": "INVALID_AUTH"
}

500 Internal Server Error

{
  "error": "Error details",
  "code": "INTERNAL_ERROR"
}

Usage Examples

cURL

curl -X POST https://api.tinytoken.org/compress \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your_api_key_here" \
  -d '{"text": "Your text here...", "auto_quality": true}'

Python

import requests

response = requests.post('https://api.tinytoken.org/compress',
    headers={
        'Content-Type': 'application/json',
        'Authorization': 'Bearer your_api_key_here'
    },
    json={
        'text': 'Your text here...',
        'auto_quality': True
    }
)

result = response.json()
print(result)