Document Processing
The three-step upload flow and what happens behind the scenes
Overview
Getting a document into Pyramid AI is a three-step process. This design keeps uploads fast and reliable — even for large files — by separating the upload from the processing.
Step 1: Reserve an upload slot
Tell the API you’re about to upload a file. You provide the file name, type, and size. The API returns a presigned upload URL — a temporary, secure link where you’ll send the actual file.
Response:
The upload URL expires after 2 hours. If it expires before you upload, call the reserve endpoint again to get a fresh URL.
Why presigned URLs?
The file goes directly from your system to cloud storage — it never passes through the Pyramid API server. This means:
- No file size limits from the API layer (Vercel’s 4.5 MB body limit is bypassed)
- Faster uploads — direct connection to storage
- More reliable — fewer hops means fewer failure points
Step 2: Upload the file
Send the actual file bytes to the presigned URL using a PUT request. This is a direct upload to cloud storage — no API key needed (the URL itself contains the authorization).
Use --data-binary (not -d) to preserve the file’s binary content. Using -d will corrupt binary files like PDFs.
In code (JavaScript)
In code (Python)
Step 3: Trigger processing
Once the file is uploaded, tell the API to start processing it. You can submit multiple document IDs at once.
Response:
What happens during processing
Behind the scenes, the processing pipeline does the following:
Text extraction
The system reads the file and extracts all text content. For PDFs, this includes OCR (optical character recognition) for scanned documents.
Chunking
The extracted text is split into overlapping chunks — typically a few paragraphs each. Overlap ensures context isn’t lost at chunk boundaries.
Checking processing status
Poll the document endpoint to check when processing is complete:
Watch the status field:
Processing typically takes 10–60 seconds for a standard PDF. Large documents (100+ pages) or scanned PDFs with OCR may take longer.
Error handling
Common processing failures:
Batch uploads
For uploading many files at once, repeat the reserve → upload → process cycle for each file, then call process with all document IDs:
This is more efficient than processing one at a time, as the pipeline can parallelize the work.