Skip to main content
Beta Sections and templates share the same draft-then-promote lifecycle. Every time you change a section’s prompts/schema or a template’s instructions/composition, you create a new version. New versions are not published automatically — your previously published version stays live until you explicitly publish a new one. That gives you safe iteration in production: drafts are private to your project until promotion, and consumers continue to see the previously published version.
Treat unpublished versions as drafts. You can GET the list of versions, inspect each, and only publish once you’re confident.

Versioning a section

Once a section exists, iterate by creating new versions.
// Replace these with your values
const SECTION_ID = "<your-section-id>";

const version = await client.documents.sections.versions.create(SECTION_ID, {
  generation: {
    heading: "Clinical Findings",
    instructions: {
      contentPrompt: "Extract all relevant clinical findings, grouped by body system where applicable.",
      writingStylePrompt: "Concise, professional, with grouped subheadings when relevant.",
    },
    outputSchema: { type: "string" },
  },
});
The response returns the new version with an auto-incremented versionNumber.
// Replace these with your values
const SECTION_ID = "<your-section-id>";
const VERSION_ID = "<your-version-id>";

await client.documents.sections.versions.publish(SECTION_ID, VERSION_ID);
A successful publish returns { "status": "published" } and the section’s publishedVersion will reflect the new version on subsequent GET calls.

Versioning a template

Once a template exists, iterate by creating new versions. The published version stays live until you explicitly publish a new one.
// Replace these with your values
const SECTION_ID_1 = "<your-section-id>";
const SECTION_ID_2 = "<your-section-id>";
const SECTION_ID_NEW = "<your-section-id>";
const TEMPLATE_ID = "<your-template-id>";

const version = await client.documents.templates.versions.create(TEMPLATE_ID, {
  generation: {
    instructions: {
      prompt: "Produce a structured consultation note. Address the patient in second person.",
    },
    sections: [
      { sectionId: SECTION_ID_1, orderIndex: 0 },
      { sectionId: SECTION_ID_2, orderIndex: 1 },
      { sectionId: SECTION_ID_NEW, orderIndex: 2 },
    ],
  },
});
// Replace these with your values
const TEMPLATE_ID = "<your-template-id>";
const VERSION_ID = "<your-version-id>";

await client.documents.templates.versions.publish(TEMPLATE_ID, VERSION_ID);
A successful publish returns { "status": "published" } and subsequent GET /documents/templates/{templateID} reflects the new publishedVersion.
Publishing a template version validates that every referenced section has a published version. Fix any unpublished sections before retrying the publish.