Document Parsing - quickstart

About the Parse API

Cohere’s Parse model converts unstructured enterprise documents (PDFs, images, slides) into structured Markdown output. It extracts text, tables, lists, forms, images, captions, and bounding box coordinates.

This quickstart guide shows you how to parse a document image with the Parse endpoint.

1

Setup

First, install the Cohere Python SDK with the following command.

$pip install -U cohere

Next, import the library and create a client.

PYTHON
1import cohere
2
3co = cohere.ClientV2(
4 "COHERE_API_KEY"
5) # Get your free API key here: https://dashboard.cohere.com/api-keys
2

Prepare the Document

Parse accepts documents as base64-encoded data URIs. Convert your image to a data URI.

PYTHON
1import base64
2
3with open("document.png", "rb") as f:
4 b64 = base64.b64encode(f.read()).decode("utf-8")
5
6data_uri = f"data:image/png;base64,{b64}"
3

Parse the Document

Pass the document to the Parse endpoint. By default, the response contains Markdown output.

PYTHON
1response = co.parse(
2 model="parse-v5.0",
3 document={"type": "image_url", "image_url": data_uri},
4)
5
6for page in response.pages:
7 print(page.markdown.content)
4

Blocks Output

To get structured content blocks, set output_format to "blocks". Each block has a type (e.g. text, table) with type-specific fields including bounding boxes for tables.

PYTHON
1response = co.parse(
2 model="parse-v5.0",
3 document={"type": "image_url", "image_url": data_uri},
4 output_format="blocks",
5)
6
7for page in response.pages:
8 for block in page.blocks:
9 if block.type == "text":
10 print(block.text.content)
11 elif block.type == "table":
12 print(f"[Table] bbox={block.table.bounding_box}")
13 print(block.table.html)
14 print(block.table.description)
15 print()

Further Resources