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

client = Retab()

response = client.edit.agent.fill(
    document="form.pdf",
    instructions="Fill this form with: Name: John Doe, Date: 2025-01-02, Email: [email protected]",
    model="retab-small"
)


# Save the filled document
with open("filled_form.pdf", "wb") as f:
    import base64
    pdf_bytes = base64.b64decode(response.filled_document.url.split(",")[1])
    f.write(pdf_bytes)
{
  "form_data": [
    {
      "key": "full_name",
      "description": "Full name of the applicant",
      "type": "text",
      "value": "John Doe",
      "bbox": {
        "page": 0,
        "x": 100,
        "y": 200,
        "width": 200,
        "height": 20
      }
    },
    {
      "key": "date",
      "description": "Date of submission",
      "type": "date",
      "value": "2025-01-02",
      "bbox": {
        "page": 0,
        "x": 100,
        "y": 250,
        "width": 100,
        "height": 20
      }
    },
    {
      "key": "email",
      "description": "Email address",
      "type": "text",
      "value": "[email protected]",
      "bbox": {
        "page": 0,
        "x": 100,
        "y": 300,
        "width": 200,
        "height": 20
      }
    }
  ],
  "filled_document": {
    "filename": "form_filled.pdf",
    "mime_type": "application/pdf",
    "url": "data:application/pdf;base64,JVBERi0xLjQK..."
  }
}
from retab import Retab

client = Retab()

response = client.edit.agent.fill(
    document="form.pdf",
    instructions="Fill this form with: Name: John Doe, Date: 2025-01-02, Email: [email protected]",
    model="retab-small"
)


# Save the filled document
with open("filled_form.pdf", "wb") as f:
    import base64
    pdf_bytes = base64.b64decode(response.filled_document.url.split(",")[1])
    f.write(pdf_bytes)
{
  "form_data": [
    {
      "key": "full_name",
      "description": "Full name of the applicant",
      "type": "text",
      "value": "John Doe",
      "bbox": {
        "page": 0,
        "x": 100,
        "y": 200,
        "width": 200,
        "height": 20
      }
    },
    {
      "key": "date",
      "description": "Date of submission",
      "type": "date",
      "value": "2025-01-02",
      "bbox": {
        "page": 0,
        "x": 100,
        "y": 250,
        "width": 100,
        "height": 20
      }
    },
    {
      "key": "email",
      "description": "Email address",
      "type": "text",
      "value": "[email protected]",
      "bbox": {
        "page": 0,
        "x": 100,
        "y": 300,
        "width": 200,
        "height": 20
      }
    }
  ],
  "filled_document": {
    "filename": "form_filled.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 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