Skip to main content
POST
/
v1
/
documents
/
edit
from retab import Retab

client = Retab()

# Option 1: Edit with a document (detects fields automatically)
result = client.documents.edit(
    instructions="Name: John Doe, Date of Birth: 1990-01-15, Address: 123 Main Street, City: New York",
    document="form.pdf",  # Can be a file path, URL, or MIMEData
    model="retab-small"
)

# Option 2: Edit with a template (uses pre-defined fields)
# result = client.documents.edit(
#     instructions="Name: John Doe, Date of Birth: 1990-01-15",
#     template_id="tmpl_abc123",  # Use template instead of document
#     model="retab-small",
# )

# Access the filled PDF (MIMEData with filename and url containing base64 data)
if result.filled_document:
    import base64
    # Extract base64 content from data URI
    base64_content = result.filled_document.url.split(",")[1]
    filled_document_bytes = base64.b64decode(base64_content)
    with open("filled_form.pdf", "wb") as f:
        f.write(filled_document_bytes)

# Access form data with filled values
print(f"Filled {len(result.form_data)} form fields")
for field in result.form_data:
    print(f"Field: {field.key} ({field.description}) = {field.value}")
{
  "form_data": [
    {
      "bbox": {
        "left": 0.15,
        "top": 0.20,
        "width": 0.35,
        "height": 0.03,
        "page": 1
      },
      "description": "Full Name - text input field for applicant's legal name",
      "type": "text",
      "key": "full_name",
      "value": "John Doe"
    },
    {
      "bbox": {
        "left": 0.15,
        "top": 0.28,
        "width": 0.20,
        "height": 0.03,
        "page": 1
      },
      "description": "Date of Birth - date field in MM/DD/YYYY format",
      "type": "text",
      "key": "date_of_birth",
      "value": "01/15/1990"
    },
    {
      "bbox": {
        "left": 0.55,
        "top": 0.45,
        "width": 0.02,
        "height": 0.02,
        "page": 1
      },
      "description": "Agreement checkbox - confirms acceptance of terms",
      "type": "checkbox",
      "key": "agreement_checkbox",
      "value": "unchecked"
    }
  ],
  "filled_document": {
    "filename": "filled_form.pdf",
    "url": "data:application/pdf;base64,JVBERi0xLjQK..."
  }
}
from retab import Retab

client = Retab()

# Option 1: Edit with a document (detects fields automatically)
result = client.documents.edit(
    instructions="Name: John Doe, Date of Birth: 1990-01-15, Address: 123 Main Street, City: New York",
    document="form.pdf",  # Can be a file path, URL, or MIMEData
    model="retab-small"
)

# Option 2: Edit with a template (uses pre-defined fields)
# result = client.documents.edit(
#     instructions="Name: John Doe, Date of Birth: 1990-01-15",
#     template_id="tmpl_abc123",  # Use template instead of document
#     model="retab-small",
# )

# Access the filled PDF (MIMEData with filename and url containing base64 data)
if result.filled_document:
    import base64
    # Extract base64 content from data URI
    base64_content = result.filled_document.url.split(",")[1]
    filled_document_bytes = base64.b64decode(base64_content)
    with open("filled_form.pdf", "wb") as f:
        f.write(filled_document_bytes)

# Access form data with filled values
print(f"Filled {len(result.form_data)} form fields")
for field in result.form_data:
    print(f"Field: {field.key} ({field.description}) = {field.value}")
{
  "form_data": [
    {
      "bbox": {
        "left": 0.15,
        "top": 0.20,
        "width": 0.35,
        "height": 0.03,
        "page": 1
      },
      "description": "Full Name - text input field for applicant's legal name",
      "type": "text",
      "key": "full_name",
      "value": "John Doe"
    },
    {
      "bbox": {
        "left": 0.15,
        "top": 0.28,
        "width": 0.20,
        "height": 0.03,
        "page": 1
      },
      "description": "Date of Birth - date field in MM/DD/YYYY format",
      "type": "text",
      "key": "date_of_birth",
      "value": "01/15/1990"
    },
    {
      "bbox": {
        "left": 0.55,
        "top": 0.45,
        "width": 0.02,
        "height": 0.02,
        "page": 1
      },
      "description": "Agreement checkbox - confirms acceptance of terms",
      "type": "checkbox",
      "key": "agreement_checkbox",
      "value": "unchecked"
    }
  ],
  "filled_document": {
    "filename": "filled_form.pdf",
    "url": "data:application/pdf;base64,JVBERi0xLjQK..."
  }
}

Authorizations

Api-Key
string
header
required

Query Parameters

access_token
string | null

Body

application/json

Request for the infer_and_fill_schema endpoint.

Performs OCR + LLM inference to detect and fill form fields in the provided document.

If form_fields is provided (PDF only), the inference step is skipped and the provided fields are used directly for filling.

document
MIMEData · object
required

Input document (PDF, DOCX, XLSX or PPTX).

instructions
string
required

Instructions to fill the form

model
string
default:retab-small

LLM model to use for inference

form_fields
FormField · object[] | null

Optional pre-defined form fields (PDF only). When provided, skips field inference and uses these fields directly.

config
EditConfig · object

Configuration for the edit request

Response

Successful Response

Response from the fill_form endpoint.

form_data
FormField · object[]
required

List of form fields (with positions, descriptions, and metadata) that define the structure of the form.

filled_document
MIMEData · object
required

PDF with filled form values