> ## Documentation Index
> Fetch the complete documentation index at: https://docs.corti.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Path 4 — Fully inline dynamic template

> Define the template and every section inline in the request body — no prior authoring required. Ideal for prototyping or one-off generations.

<Badge className="accent-badge" shape="rounded">Beta</Badge>

← Back to [Guided Synthesis overview](/textgen/documents-guided-synthesis)

Use this for prototyping, one-off generations, or workflows where you don't want to maintain stored sections. Define both the template instructions and each section's full `generation` block inline. Sections and the wrapping template are created as auto-generated resources and immediately published — and like all auto-generated aggregates, are **retained for 30 days only** (see [Auto-generated template aggregates — 30-day retention](/textgen/documents-guided-synthesis#auto-generated-template-aggregates-30-day-retention)).

<CodeGroup>
  ```ts title="JavaScript" expandable theme={null}
  // Replace these with your values
  const INTERACTION_ID = "<your-interaction-id>";

  const result = await client.documents.generate({
    outputLanguage: "en-US",
    interactionId: INTERACTION_ID,
    dynamicTemplate: {
      name: "Allergy follow-up note (inline prototype)",
      generation: {
        instructions: { prompt: "Produce a focused allergy follow-up note." },
        sections: [
          {
            heading: "History of present illness",
            instructions: {
              contentPrompt: "Summarise the recent course of the patient's allergy symptoms.",
              writingStylePrompt: "Concise, professional.",
            },
            outputSchema: { type: "string" },
          },
          {
            heading: "Plan",
            instructions: {
              contentPrompt: "Outline next steps including any medication changes, testing or follow-up.",
            },
            outputSchema: {
              type: "array",
              itemFormat: "* {item}\n",
              maxItems: 5,
              items: { type: "string" },
            },
          },
        ],
      },
    },
  });
  ```

  ```csharp title="C# .NET" expandable theme={null}
  using Corti;

  // Replace these with your values
  const string InteractionId = "<your-interaction-id>";

  var result = await client.Documents.GenerateAsync(
      new GuidedDocumentsGenerateByDynamic
      {
          OutputLanguage = "en-US",
          InteractionId = InteractionId,
          DynamicTemplate = new GuidedDynamicRequest
          {
              Name = "Allergy follow-up note (inline prototype)",
              Generation = new GuidedDynamicInline
              {
                  Instructions = new GuidedTemplateInstructions
                  {
                      Prompt = "Produce a focused allergy follow-up note.",
                  },
                  Sections = new[]
                  {
                      new GuidedSectionGeneration
                      {
                          Heading = "History of present illness",
                          Instructions = new GuidedSectionInstructions
                          {
                              ContentPrompt = "Summarise the recent course of the patient's allergy symptoms.",
                              WritingStylePrompt = "Concise, professional.",
                          },
                          OutputSchema = new GuidedStringNode(),
                      },
                      new GuidedSectionGeneration
                      {
                          Heading = "Plan",
                          Instructions = new GuidedSectionInstructions
                          {
                              ContentPrompt = "Outline next steps including any medication changes, testing or follow-up.",
                          },
                          OutputSchema = new GuidedArrayNode
                          {
                              ItemFormat = "* {item}\n",
                              MaxItems = 5,
                              Items = new GuidedStringNode(),
                          },
                      },
                  },
              },
          },
      });
  ```

  ```python title="Python" expandable theme={null}
  import requests

  # Replace these with your values
  ENVIRONMENT = "<eu-or-us>"
  INTERACTION_ID = "<your-interaction-id>"
  TENANT = "<your-tenant-name>"
  TOKEN = "<your-access-token>"

  response = requests.post(
      f"https://api.{ENVIRONMENT}.corti.app/v2/documents",
      headers={
          "Authorization": f"Bearer {TOKEN}",
          "Tenant-Name": TENANT,
          "Content-Type": "application/json",
      },
      json={
          "outputLanguage": "en-US",
          "interactionId": INTERACTION_ID,
          "dynamicTemplate": {
              "name": "Allergy follow-up note (inline prototype)",
              "generation": {
                  "instructions": {"prompt": "Produce a focused allergy follow-up note."},
                  "sections": [
                      {
                          "heading": "History of present illness",
                          "instructions": {
                              "contentPrompt": "Summarise the recent course of the patient's allergy symptoms.",
                              "writingStylePrompt": "Concise, professional.",
                          },
                          "outputSchema": {"type": "string"},
                      },
                      {
                          "heading": "Plan",
                          "instructions": {
                              "contentPrompt": "Outline next steps including any medication changes, testing or follow-up.",
                          },
                          "outputSchema": {
                              "type": "array",
                              "itemFormat": "* {item}\n",
                              "maxItems": 5,
                              "items": {"type": "string"},
                          },
                      },
                  ],
              },
          },
      },
  )
  response.raise_for_status()
  result = response.json()
  ```

  ```bash title="cURL" expandable theme={null}
  # Replace these with your values
  ENVIRONMENT="<eu-or-us>"
  INTERACTION_ID="<your-interaction-id>"
  TENANT="<your-tenant-name>"
  TOKEN="<your-access-token>"

  curl --request POST \
    --url "https://api.${ENVIRONMENT}.corti.app/v2/documents" \
    --header "Authorization: Bearer ${TOKEN}" \
    --header "Tenant-Name: ${TENANT}" \
    --header "Content-Type: application/json" \
    --data "{
      \"outputLanguage\": \"en-US\",
      \"interactionId\": \"${INTERACTION_ID}\",
      \"dynamicTemplate\": {
        \"name\": \"Allergy follow-up note (inline prototype)\",
        \"generation\": {
          \"instructions\": { \"prompt\": \"Produce a focused allergy follow-up note.\" },
          \"sections\": [
            {
              \"heading\": \"History of present illness\",
              \"instructions\": {
                \"contentPrompt\": \"Summarise the recent course of the patient's allergy symptoms.\",
                \"writingStylePrompt\": \"Concise, professional.\"
              },
              \"outputSchema\": { \"type\": \"string\" }
            },
            {
              \"heading\": \"Plan\",
              \"instructions\": {
                \"contentPrompt\": \"Outline next steps including any medication changes, testing or follow-up.\"
              },
              \"outputSchema\": {
                \"type\": \"array\",
                \"itemFormat\": \"* {item}\\n\",
                \"maxItems\": 5,
                \"items\": { \"type\": \"string\" }
              }
            }
          ]
        }
      }
    }"
  ```
</CodeGroup>

<Tip>Each inline `sections[]` entry is a full [`SectionGeneration`](/textgen/section-creation#configuring-the-generation-block) — same shape you'd `POST /documents/sections` with. Use the full `outputSchema` toolbox (string, number, boolean, array, object with `fields`) to constrain output. See [Section Schemas](/textgen/section-schemas) for design patterns.</Tip>

## Mapping response section IDs back to your inline sections — Path 4 gotcha

Path 4 is the one place where mapping response keys back to your request sections is non-trivial. Your request supplies an **ordered list of `SectionGeneration` objects with no IDs of your own**, but the response's `stringDocument` / `structuredDocument` are keyed by **server-generated section UUIDs**. To attach the right heading to each rendered section:

1. Take the `templateVersionId` returned in the response.
2. Call `GET /documents/templates/{templateId}/versions/{templateVersionId}`.
3. The version's `sections[]` array preserves your request order and carries the resolved section IDs. Build a `position → sectionId → heading` mapping from that response, then key the rendered output against it.

<Warning>The auto-generated aggregate the follow-up GET reads is itself subject to the [30-day retention window](/textgen/documents-guided-synthesis#auto-generated-template-aggregates-30-day-retention). Do the mapping read soon after generation (typically in the same processing pass), or persist the mapping in your service.</Warning>

<Note>This is a known DX gap for Path 4 specifically. The roadmap includes returning client-supplied identifiers (or section ordering) directly on the response so the follow-up GET isn't needed.</Note>

## When to use this path

| Scenario                                                                      | Why Path 4                                                          |
| :---------------------------------------------------------------------------- | :------------------------------------------------------------------ |
| Prototyping a new section or schema before promoting into your stored library | Iterate in one request; no authoring overhead.                      |
| One-off generation that doesn't justify creating a section                    | Inline what you need; the auto-generated aggregate is your receipt. |
| Experiments on prompt + schema combinations                                   | Run the same call with variations; compare outputs.                 |

## Related

<Columns cols={2}>
  <Card title="Guided Synthesis overview" href="/textgen/documents-guided-synthesis" icon="wand-sparkles">
    Shared concepts: input context, response shape, errors, 30-day retention.
  </Card>

  <Card title="Section Schemas" href="/textgen/section-schemas" icon="braces">
    Schema patterns for the `outputSchema` shapes you'll define inline.
  </Card>
</Columns>
