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.
curl https://api.case.dev/format/v1/templates?type=contract \
  -H "Authorization: Bearer sk_case_YOUR_API_KEY"

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.
curl -X POST https://api.case.dev/format/v1/templates \
  -H "Authorization: Bearer sk_case_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Motion Template",
    "description": "Standard motion format for California Superior Court",
    "type": "pleading",
    "content": "# {{motion_title}}\n\n**CASE NO.:** {{case_number}}...",
    "variables": [
      { "name": "motion_title", "required": true },
      { "name": "case_number", "required": true }
    ],
    "tags": ["motion", "california"]
  }'

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.
curl https://api.case.dev/format/v1/templates/tmpl_abc123 \
  -H "Authorization: Bearer sk_case_YOUR_API_KEY"

Using templates

Reference saved templates when generating documents:
# CLI (via cURL - no direct CLI command)
curl -X POST https://api.case.dev/format/v1/document \
  -H "Authorization: Bearer $CASEDEV_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "",
    "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:
# CLI (via cURL - no direct CLI command)
# This will return a 400 error: "Missing required variables: case_number, party_name"
curl -X POST https://api.case.dev/format/v1/document \
  -H "Authorization: Bearer $CASEDEV_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "output_format": "pdf",
    "options": {
      "components": [{
        "templateId": "tmpl_abc123",
        "variables": {
          "motion_title": "Motion for Summary Judgment"
        }
      }]
    }
  }'

Error codes

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