REST API
Quickstart
Section titled âQuickstartâUpload a document
Section titled âUpload a documentâFirst, upload a PDF using the Files API.
curl -X 'POST' \ 'https://api.cloud.llamaindex.ai/api/v1/files' \ -H 'accept: application/json' \ -H "Authorization: Bearer $LLAMA_CLOUD_API_KEY" \ -F 'upload_file=@/path/to/your/file.pdf;type=application/pdf'Save the returned id as your FILE_ID.
Create a split job
Section titled âCreate a split jobâCreate a split job with your file ID and category definitions:
curl -X 'POST' \ 'https://api.cloud.llamaindex.ai/api/v1/beta/split/jobs' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $LLAMA_CLOUD_API_KEY" \ -d '{ "document_input": { "type": "file_id", "value": "YOUR_FILE_ID" }, "categories": [ { "name": "invoice", "description": "A commercial document requesting payment for goods or services, typically containing line items, totals, and payment terms" }, { "name": "contract", "description": "A legal agreement between parties outlining terms, conditions, obligations, and signatures" } ] }'The response includes the job ID and initial status:
{ "id": "spl-abc123...", "status": "pending"}Poll for job completion
Section titled âPoll for job completionâJobs are processed asynchronously. Poll the status until it reaches completed or failed:
curl -X 'GET' \ 'https://api.cloud.llamaindex.ai/api/v1/beta/split/jobs/YOUR_JOB_ID' \ -H 'accept: application/json' \ -H "Authorization: Bearer $LLAMA_CLOUD_API_KEY"Get the results
Section titled âGet the resultsâWhen the job completes successfully, the response includes the segmentation results:
{ "id": "spl-abc123...", "status": "completed", "result": { "segments": [ { "category": "invoice", "pages": [1, 2, 3], "confidence_category": "high" }, { "category": "contract", "pages": [4, 5, 6, 7, 8], "confidence_category": "high" } ] }}Each segment contains:
category: The assigned category namepages: Array of page numbers (1-indexed) belonging to this segmentconfidence_category: Confidence level (high,medium, orlow)
Advanced Options
Section titled âAdvanced OptionsâAllow uncategorized pages
Section titled âAllow uncategorized pagesâBy default, all pages must be assigned to one of your defined categories. To allow pages that donât match any category to be grouped as uncategorized, use the splitting_strategy option:
curl -X 'POST' \ 'https://api.cloud.llamaindex.ai/api/v1/beta/split/jobs' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $LLAMA_CLOUD_API_KEY" \ -d '{ "document_input": { "type": "file_id", "value": "YOUR_FILE_ID" }, "categories": [ { "name": "invoice", "description": "A commercial document requesting payment for goods or services" } ], "splitting_strategy": { "allow_uncategorized": true } }'With this option, pages that donât match invoice will be grouped into segments with category: "uncategorized".
Using project IDs
Section titled âUsing project IDsâIf youâre working within a specific project, include the project_id query parameter:
curl -X 'POST' \ 'https://api.cloud.llamaindex.ai/api/v1/beta/split/jobs?project_id=YOUR_PROJECT_ID' \ ...Full API Documentation
Section titled âFull API DocumentationâThis is a subset of the available endpoints to help you get started.
You can see all available endpoints in our full API documentation.