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

client = Retab()

# Edit the form by inferring fields and filling them
result = client.documents.edit(
    document="form.pdf",  # Can be a file path, URL, or MIMEData
    filling_instructions="Name: John Doe, Date of Birth: 1990-01-15, Address: 123 Main Street, City: New York",
    model="gemini-2.5-pro",
)

# Access the filled PDF (MIMEData with filename and url containing base64 data)
if result.filled_pdf:
    import base64
    # Extract base64 content from data URI
    base64_content = result.filled_pdf.url.split(",")[1]
    filled_pdf_bytes = base64.b64decode(base64_content)
    with open("filled_form.pdf", "wb") as f:
        f.write(filled_pdf_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.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",
      "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",
      "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",
      "value": "unchecked"
    }
  ],
  "filled_pdf": {
    "filename": "filled_form.pdf",
    "url": "data:application/pdf;base64,JVBERi0xLjQK..."
  }
}
from retab import Retab

client = Retab()

# Edit the form by inferring fields and filling them
result = client.documents.edit(
    document="form.pdf",  # Can be a file path, URL, or MIMEData
    filling_instructions="Name: John Doe, Date of Birth: 1990-01-15, Address: 123 Main Street, City: New York",
    model="gemini-2.5-pro",
)

# Access the filled PDF (MIMEData with filename and url containing base64 data)
if result.filled_pdf:
    import base64
    # Extract base64 content from data URI
    base64_content = result.filled_pdf.url.split(",")[1]
    filled_pdf_bytes = base64.b64decode(base64_content)
    with open("filled_form.pdf", "wb") as f:
        f.write(filled_pdf_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.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",
      "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",
      "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",
      "value": "unchecked"
    }
  ],
  "filled_pdf": {
    "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.

document
MIMEData · object
required

Input document (PDF)

filling_instructions
string
required

Instructions to fill the form

model
string
default:gemini-2.5-pro

LLM model to use for inference

Response

Successful Response

Response from the fill_form endpoint.

ocr_result
OCRResult · object
required

The OCR results used for inference

form_data
FilledFormField · object[]
required

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

filled_pdf
MIMEData · object
required

PDF with filled form values