POST /document/crop
Returns the cropped and normalized version of a document image — the same preprocessing the xTrakt engine applies before running extraction or classification. Useful when you want to deskew, trim margins, or get a clean image of a scanned page to feed into your own pipeline.
📷 Paste here: screenshot of the Playground → Crop screen on the platform, so the reader can compare the API output with the UI output side by side.
Endpoint
POST https://api-dev.xtrakt.ai/document/crop
Authentication
Send your API key as a Bearer token. See Getting Started for how to generate one.
Authorization: Bearer xtkt_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Request
Content-Type: multipart/form-data
| Field | Type | Required | Description |
|---|---|---|---|
file | file | ✅ | The document or image to crop. |
Constraints
- Allowed extensions:
.pdf,.png,.jpg,.jpeg,.tiff,.tif,.bmp,.doc,.docx. - Max size: 10 MB.
- Rate limit: 50 requests/minute per API key.
Response
200 OK — the envelope's data carries the URLs of the cropped pages stored on the platform. The exact shape is template-engine driven and may include base64 previews depending on tenant configuration:
{
"data": {
"id": "1a2b3c4d-5e6f-7890-1234-567890abcdef",
"metadata": {
"pages": [
{
"pageNumber": 1,
"croppedUrl": "https://storage.googleapis.com/.../crop-1.png",
"width": 1654,
"height": 2339
}
]
},
"createdDate": "2026-05-19T13:55:21Z"
},
"meta": { "httpStatusCode": 200, "messages": [] },
"hasErrors": false
}
Example — curl
curl -X POST "https://api-dev.xtrakt.ai/document/crop" \
-H "Authorization: Bearer xtkt_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-F "file=@./scan.jpg"
Example — Python
import requests
API_KEY = "xtkt_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
BASE_URL = "https://api-dev.xtrakt.ai"
with open("scan.jpg", "rb") as fp:
response = requests.post(
f"{BASE_URL}/document/crop",
headers={"Authorization": f"Bearer {API_KEY}"},
files={"file": ("scan.jpg", fp, "image/jpeg")},
)
response.raise_for_status()
print(response.json()["data"]["metadata"]["pages"])
Example — Node.js
import fs from "node:fs";
const API_KEY = "xtkt_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const BASE_URL = "https://api-dev.xtrakt.ai";
const form = new FormData();
form.append("file", new Blob([fs.readFileSync("./scan.jpg")]), "scan.jpg");
const response = await fetch(`${BASE_URL}/document/crop`, {
method: "POST",
headers: { Authorization: `Bearer ${API_KEY}` },
body: form,
});
const { data } = await response.json();
console.log(data.metadata.pages);
Errors
| HTTP status | Reason |
|---|---|
400 Bad Request | Missing file, empty file, disallowed extension, or file over 10 MB. |
401 Unauthorized | Missing/invalid/revoked API key. |
403 Forbidden | Tenant has no active subscription for the crop capability. |
429 Too Many Requests | API key exceeded the 50 req/min limit. |