Document Parsing - best practices

Quick Recommendations

Use CaseFormatResizeNotes
General Parsing (recommended)WebP 902048/1536px long sideGood balance for most workloads
Tables, financial, high precision docsPNG or JPEG 952048px long sidePreserves fine lines and cell borders

For throughput: resize to 1536px on the long side before sending. Minimal loss in parsing quality while significantly improving throughput.

Resize and Convert

The key operation is thumbnail which resizes in-place while preserving aspect ratio:

PYTHON
1from PIL import Image
2
3IMG_MAX_SIZE = 2048
4
5with Image.open("page.png") as img:
6 img.thumbnail(
7 (IMG_MAX_SIZE, IMG_MAX_SIZE), Image.Resampling.LANCZOS
8 )
9 if img.mode != "RGB":
10 img = img.convert("RGB")
11 img.save("page.webp", format="WEBP", quality=90)

Send a Parse Request

PYTHON
1import os
2import base64
3import cohere
4
5co = cohere.ClientV2(
6 "COHERE_API_KEY"
7) # Get your free API key here: https://dashboard.cohere.com/api-keys
8
9with open("page.webp", "rb") as f:
10 b64 = base64.b64encode(f.read()).decode()
11
12data_uri = f"data:image/webp;base64,{b64}"
13
14response = co.parse(
15 model="parse-v5.0",
16 document={"type": "image_url", "image_url": data_uri},
17)
18
19for page in response.pages:
20 print(page.markdown.content)