Goals:

1. Set your API key

Create your account here [https://dashboard.runtrellis.com/sign-up]. Then, click settings on the lower right or visit the setting page and copy your API key.

Python
import requests
YOUR_API_KEY = "YOUR_API_KEY" # add your api key

2. Create a Project to put your data

Each project has a unique ID. You can use this ID to refer to the project in the data upload process.

Python
YOUR_PROJ_NAME = "YOUR_PROJECT_NAME" 
url = f"https://api.runtrellis.com/v1/projects/create"

payload = {"name": YOUR_PROJ_NAME}
headers = {
    "Authorization": YOUR_API_KEY,
    "Content-Type": "application/json"
}
response = requests.request("POST", url, json=payload, headers=headers)
proj_id = response.json()["data"]["proj_id"]
print(proj_id)

3. Upload the data to the project

In this example, we will use sample W2 form data.

Python
url = f"https://api.runtrellis.com/v1/assets/upload"

payload = {
    "proj_id": proj_id,
    "urls": ["https://trellis-ai-public.s3.us-west-2.amazonaws.com/pdf_w2_clean/W2_XL_input_clean_1.pdf"
    ]
}
response = requests.request("POST", url, json=payload, headers=headers)
asset_ids = [data["asset_id"] for data in response.json()["data"] ]
print(response.text)

4. Start the PDF to markdown extraction

Python

url = "https://api.runtrellis.com/v1/assets/extract"

payload = {
    "asset_ids": asset_ids,
    "proj_id": proj_id,
    "parse_strategy": "markdown",
    "run_on_all_assets": True
}


response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)

5. Get the markdown results

Python
for asset_id in asset_ids:
  url = f"https://api.runtrellis.com/v1/assets/{asset_id}/extract"
  
  response = requests.request("GET", url, headers=headers)
  
  print(response.text)