BLUF: SmartSlim Server provides a RESTful API with 4 main interfaces — upload compression, batch compression, status query, and callback notification — supporting API Key and Bearer Token authentication. Single-file upload compression of a 100MB PDF completes in about 8s, and batch compression of 100 files takes about 12s. Default rate limit is 60 requests per minute, with Enterprise edition supporting up to 300. This article provides parameter reference tables for all 4 interfaces, Python/JavaScript/curl examples, and error handling strategies. Below, we start with an API overview and detail each interface.
If you need local SDK integration instead of HTTP API calls, we recommend readingCompression SDK Integration Guide: Python/Java/C# Multi-Language Calls。
1. API Overview
SmartSlim Server's RESTful API is built on the FastAPI framework. All interfaces return JSON data and support multipart/form-data file uploads. The API base path is /api/v1/, and all requests must include authentication information.
| Interface | Method | Path | Function | Sync/Async |
|---|---|---|---|---|
| Upload Compression | POST | /api/v1/compress | Upload single file and compress | Sync (<50MB) / Async |
| Batch Compression | POST | /api/v1/compress/batch | Batch upload multiple files and compress | Async |
| Status Query | GET | /api/v1/status/{task_id} | Query compression task status | Sync |
| Callback Notification | POST | Client callback URL | Active notification after compression | Async push |
Authentication has two methods: API Key for server-side calls, Bearer Token for frontend calls. The table below compares the two.
| Auth Method | Header | Validity | Use Case | Security |
|---|---|---|---|---|
| API Key | X-API-Key: your-key | Permanent (revocable) | Server-side calls | Medium (requires HTTPS) |
| Bearer Token | Authorization: Bearer token | 24 hours | Frontend calls | High (short-term validity) |
2. Interface Parameter Reference
1. Upload Compression Interface
The upload compression interface receives a single file and returns compression results. Files under 50MB synchronously return a download link for the compressed file; files over 50MB asynchronously return a task ID.
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
| file | multipart/file | Yes | - | File to compress |
| format | string | No | Auto-detect | File type (pdf/image/ofd) |
| level | string | No | medium | Compression level (low/medium/high/ultra) |
| quality | integer | No | 75 | Quality factor (1-100) |
| callback_url | string | No | - | Async callback URL |
2. Batch Compression Interface
The batch compression interface receives multiple files, processes them asynchronously, and returns a batch task ID. Supports specifying concurrency, with maximum concurrency limited by license.
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
| files | multipart/file[] | Yes | - | File list to compress (max 100) |
| level | string | No | medium | Compression level |
| quality | integer | No | 75 | Quality factor |
| workers | integer | No | 4 | Concurrency (1-16) |
| callback_url | string | No | - | Completion callback URL |
3. Status Query Interface
The status query interface retrieves the current status and results of an async compression task via task ID.
| Return Field | Type | Description |
|---|---|---|
| task_id | string | Unique task identifier |
| status | string | Status (pending/processing/completed/failed) |
| progress | integer | Progress percentage (0-100) |
| download_url | string | Compressed result download link (when complete) |
| original_size | integer | Original file size (bytes) |
| compressed_size | integer | Compressed size (bytes) |
| error | string | Error message (on failure) |
3. Code Examples in Three Languages
Below are call examples in curl, Python, and JavaScript, all demonstrating upload compression of a single PDF file.
| Language | Core Code | Description |
|---|---|---|
| curl | curl -X POST -H "X-API-Key: key" -F "file=@doc.pdf" -F "level=medium" http://localhost:8000/api/v1/compress | Command-line call |
| Python | requests.post(url, headers={"X-API-Key":key}, files={"file":open("doc.pdf","rb")}, data={"level":"medium"}) | requests library |
| JavaScript | fetch(url, {method:"POST", headers:{"X-API-Key":key}, body:formData}) | Fetch API |
4. Rate Limiting and Error Handling
The API has comprehensive rate limiting and error handling mechanisms. Understanding HTTP status codes and error codes is essential for writing robust calling code.
| HTTP Status | Error Code | Meaning | Handling |
|---|---|---|---|
| 200 | - | Success | Parse response data |
| 400 | INVALID_PARAM | Invalid parameter | Check request parameters |
| 401 | UNAUTHORIZED | Authentication failed | Check API Key/Token |
| 413 | FILE_TOO_LARGE | File too large | Use chunked upload |
| 429 | RATE_LIMITED | Rate limited | Exponential backoff retry |
| 500 | INTERNAL_ERROR | Server error | Retry or contact support |
| 503 | SERVICE_UNAVAILABLE | Service unavailable | Retry after waiting |
Rate limiting details: default 60 requests per minute, 10 concurrent per second; Enterprise edition 300 per minute, 30 concurrent per second. Exceeding limits returns 429, with response headers containing X-RateLimit-Remaining (remaining count) and X-RateLimit-Reset (reset timestamp). Clients should implement exponential backoff retry: wait 1s after receiving 429, then 2s, then 4s, with a maximum of 3 retries.
| File Type | Original Size | Compressed Size | Compression Time | Ratio |
|---|---|---|---|---|
| PDF (scanned) | 80MB | 8.2MB | 6.5s | 89.8% |
| PDF (digital) | 15MB | 3.1MB | 1.2s | 79.3% |
| JPEG image | 12MB | 2.8MB | 0.8s | 76.7% |
| PNG image | 25MB | 6.5MB | 1.5s | 74.0% |
| OFD document | 30MB | 5.2MB | 2.0s | 82.7% |
If you need to understand the underlying design of compression task queues, seeCompression Task Queue Design. If you need to deploy API services via Docker, seeDocker Compression Service Deployment。
5. FAQ
Q1: How to authenticate compression API calls?
SmartSlim Server's compression API supports two authentication methods: API Key authentication (pass the key in the X-API-Key header, suitable for server-side calls) and Bearer Token authentication (pass a JWT Token in the Authorization header, suitable for frontend calls). API Keys are permanent but can be revoked at any time, while Tokens are valid for 24 hours and require periodic refresh. For production environments, API Key is recommended for its simplicity and reliability.
Q2: Which file formats does the compression API support?
SmartSlim Server API supports PDF, images (jpg/jpeg/tif), and OFD formats, with a 1GB single-file limit. SmartSlim Cloud API supports all 10 categories and 40+ formats (including video, audio, Office documents, etc.), with a 10GB single-file limit. Specify the file type via the format parameter when calling; if omitted, it is auto-detected. Note that the Server edition only supports PDF/image/OFD; full format support requires the Cloud edition.
Q3: Does the compression API have rate limits?
Rate limiting protects service stability. Default limits: 60 requests per minute, 10 concurrent per second. Exceeding limits returns a 429 status code, with response headers containing X-RateLimit-Remaining and X-RateLimit-Reset fields. Enterprise edition can be increased to 300 requests per minute and 30 concurrent per second. Clients are recommended to implement exponential backoff retry — wait 1-2-4 seconds incrementally after receiving 429.
Q4: How does the compression API handle large files?
For large files (over 50MB), use the chunked upload interface — split the file into multiple 5MB chunks, upload all, then notify to merge and compress. After compression completes, retrieve results via callback notification or polling the status query interface. Large file compression is asynchronous and does not block API calls. A 100MB PDF takes about 8s, a 1GB video takes about 90s, and a download link is automatically generated upon completion.
Summary
SmartSlim Server's RESTful API provides 4 main interfaces — upload compression, batch compression, status query, and callback notification — covering all scenarios from single files to batch processing. Two authentication options: API Key for server-side, Bearer Token for frontend. Clear rate limiting: default 60 per minute, Enterprise 300, with 429 status code and exponential backoff retry. An 80MB scanned PDF compresses to 8.2MB in just 6.5s, a 89.8% compression ratio.
Remember three points: first, files under 50MB return results synchronously, while larger files use async task IDs for querying; second, implement exponential backoff retry for 429 rate limits — don't just retry aggressively; third, use the chunked upload interface for large files, splitting into 5MB chunks. With the right interface and parameters, compression API calls are straightforward. If you prefer local SDK integration over HTTP calls, see the Compression SDK Integration Guide.
Related Articles
Need to Compress Files? Try SmartSlim
Built on a self-developed Rust compression engine, supporting 10 categories and 40+ formats including PDF, images, video, Office, and OFD, with local compression that keeps your data on-premises.