Python Quick Start

The python request library can be used to send a request to the API:

Upload a file

import requests
api_key = "YOUR_API_KEY"

url = 'https://api.tile.run/v1/upload'
headers = {
    'Authorization': f'Bearer {api_key}',
    "Content-Type": "application/json"
}

file_path = '/tmp/invoice.pdf'

with open(file_path, "rb") as file:
    file_base64 = base64.b64encode(file.read()).decode("utf-8")
    data = {"file_base64": file_base64, "content_type": "application/pdf"}
    response = requests.post(url=url, headers=headers, json=data).json()
    file_id = response["file_id"]

Extract data

url = 'https://api.tile.run/v1/extract'

data = {
    "file_id": file_id,
    "document_schema": {
        "name": "invoices",
        "description": "A schema for invoices",
        "fields": [
            {
                "name": "Invoice number",
                "description": "The unique identifier for the invoice",
                "type": "string",
            }
        ],
    },
}

post_response = requests.post(url, headers=headers, json=data).json()
extraction_id = post_response["extraction_id"]

Poll for results

import time

url = f'https://api.tile.run/v1/extract/{file_id}'

for i in range(60 * 5):
    response_data = requests.get(url, headers=headers).json()
    if response_data["status"] == "COMPLETED":
        print("Extraction completed")
        print(response_data["extracted_data"])
        break
    time.sleep(1)