from retab import MIMEData, Retab
client = Retab()
document = MIMEData(
filename="passport.jpeg",
url="https://storage.googleapis.com/retab-docs/passport.jpeg",
)
response = client.schemas.generate(
documents=[document],
model="retab-small", # or any model your plan supports
)
print("Generated JSON Schema:")
print(response)
{
"title": "Invoice Document Schema",
"description": "A schema for storing structured data extracted from invoice documents, including parties, line items, and payment details.",
"type": "object",
"X-SchemaType": "generic",
"properties": {
"invoice_number": {
"type": "string",
"description": "Unique identifier for the invoice."
},
"date_of_issue": {
"type": "string",
"description": "Date when the invoice was issued."
},
"date_due": {
"type": "string",
"description": "Date when the invoice payment is due."
},
"seller": {
"$ref": "#/$defs/party"
},
"bill_to": {
"$ref": "#/$defs/party"
},
"ship_to": {
"$ref": "#/$defs/party"
},
"line_items": {
"type": "array",
"description": "List of items or services billed on the invoice.",
"items": {
"$ref": "#/$defs/line_item"
}
},
"subtotal": {
"type": "number",
"description": "Subtotal amount before taxes or discounts."
},
"total": {
"type": "number",
"description": "Total amount due."
},
"amount_due": {
"type": "number",
"description": "Amount due for payment."
},
"currency": {
"type": "string",
"description": "Currency code (e.g., USD, EUR)."
}
},
"required": [
"invoice_number",
"date_of_issue",
"date_due",
"seller",
"bill_to",
"ship_to",
"line_items",
"subtotal",
"total",
"amount_due",
"currency"
],
"additionalProperties": false,
"$defs": {
"party": {
"type": "object",
"description": "Information about a party involved in the invoice (seller, buyer, or recipient).",
"properties": {
"name": {
"type": "string",
"description": "Name of the party."
},
"address": {
"type": "string",
"description": "Full address of the party."
},
"email": {
"type": "string",
"description": "Email address of the party."
},
"tax_id": {
"type": "string",
"description": "Tax identification number or EIN."
}
},
"required": ["name", "address", "email", "tax_id"],
"additionalProperties": false
},
"line_item": {
"type": "object",
"description": "A single item or service listed on the invoice.",
"properties": {
"description": {
"type": "string",
"description": "Description of the item or service."
},
"service_period": {
"type": "string",
"description": "Service period or date range for the item."
},
"quantity": {
"type": "number",
"description": "Quantity of the item or service."
},
"unit_price": {
"type": "number",
"description": "Unit price of the item or service."
},
"amount": {
"type": "number",
"description": "Total amount for this line item."
}
},
"required": [
"description",
"service_period",
"quantity",
"unit_price",
"amount"
],
"additionalProperties": false
}
}
}
Schemas
Generate
Generates a JSON Schema from scratch by inferring structure from the content of the provided example documents.
POST
/
v1
/
schemas
/
generate
from retab import MIMEData, Retab
client = Retab()
document = MIMEData(
filename="passport.jpeg",
url="https://storage.googleapis.com/retab-docs/passport.jpeg",
)
response = client.schemas.generate(
documents=[document],
model="retab-small", # or any model your plan supports
)
print("Generated JSON Schema:")
print(response)
{
"title": "Invoice Document Schema",
"description": "A schema for storing structured data extracted from invoice documents, including parties, line items, and payment details.",
"type": "object",
"X-SchemaType": "generic",
"properties": {
"invoice_number": {
"type": "string",
"description": "Unique identifier for the invoice."
},
"date_of_issue": {
"type": "string",
"description": "Date when the invoice was issued."
},
"date_due": {
"type": "string",
"description": "Date when the invoice payment is due."
},
"seller": {
"$ref": "#/$defs/party"
},
"bill_to": {
"$ref": "#/$defs/party"
},
"ship_to": {
"$ref": "#/$defs/party"
},
"line_items": {
"type": "array",
"description": "List of items or services billed on the invoice.",
"items": {
"$ref": "#/$defs/line_item"
}
},
"subtotal": {
"type": "number",
"description": "Subtotal amount before taxes or discounts."
},
"total": {
"type": "number",
"description": "Total amount due."
},
"amount_due": {
"type": "number",
"description": "Amount due for payment."
},
"currency": {
"type": "string",
"description": "Currency code (e.g., USD, EUR)."
}
},
"required": [
"invoice_number",
"date_of_issue",
"date_due",
"seller",
"bill_to",
"ship_to",
"line_items",
"subtotal",
"total",
"amount_due",
"currency"
],
"additionalProperties": false,
"$defs": {
"party": {
"type": "object",
"description": "Information about a party involved in the invoice (seller, buyer, or recipient).",
"properties": {
"name": {
"type": "string",
"description": "Name of the party."
},
"address": {
"type": "string",
"description": "Full address of the party."
},
"email": {
"type": "string",
"description": "Email address of the party."
},
"tax_id": {
"type": "string",
"description": "Tax identification number or EIN."
}
},
"required": ["name", "address", "email", "tax_id"],
"additionalProperties": false
},
"line_item": {
"type": "object",
"description": "A single item or service listed on the invoice.",
"properties": {
"description": {
"type": "string",
"description": "Description of the item or service."
},
"service_period": {
"type": "string",
"description": "Service period or date range for the item."
},
"quantity": {
"type": "number",
"description": "Quantity of the item or service."
},
"unit_price": {
"type": "number",
"description": "Unit price of the item or service."
},
"amount": {
"type": "number",
"description": "Total amount for this line item."
}
},
"required": [
"description",
"service_period",
"quantity",
"unit_price",
"amount"
],
"additionalProperties": false
}
}
}
from retab import MIMEData, Retab
client = Retab()
document = MIMEData(
filename="passport.jpeg",
url="https://storage.googleapis.com/retab-docs/passport.jpeg",
)
response = client.schemas.generate(
documents=[document],
model="retab-small", # or any model your plan supports
)
print("Generated JSON Schema:")
print(response)
{
"title": "Invoice Document Schema",
"description": "A schema for storing structured data extracted from invoice documents, including parties, line items, and payment details.",
"type": "object",
"X-SchemaType": "generic",
"properties": {
"invoice_number": {
"type": "string",
"description": "Unique identifier for the invoice."
},
"date_of_issue": {
"type": "string",
"description": "Date when the invoice was issued."
},
"date_due": {
"type": "string",
"description": "Date when the invoice payment is due."
},
"seller": {
"$ref": "#/$defs/party"
},
"bill_to": {
"$ref": "#/$defs/party"
},
"ship_to": {
"$ref": "#/$defs/party"
},
"line_items": {
"type": "array",
"description": "List of items or services billed on the invoice.",
"items": {
"$ref": "#/$defs/line_item"
}
},
"subtotal": {
"type": "number",
"description": "Subtotal amount before taxes or discounts."
},
"total": {
"type": "number",
"description": "Total amount due."
},
"amount_due": {
"type": "number",
"description": "Amount due for payment."
},
"currency": {
"type": "string",
"description": "Currency code (e.g., USD, EUR)."
}
},
"required": [
"invoice_number",
"date_of_issue",
"date_due",
"seller",
"bill_to",
"ship_to",
"line_items",
"subtotal",
"total",
"amount_due",
"currency"
],
"additionalProperties": false,
"$defs": {
"party": {
"type": "object",
"description": "Information about a party involved in the invoice (seller, buyer, or recipient).",
"properties": {
"name": {
"type": "string",
"description": "Name of the party."
},
"address": {
"type": "string",
"description": "Full address of the party."
},
"email": {
"type": "string",
"description": "Email address of the party."
},
"tax_id": {
"type": "string",
"description": "Tax identification number or EIN."
}
},
"required": ["name", "address", "email", "tax_id"],
"additionalProperties": false
},
"line_item": {
"type": "object",
"description": "A single item or service listed on the invoice.",
"properties": {
"description": {
"type": "string",
"description": "Description of the item or service."
},
"service_period": {
"type": "string",
"description": "Service period or date range for the item."
},
"quantity": {
"type": "number",
"description": "Quantity of the item or service."
},
"unit_price": {
"type": "number",
"description": "Unit price of the item or service."
},
"amount": {
"type": "number",
"description": "Total amount for this line item."
}
},
"required": [
"description",
"service_period",
"quantity",
"unit_price",
"amount"
],
"additionalProperties": false
}
}
}
Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Headers
Body
application/json
Body to generate a JSON schema from example documents, optionally steered by instructions.
Response
Successful Response
Public generated schema response.
Unique identifier of the schema generation.
Lifecycle status. The synchronous path returns 'completed'. Background runs progress pending -> queued -> in_progress -> completed | failed | cancelled.
Available options:
pending, queued, in_progress, completed, failed, cancelled Error details when a background run fails; null otherwise. Always present so consumers can read it without an existence check.
Show child attributes
Show child attributes
⌘I