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

# Templates API

> List templates and retrieve template details for generation setup.

Use the Templates API to discover available templates programmatically and retrieve template details before starting a generation flow.

This is useful when building a custom front end, internal selection layer, or automated content workflow.

## Template Overview

<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: '12px', margin: '1.5rem 0' }}>
  <div style={{ border: '1px solid rgba(128,128,128,0.20)', borderRadius: '14px', padding: '16px', background: 'rgba(255,255,255,0.04)' }}>
    <div style={{ fontWeight: 800 }}>Structure</div>
    <div style={{ fontSize: '13px', color: 'var(--colors-content-secondary)' }}>Defines the content format and sections.</div>
  </div>

  <div style={{ border: '1px solid rgba(128,128,128,0.20)', borderRadius: '14px', padding: '16px', background: 'rgba(255,255,255,0.04)' }}>
    <div style={{ fontWeight: 800 }}>Inputs</div>
    <div style={{ fontSize: '13px', color: 'var(--colors-content-secondary)' }}>Defines required user-provided fields.</div>
  </div>

  <div style={{ border: '1px solid rgba(128,128,128,0.20)', borderRadius: '14px', padding: '16px', background: 'rgba(255,255,255,0.04)' }}>
    <div style={{ fontWeight: 800 }}>Category</div>
    <div style={{ fontSize: '13px', color: 'var(--colors-content-secondary)' }}>Groups templates by content purpose.</div>
  </div>

  <div style={{ border: '1px solid rgba(128,128,128,0.20)', borderRadius: '14px', padding: '16px', background: 'rgba(255,255,255,0.04)' }}>
    <div style={{ fontWeight: 800 }}>Generation</div>
    <div style={{ fontSize: '13px', color: 'var(--colors-content-secondary)' }}>Guides request setup before submission.</div>
  </div>
</div>

## List Templates

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
GET https://api.writerzroom.com/api/templates
Authorization: Bearer YOUR_API_KEY
```

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "templates": [
    {
      "id": "blog_article_generator",
      "name": "Blog Article",
      "category": "marketing",
      "description": "Long-form educational, informative, or thought leadership content"
    },
    {
      "id": "research_paper_template",
      "name": "Research Paper",
      "category": "academic",
      "description": "Formal, evidence-driven, analytically structured content"
    }
  ]
}
```

## Get Template by Slug

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
GET https://api.writerzroom.com/api/templates/{slug}
Authorization: Bearer YOUR_API_KEY
```

## Supported Operations

| Operation      | Description                                                         |
| -------------- | ------------------------------------------------------------------- |
| List templates | Retrieve all available templates                                    |
| Get template   | Retrieve one template by slug                                       |
| Read metadata  | Access name, type, description, category, and required input fields |
| Build forms    | Use template fields to generate frontend input forms                |

## Integration Flow

<Steps>
  <Step title="Fetch available templates">
    Call `GET /templates` to retrieve the current template catalog.
  </Step>

  <Step title="Select a template">
    Use the template slug as the `template_id` in generation requests.
  </Step>

  <Step title="Read input requirements">
    Retrieve template details to understand required fields and optional parameters.
  </Step>

  <Step title="Build the request form">
    Use the template response to guide user input collection.
  </Step>

  <Step title="Submit generation">
    Send the selected template, style profile, and structured input to `POST /api/generate`.
  </Step>
</Steps>

## Best Practice

Use template detail responses to drive your form layer. This makes your integration more resilient because input requirements come from the template definition instead of hard-coded assumptions.

<AccordionGroup>
  <Accordion title="Should templates be hardcoded?">
    Avoid hardcoding template catalogs in production integrations. Fetch templates from the API so your interface stays aligned with WriterzRoom updates.
  </Accordion>

  <Accordion title="What does a template control?">
    A template controls content type, required inputs, structure, section expectations, and output format.
  </Accordion>

  <Accordion title="How does this relate to style profiles?">
    Templates define the structure of the output. Style profiles define tone, voice, pacing, audience fit, and writing behavior.
  </Accordion>
</AccordionGroup>

<Tip>
  Use `/templates/{slug}` before generation when you need to build dynamic forms or validate required fields.
</Tip>

<CardGroup cols={2}>
  <Card title="Style Profiles API" icon="sliders-horizontal" href="/api/style-profiles-api">
    Retrieve available writing styles for generation setup.
  </Card>

  <Card title="Generate Content" icon="sparkles" href="/api/generate-content">
    Submit a request using the selected template.
  </Card>
</CardGroup>
