Skip to content
Guide
Parse
Guides

Recipes

Short, copy-pasteable Parse snippets for common workflows — retries, S3 uploads, webhooks, multi-language OCR, page ranges, pandas tables, multimodal screenshots.

Short, copy-pasteable snippets for the patterns Parse users hit most often. Each recipe is ~10-20 lines and answers a specific “how do I do X?” question. Drop them into your project and adapt as needed.

For full walk-throughs, see the Parse Examples tutorials. For the full API reference, see the REST API Guide.

Set your API key once so the SDKs and CLI pick it up automatically:

Terminal window
export LLAMA_CLOUD_API_KEY="llx-..."

Every recipe below assumes you’ve constructed a client and uploaded a file:

Terminal window
pip install "llama-cloud>=2.8"
from llama_cloud import LlamaCloud
client = LlamaCloud() # reads LLAMA_CLOUD_API_KEY from the environment
file = client.files.create(file="doc.pdf", purpose="parse")

The bare minimum: upload a file, parse it, print the markdown.

result = client.parsing.parse(
file_id=file.id,
tier="agentic",
version="latest",
expand=["markdown"],
)
print(result.markdown.pages[0].markdown)

Use a dated version so model updates can’t change your output without your knowledge.

result = client.parsing.parse(
file_id=file.id,
tier="agentic",
version="2026-04-06", # pin a specific date
expand=["markdown"],
)

See Tiers → Versioning and reproducibility for the latest available dates.

Skip irrelevant pages and save credits.

result = client.parsing.parse(
file_id=file.id,
tier="agentic",
version="latest",
page_ranges={"target_pages": "1,3,5-10"}, # 1-indexed
expand=["markdown"],
)

You can also cap the total with max_pages (--page-ranges.max-pages on the CLI).

Strip a fixed margin off the top and bottom of every page before parsing.

result = client.parsing.parse(
file_id=file.id,
tier="agentic",
version="latest",
crop_box={"top": 0.08, "bottom": 0.08, "left": 0, "right": 0},
expand=["markdown"],
)

Values are page-height/width ratios (0.0–1.0).

Hint the OCR engine for non-English documents.

result = client.parsing.parse(
file_id=file.id,
tier="agentic",
version="latest",
processing_options={
"ocr_parameters": {"languages": ["en", "fr", "de"]},
},
expand=["markdown"],
)

Save money on long mixed-complexity documents

Section titled “Save money on long mixed-complexity documents”

Enable Cost Optimizer to route simple pages to cost_effective automatically, then read the per-page metadata to see which pages got the cheaper tier.

result = client.parsing.parse(
file_id=file.id,
tier="agentic_plus",
version="latest",
processing_options={
"cost_optimizer": {"enable": True},
},
expand=["markdown", "metadata"],
)
# See which pages got the cheaper tier
for page in result.metadata.pages:
flag = "cost-optimized" if page.cost_optimized else "premium"
print(f"page {page.page_number}: {flag}")

See Cost Optimizer.

Tell the agentic model what to focus on.

result = client.parsing.parse(
file_id=file.id,
tier="agentic",
version="latest",
agentic_options={
"custom_prompt": "This is a financial 10-K. Preserve currency symbols on every number and keep the original section hierarchy.",
},
expand=["markdown"],
)

See Custom Prompt for prompt-engineering tips.

Get structured items, walk for tables, load into a dataframe. The table-to-dataframe step is Python + pandas — for how to fetch the items tree in TypeScript, Go, Java, or the CLI, see Retrieving Results → Markdown plus the structured items tree.

import io
import pandas as pd
result = client.parsing.parse(
file_id=file.id,
tier="agentic",
version="latest",
expand=["items"],
)
# Find the first table on page 3 and load it
page = result.items.pages[2] # 0-indexed in the items tree
table = next(item for item in page.items if getattr(item, "type", None) == "table")
df = pd.read_csv(io.StringIO(table.csv))
print(df.head())

For an end-to-end version with charts, see the Parse Charts in PDFs and Analyze with Pandas tutorial.

Get per-page screenshots for a multimodal pipeline

Section titled “Get per-page screenshots for a multimodal pipeline”

Save full-page screenshots and list their presigned download URLs alongside a markdown blob for the LLM.

result = client.parsing.parse(
file_id=file.id,
tier="agentic",
version="latest",
output_options={"images_to_save": ["screenshot"]},
expand=["markdown_full", "images_content_metadata"],
)
# One big markdown blob for the LLM
markdown_blob = result.markdown_full
# Each page screenshot as a downloadable URL
for image in result.images_content_metadata.images:
print(f"{image.filename}: {image.presigned_url}")

Each presigned_url is a plain HTTP GET away from the image bytes. In Python:

import requests
for image in result.images_content_metadata.images:
img_bytes = requests.get(image.presigned_url).content
with open(image.filename, "wb") as f:
f.write(img_bytes)

Push results to a webhook instead of polling

Section titled “Push results to a webhook instead of polling”

For long-running jobs, let Parse call you back when the job finishes.

result = client.parsing.parse(
file_id=file.id,
tier="agentic_plus",
version="latest",
webhook_configurations=[
{
"webhook_url": "https://your-app.com/parse-callback",
"webhook_headers": {"X-My-Auth": "secret"},
}
],
expand=["markdown"],
)
print(f"Job started: {result.job.id}")

When the job finishes, Parse POSTs an event notification to your URL. See Webhook Configurations.

Retrieve results later (without re-parsing)

Section titled “Retrieve results later (without re-parsing)”

Run the job once, fetch additional fields later by job_id.

# Step 1 — parse with a minimal expand
result = client.parsing.parse(
file_id=file.id,
tier="agentic",
version="latest",
expand=["markdown"],
)
job_id = result.job.id
# Step 2 — later, in another script, get the items tree for the same job
items_result = client.parsing.get(job_id=job_id, expand=["items"])
for page in items_result.items.pages:
print(f"page {page.page_number}: {len(page.items)} items")

See Retrieving Results for every legal expand value.

If a parse job fails on agentic_plus (e.g. for an unusual layout), retry on agentic, then cost_effective.

def parse_with_fallback(file_id):
for tier in ["agentic_plus", "agentic", "cost_effective"]:
try:
return client.parsing.parse(
file_id=file_id,
tier=tier,
version="latest",
expand=["markdown"],
)
except Exception as e:
print(f"tier {tier} failed: {e}")
raise RuntimeError("all tiers failed")
result = parse_with_fallback(file.id)

Skip cached results when you need a deterministic re-parse (e.g. after a tier version change).

result = client.parsing.parse(
file_id=file.id,
tier="agentic",
version="2026-04-06",
disable_cache=True,
expand=["markdown"],
)

See Cache Control.

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/