Skip to main content

Templates API

The Templates API manages Machine Readable Templates (MRTs) with nested sections and content extraction rules. Templates define the structure and content requirements for generated documents.

List Templates

Retrieve all MRT templates accessible to the authenticated user.
GET /api/v1/templates/

Request Example

curl -X GET "https://api.artosai.com/api/v1/templates/" \
  -H "Authorization: Bearer YOUR_TOKEN"

Response

{
  "templates": [
    {
      "id": "template-uuid-1",
      "template_name": "CSR Template",
      "source_document_name": "csr-example.docx",
      "url": "https://s3.amazonaws.com/bucket/template.docx?...",
      "detected_document_type": "CSR",
      "template_id": "template-uuid-1",
      "sections": [
        {
          "section_id": "section-1",
          "title": "Executive Summary",
          "level": 1
        }
      ],
      "status": "active",
      "template_file_name": "csr-template.docx",
      "created_at": "2024-01-20T10:00:00Z",
      "updated_at": "2024-01-25T12:00:00Z"
    }
  ]
}

Status Codes

  • 200 OK: Templates retrieved successfully
  • 401 Unauthorized: Missing or invalid Bearer token

Get Single Template

Retrieve a specific MRT template with full details.
GET /api/v1/templates/{template_id}

Path Parameters

ParameterTypeRequiredDescription
template_idstringYesUUID of template

Request Example

curl -X GET "https://api.artosai.com/api/v1/templates/template-uuid" \
  -H "Authorization: Bearer YOUR_TOKEN"

Response

{
  "url": "https://s3.amazonaws.com/bucket/template.docx?...",
  "template_name": "CSR Template",
  "source_document_name": "csr-example.docx",
  "detected_document_type": "CSR",
  "template_id": "template-uuid",
  "sections": [
    {
      "section_id": "section-1",
      "order_index": 0,
      "level": 1,
      "title": "Executive Summary",
      "synopsis": "Summary of key findings",
      "template_instructions": "Summarize in 2-3 paragraphs",
      "rules": [
        {
          "rule_type": "extraction",
          "rule_mode": "auto",
          "description": "Extract safety findings"
        }
      ]
    }
  ],
  "examples": [
    {
      "example_id": "example-1",
      "content": "Example content here"
    }
  ],
  "users": [
    {
      "user_id": "user-uuid",
      "email": "[email protected]"
    }
  ]
}

Status Codes

  • 200 OK: Template retrieved successfully
  • 400 Bad Request: Authentication failure
  • 404 Not Found: Template not found

Create Template

Create a new MRT template with nested sections and extraction rules.
POST /api/v1/templates/

Request Body

{
  "template_name": "CSR Template",
  "document_type": "CSR",
  "sections": [
    {
      "order_index": 0,
      "level": 1,
      "section_name": "Executive Summary",
      "synopsis": "Overview of document",
      "template_instructions": "Summarize key findings",
      "template_text": "This section contains...",
      "section_type": "summary",
      "section_mode": "auto",
      "is_repeating": false,
      "rules": [
        {
          "rule_type": "extraction",
          "rule_mode": "auto",
          "description": "Extract safety data"
        }
      ]
    },
    {
      "order_index": 1,
      "level": 1,
      "section_name": "Methodology",
      "template_instructions": "Describe study design"
    }
  ],
  "template_s3_uri": "s3://bucket/template.docx",
  "document_description": "Standard CSR template",
  "tags": ["csr", "regulatory"],
  "users": ["user-uuid-1", "user-uuid-2"]
}

Request Parameters

ParameterTypeRequiredDescription
template_namestringYesTemplate name
document_typestringYesDocument type (e.g., CSR, IND, Protocol)
sectionsarrayYesAt least one section required
template_s3_uristringNoS3 URI for template file
template_file_namestringNoTemplate file name
document_descriptionstringNoDescription
tagsarrayNoCategorization tags
usersarrayNoUser IDs with access

Section Parameters

ParameterTypeRequiredDescription
order_indexintegerYesPosition in template (0-based)
levelintegerYesNesting level (1=top-level)
section_namestringYesSection title
synopsisstringNoBrief summary
template_instructionsstringNoCompletion instructions
template_textstringNoTemplate text
section_typestringNoSection type
section_modestringNoOperation mode
is_repeatingbooleanNoDefault: false
expansion_typestringNoFor repeating sections
rulesarrayNoExtraction rules

Request Example

curl -X POST "https://api.artosai.com/api/v1/templates/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "template_name": "CSR Template",
    "document_type": "CSR",
    "sections": [
      {
        "order_index": 0,
        "level": 1,
        "section_name": "Executive Summary"
      }
    ],
    "template_s3_uri": "s3://bucket/template.docx"
  }'

Python Example

import requests

url = "https://api.artosai.com/api/v1/templates/"
headers = {
    "Authorization": "Bearer YOUR_TOKEN",
    "Content-Type": "application/json"
}

payload = {
    "template_name": "CSR Template",
    "document_type": "CSR",
    "sections": [
        {
            "order_index": 0,
            "level": 1,
            "section_name": "Executive Summary",
            "template_instructions": "Summarize findings"
        }
    ],
    "template_s3_uri": "s3://bucket/template.docx"
}

response = requests.post(url, headers=headers, json=payload)
template = response.json()
print(f"Created template: {template['template_id']}")

Response (201 Created)

{
  "template_id": "template-uuid",
  "template_name": "CSR Template",
  "organization_id": "org-uuid",
  "section_count": 2,
  "rule_count": 3,
  "created_at": "2024-01-25T12:00:00Z"
}

Status Codes

  • 201 Created: Template created successfully
  • 400 Bad Request: Validation errors (missing fields, duplicate indices)
  • 401 Unauthorized: Authentication failures
  • 500 Internal Server Error: Database operation failures

Delete Template Section

Delete a section from an MRT template.
DELETE /api/v1/templates/{template_id}/sections/{section_id}

Path Parameters

ParameterTypeRequiredDescription
template_idstringYesUUID of template
section_idstringYesUUID of section to delete

Query Parameters

ParameterTypeRequiredDefaultDescription
cascade_childrenbooleanNotrueDelete child sections

Request Example

curl -X DELETE "https://api.artosai.com/api/v1/templates/template-uuid/sections/section-uuid" \
  -H "Authorization: Bearer YOUR_TOKEN"

Response

{
  "message": "Section deleted successfully",
  "deleted_section_id": "section-uuid",
  "deleted_count": 1
}

Status Codes

  • 200 OK: Section deleted successfully
  • 400 Bad Request: Invalid parameters
  • 403 Forbidden: Not authorized
  • 404 Not Found: Template or section not found