Ocriva Logo

Documents

Templates

Create, update, delete, and manage extraction templates via the Open API.

apiopenapitemplates

Published: 3/31/2026

Templates

Templates define how the AI extracts data from your documents — the schema fields, instructions, and output format. The Templates endpoints let you manage templates programmatically, including uploading reference data files that guide the AI during extraction.


List Templates

GET /v1/openapi/templates

Returns all templates accessible to the token. Organization tokens return templates across all projects in the organization; project tokens return templates for their scoped project only.

Headers:

HeaderValueRequired
X-API-Keyocr_your_api_keyYes

Example Request:

curl "https://api.ocriva.com/v1/openapi/templates" \
  -H "X-API-Key: ocr_your_api_key"

Example Response (200 OK):

[
  {
    "templateId": "68db4bb3a67e9c04fb0c6f85",
    "name": "Invoice Template",
    "description": "Extract structured data from invoices including line items, totals, and vendor details",
    "templateSchema": {
      "invoiceNumber": { "type": "string", "description": "Invoice number" },
      "totalAmount": { "type": "number", "description": "Total invoice amount" },
      "vendor": { "type": "string", "description": "Vendor name" }
    },
    "projectId": "68db4aa2967d9c03fa9b5e74",
    "isActive": true,
    "resultFormat": "json",
    "extractionMode": "structured",
    "createdAt": "2026-01-15T08:00:00.000Z",
    "updatedAt": "2026-03-20T14:30:00.000Z"
  }
]

Create Template

POST /v1/openapi/templates

Creates a new extraction template for a project.

Headers:

HeaderValueRequired
X-API-Keyocr_your_api_keyYes
Content-Typeapplication/jsonYes

Request Body:

FieldTypeRequiredDescription
namestringYesTemplate name (e.g., Receipt)
descriptionstringYesWhat this template extracts
templateSchemaobjectYesJSON Schema defining the fields to extract
projectIdstringYesTarget project ID
instructionsstringNoCustom AI assistant instructions

Example Request:

curl -X POST "https://api.ocriva.com/v1/openapi/templates" \
  -H "X-API-Key: ocr_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Receipt",
    "description": "Extract structured data from receipts including merchant information, items purchased, amounts, and payment details",
    "projectId": "68db4aa2967d9c03fa9b5e74",
    "templateSchema": {
      "merchantName": {
        "type": "string",
        "description": "Name of the merchant or store"
      },
      "totalAmount": {
        "type": "number",
        "description": "Total amount paid including tax"
      },
      "date": {
        "type": "string",
        "description": "Date of the transaction (YYYY-MM-DD)"
      },
      "items": {
        "type": "array",
        "description": "List of purchased items"
      }
    },
    "instructions": "You are an expert in document analysis. Extract all fields accurately."
  }'

Example Response (201 Created):

{
  "templateId": "68db4bb3a67e9c04fb0c6f85",
  "name": "Receipt",
  "description": "Extract structured data from receipts including merchant information, items purchased, amounts, and payment details",
  "templateSchema": {
    "merchantName": { "type": "string", "description": "Name of the merchant or store" },
    "totalAmount": { "type": "number", "description": "Total amount paid including tax" },
    "date": { "type": "string", "description": "Date of the transaction (YYYY-MM-DD)" },
    "items": { "type": "array", "description": "List of purchased items" }
  },
  "projectId": "68db4aa2967d9c03fa9b5e74",
  "isActive": true,
  "createdAt": "2026-03-31T10:00:00.000Z",
  "updatedAt": "2026-03-31T10:00:00.000Z"
}

Update Template

PUT /v1/openapi/templates/:id

Updates an existing template. Only the fields you provide are changed.

Path Parameters:

ParameterDescription
idTemplate ID to update

Headers:

HeaderValueRequired
X-API-Keyocr_your_api_keyYes
Content-Typeapplication/jsonYes

Request Body:

FieldTypeRequiredDescription
projectIdstringYesProject ID the template belongs to
namestringNoUpdated template name
descriptionstringNoUpdated description
templateSchemaobjectNoUpdated schema definition
instructionsstringNoUpdated AI instructions

Example Request:

curl -X PUT "https://api.ocriva.com/v1/openapi/templates/68db4bb3a67e9c04fb0c6f85" \
  -H "X-API-Key: ocr_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "projectId": "68db4aa2967d9c03fa9b5e74",
    "name": "Receipt Updated",
    "description": "Updated description for receipt processing"
  }'

Example Response (200 OK):

{
  "templateId": "68db4bb3a67e9c04fb0c6f85",
  "name": "Receipt Updated",
  "description": "Updated description for receipt processing",
  "templateSchema": {
    "merchantName": { "type": "string", "description": "Name of the merchant or store" },
    "totalAmount": { "type": "number", "description": "Total amount paid including tax" }
  },
  "projectId": "68db4aa2967d9c03fa9b5e74",
  "isActive": true,
  "createdAt": "2026-03-31T10:00:00.000Z",
  "updatedAt": "2026-03-31T11:15:00.000Z"
}

Common Errors:

StatusCause
401Template does not belong to the token's project or organization
404Template not found

Delete Template

DELETE /v1/openapi/templates/:id

Soft-deletes a template. The template is marked inactive and will no longer appear in list responses, but historical processing records that reference it are preserved.

Path Parameters:

ParameterDescription
idTemplate ID to delete

Headers:

HeaderValueRequired
X-API-Keyocr_your_api_keyYes

Example Request:

curl -X DELETE "https://api.ocriva.com/v1/openapi/templates/68db4bb3a67e9c04fb0c6f85" \
  -H "X-API-Key: ocr_your_api_key"

Example Response (200 OK):

{
  "message": "Template deleted successfully"
}

Common Errors:

StatusCause
401Template does not belong to the token's project or organization
404Template not found

Upload Data File to Template

POST /v1/openapi/templates/:id/files

Attaches a reference data file (JSON, Markdown, or plain text) to a template. The AI uses these files as additional context during extraction — for example, a product catalog or a list of merchant codes.

Path Parameters:

ParameterDescription
idTemplate ID to attach the file to

Headers:

HeaderValueRequired
X-API-Keyocr_your_api_keyYes
Content-Typemultipart/form-dataYes

Request Body (multipart/form-data):

FieldTypeRequiredDescription
fileFileYesData file to attach. Accepted types: .json, .md, .txt

Example Request:

curl -X POST "https://api.ocriva.com/v1/openapi/templates/68db4bb3a67e9c04fb0c6f85/files" \
  -H "X-API-Key: ocr_your_api_key" \
  -F "file=@/path/to/product-catalog.json"

Example Response (201 Created):

{
  "templateId": "68db4bb3a67e9c04fb0c6f85",
  "name": "Receipt",
  "description": "Extract structured data from receipts",
  "templateSchema": { ... },
  "projectId": "68db4aa2967d9c03fa9b5e74",
  "isActive": true,
  "createdAt": "2026-03-31T10:00:00.000Z",
  "updatedAt": "2026-03-31T12:00:00.000Z"
}

Common Errors:

StatusCause
400No file included, or unsupported file type
401Template does not belong to the token's scope
404Template not found

Remove Data File from Template

DELETE /v1/openapi/templates/:id/files/:fileId

Removes a previously attached data file from a template.

Path Parameters:

ParameterDescription
idTemplate ID
fileIdData file ID to remove

Headers:

HeaderValueRequired
X-API-Keyocr_your_api_keyYes

Example Request:

curl -X DELETE "https://api.ocriva.com/v1/openapi/templates/68db4bb3a67e9c04fb0c6f85/files/68dc2dd5c89f1e26fd3b8g02" \
  -H "X-API-Key: ocr_your_api_key"

Example Response (200 OK):

{
  "templateId": "68db4bb3a67e9c04fb0c6f85",
  "name": "Receipt",
  "description": "Extract structured data from receipts",
  "templateSchema": { ... },
  "projectId": "68db4aa2967d9c03fa9b5e74",
  "isActive": true,
  "createdAt": "2026-03-31T10:00:00.000Z",
  "updatedAt": "2026-03-31T12:30:00.000Z"
}

Common Errors:

StatusCause
401Template does not belong to the token's scope
404Template or file not found