Skip to main content
Templates support variable interpolation for consistent, dynamic document generation.

List templates

GET /format/v1/templates Retrieve all format templates for your organization.
const { templates } = await client.format.v1.templates.list({
  type: 'contract' // optional filter
});

console.log(templates);
// [
//   {
//     id: 'tmpl_abc123',
//     name: 'NDA Template',
//     description: 'Standard non-disclosure agreement',
//     type: 'contract',
//     variables: ['party1', 'party2', 'effectiveDate', 'jurisdiction'],
//     tags: ['confidentiality', 'standard'],
//     usageCount: 42,
//     createdAt: '2024-01-15T10:30:00Z'
//   }
// ]

Query parameters

ParameterTypeDescription
typestringFilter by template type (e.g., contract, pleading, letter)

Response

{
  "templates": [
    {
      "id": "tmpl_abc123",
      "name": "NDA Template",
      "description": "Standard non-disclosure agreement template",
      "type": "contract",
      "variables": ["party1", "party2", "effectiveDate", "jurisdiction"],
      "tags": ["confidentiality", "standard"],
      "usageCount": 42,
      "createdAt": "2024-01-15T10:30:00Z"
    }
  ]
}

Create template

POST /format/v1/templates Save a new format template for reuse.
const template = await client.format.v1.templates.create({
  name: 'Motion Template',
  description: 'Standard motion format for California Superior Court',
  type: 'pleading',
  content: `
# {{motion_title}}

**CASE NO.:** {{case_number}}

{{party_name}}, {{party_role}}, hereby moves this Court for {{relief_sought}}...

## STATEMENT OF FACTS

{{facts}}

## LEGAL ARGUMENT

{{argument}}
  `,
  variables: [
    { name: 'motion_title', required: true },
    { name: 'case_number', required: true },
    { name: 'party_name', required: true },
    { name: 'party_role', required: true, default: 'Plaintiff' },
    { name: 'relief_sought', required: true },
    { name: 'facts', required: true },
    { name: 'argument', required: true }
  ],
  styles: {
    h1: { font: 'Times New Roman', size: 14, bold: true, alignment: 'center' },
    p: { font: 'Times New Roman', size: 12, spacingAfter: 12 }
  },
  tags: ['motion', 'california', 'superior-court']
});

Request body

FieldTypeRequiredDescription
namestringYesTemplate name
descriptionstringNoDescription of the template
typestringNoCategory: contract, pleading, letter, memo, etc.
contentstringYesTemplate content with {{variable}} placeholders
variablesarrayNoVariable definitions with names, requirements, and defaults
stylesobjectNoDefault styles for this template
tagsarrayNoTags for organization

Get template

GET /format/v1/templates/{id} Retrieve a specific template by ID.
const template = await client.format.v1.templates.retrieve('tmpl_abc123');

Using templates

Reference saved templates when generating documents:
const document = await client.format.v1.document({
  content: '', // Can be empty when using templateId
  output_format: 'pdf',
  options: {
    components: [{
      templateId: 'tmpl_abc123',
      variables: {
        motion_title: 'Motion for Summary Judgment',
        case_number: '2024-CV-12345',
        party_name: 'John Doe',
        party_role: 'Plaintiff',
        relief_sought: 'summary judgment on all claims',
        facts: 'On January 1, 2024...',
        argument: 'Under California Code of Civil Procedure...'
      }
    }]
  }
});
Template usage is tracked automatically. The usageCount field shows how many times each template has been used, helping you identify your most valuable templates.

Variable validation

When using a template, the API validates that all required variables are provided:
// This will return a 400 error with message:
// "Missing required variables: case_number, party_name"
const document = await client.format.v1.document({
  output_format: 'pdf',
  options: {
    components: [{
      templateId: 'tmpl_abc123',
      variables: {
        motion_title: 'Motion for Summary Judgment'
        // Missing required variables!
      }
    }]
  }
});

Error codes

StatusDescription
400Invalid request or missing required variables
401Invalid or missing API key
404Template not found