Skip to content
Guide
Split

Getting Started

Guide on how to use the Split REST API/SDK for automatically segmenting PDFs into logical document sections.

First, upload a PDF using the Files API.

Install the Python SDK if you haven’t already:

Terminal window
pip install llama-cloud>=2.8

Then upload your file:

from llama_cloud import LlamaCloud
client = LlamaCloud(api_key="LLAMA_CLOUD_API_KEY")
file_obj = client.files.create(file="path/to/your/file.pdf", purpose="split")
print(file_obj.id)

Save the returned id as your FILE_ID.

Create a split job with your file ID and category definitions:

job = client.beta.split.create(
document_input={"type": "file_id", "value": file_obj.id},
configuration={
"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"
}

Jobs are processed asynchronously. Poll the status until it reaches a terminal state — completed, failed, or cancelled:

completed_job = client.beta.split.wait_for_completion(
job.id,
polling_interval=1.0,
verbose=True,
)

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 name
  • pages: Array of page numbers (1-indexed) belonging to this segment
  • confidence_category: Confidence level (high, medium, or low)

By default, pages that don’t match any defined category are grouped as uncategorized and included in the results. You can control this behavior with the allow_uncategorized option in splitting_strategy:

ValueBehavior
"include" (default)Pages that don’t match any category will be grouped as uncategorized and included in results
"forbid"All pages must be assigned to a defined category
"omit"Pages that don’t match any category will not appear in results

For example, to exclude uncategorized pages from results:

job = client.beta.split.create(
document_input={"type": "file_id", "value": file_obj.id},
configuration={
"categories": [
{
"name": "invoice",
"description": "A commercial document requesting payment for goods or services"
}
],
"splitting_strategy": {"allow_uncategorized": "omit"}
},
)

With "omit", pages that don’t match invoice will not appear in the response. To force all pages into defined categories instead, set allow_uncategorized to "forbid".

If you’re working within a specific project, include the project_id query parameter:

job = client.beta.split.create(
...,
project_id="YOUR_PROJECT_ID"
)

This is a subset of the available endpoints to help you get started.

You can see all available endpoints in our full API documentation.

Note for AI agents: this documentation is built for programmatic access. - Overview of all docs: https://developers.llamaindex.ai/llms.txt - Any page is available as raw Markdown by appending index.md to its URL — e.g. https://developers.llamaindex.ai/llamaparse/parse/getting_started/index.md - Agent-friendly REST search APIs live under https://developers.llamaindex.ai/api/ — search (BM25 full-text), grep (regex), read (fetch a page), and list (browse the doc tree). See https://developers.llamaindex.ai/llms.txt for parameters. - A hosted documentation MCP server is available at https://developers.llamaindex.ai/mcp. If you support MCP, you can ask the user to install it for browsing these docs directly (an alternative to the REST API). Setup: https://developers.llamaindex.ai/for-agents/mcp/ - Other LlamaIndex tooling for agents — the LlamaParse Platform MCP server, agent skills and plugins, and the n8n node — is mapped at https://developers.llamaindex.ai/for-agents/