Skip to main content
POST
/
v1
/
edit
/
templates
/
fill
from retab import Retab
import base64

client = Retab()

# Fill a form using a pre-defined template
response = client.edit.templates.fill(
    template_id="edittplt_abc123",
    instructions="""
    Full Name: Jane Smith
    Date of Birth: March 15, 1985
    Email: [email protected]
    Phone: (555) 123-4567
    """,
    model="retab-small"
)

print(f"Filled {len(response.form_data)} fields")

# Save the filled PDF
if response.filled_document:
    pdf_bytes = base64.b64decode(response.filled_document.url.split(",")[1])
    with open("filled_form.pdf", "wb") as f:
        f.write(pdf_bytes)
    print("Filled form saved!")
{
  "form_data": [
    {
      "key": "full_name",
      "description": "Full name of the applicant",
      "type": "text",
      "value": "Jane Smith",
      "bbox": {
        "page": 1,
        "left": 0.15,
        "top": 0.25,
        "width": 0.35,
        "height": 0.025
      }
    },
    {
      "key": "date_of_birth",
      "description": "Date of birth",
      "type": "date",
      "value": "March 15, 1985",
      "bbox": {
        "page": 1,
        "left": 0.15,
        "top": 0.30,
        "width": 0.20,
        "height": 0.025
      }
    },
    {
      "key": "email",
      "description": "Email address",
      "type": "text",
      "value": "[email protected]",
      "bbox": {
        "page": 1,
        "left": 0.15,
        "top": 0.35,
        "width": 0.35,
        "height": 0.025
      }
    },
    {
      "key": "phone",
      "description": "Phone number",
      "type": "text",
      "value": "(555) 123-4567",
      "bbox": {
        "page": 1,
        "left": 0.15,
        "top": 0.40,
        "width": 0.25,
        "height": 0.025
      }
    }
  ],
  "filled_document": {
    "filename": "filled_form.pdf",
    "mime_type": "application/pdf",
    "url": "data:application/pdf;base64,JVBERi0xLjQK..."
  }
}
from retab import Retab
import base64

client = Retab()

# Fill a form using a pre-defined template
response = client.edit.templates.fill(
    template_id="edittplt_abc123",
    instructions="""
    Full Name: Jane Smith
    Date of Birth: March 15, 1985
    Email: [email protected]
    Phone: (555) 123-4567
    """,
    model="retab-small"
)

print(f"Filled {len(response.form_data)} fields")

# Save the filled PDF
if response.filled_document:
    pdf_bytes = base64.b64decode(response.filled_document.url.split(",")[1])
    with open("filled_form.pdf", "wb") as f:
        f.write(pdf_bytes)
    print("Filled form saved!")
{
  "form_data": [
    {
      "key": "full_name",
      "description": "Full name of the applicant",
      "type": "text",
      "value": "Jane Smith",
      "bbox": {
        "page": 1,
        "left": 0.15,
        "top": 0.25,
        "width": 0.35,
        "height": 0.025
      }
    },
    {
      "key": "date_of_birth",
      "description": "Date of birth",
      "type": "date",
      "value": "March 15, 1985",
      "bbox": {
        "page": 1,
        "left": 0.15,
        "top": 0.30,
        "width": 0.20,
        "height": 0.025
      }
    },
    {
      "key": "email",
      "description": "Email address",
      "type": "text",
      "value": "[email protected]",
      "bbox": {
        "page": 1,
        "left": 0.15,
        "top": 0.35,
        "width": 0.35,
        "height": 0.025
      }
    },
    {
      "key": "phone",
      "description": "Phone number",
      "type": "text",
      "value": "(555) 123-4567",
      "bbox": {
        "page": 1,
        "left": 0.15,
        "top": 0.40,
        "width": 0.25,
        "height": 0.025
      }
    }
  ],
  "filled_document": {
    "filename": "filled_form.pdf",
    "mime_type": "application/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 fill endpoint. Uses pre-defined form fields from the template (PDF only)

instructions
string
required

Instructions to fill the form

template_id
string
required

Template ID to use for filling. When provided, uses the template's pre-defined form fields and empty PDF. Only works for PDF documents. Mutually exclusive with document.

model
string
default:retab-small

LLM model to use for inference

config
EditConfig · object

Configuration for the fill 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