# Templates and voices

A template decides what kind of article Unspar writes, like a guide or a comparison. A voice decides how it sounds. With these endpoints, your code picks both, makes your own copies and builds a voice from your writing.

Web version: https://www.unspar.com/docs/api/templates/

Every article uses one template and, optionally, one voice. A template is the recipe for a specific kind of text. It sets how much research goes in and how the article is structured. A voice sets the tone, like how long the sentences are and how formal the writing sounds.

Most integrations don't need these endpoints right away. If you leave out `template`, an article uses the project's default, and every new project starts with General Guide. You'll only need these endpoints when an article calls for a different format or when you want to use your own style. In the web app, the templates appear in the **Template** field on the Create page, and the voices under [Voices](https://app.unspar.com/voices).

## List the templates

`GET /templates` returns both the built-in templates and your team's own copies. Built-ins have readable IDs like `template:builtin:general_guide` and can't be edited, while your copies use the usual 26-character IDs. By default, the list only includes active templates. Pass `status=archived` or `status=all` to see the rest.

These fields help you choose:

| Field           | What it tells you                                                                                  |
| --------------- | -------------------------------------------------------------------------------------------------- |
| `review_status` | `tested` means we reviewed the built-in for its kind of text. `experimental` means we haven't yet. |
| `best_for`      | When the template fits.                                                                            |
| `avoid_when`    | When you shouldn't use it.                                                                         |

`GET /templates/{template}` returns a single template along with its full configuration. For a breakdown of each built-in, see [Choosing a template](https://www.unspar.com/docs/guides/choosing-a-template/).

## Ask which template fits a topic

If you aren't sure which template fits an article, you can ask the API. `POST /templates/recommend` takes a topic and an optional project. The call is free and doesn't create anything.

```sh
curl -X POST https://app.unspar.com/api/v1/templates/recommend \
  -H "Authorization: Bearer $UNSPAR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"topic": "How to choose an e-bike for a hilly commute", "project": "<project-id>"}'
```

The response has three parts:

| Field          | What it has                                                 |
| -------------- | ----------------------------------------------------------- |
| `preferred`    | The project's default template, if it has one.              |
| `recommended`  | The template Unspar suggests for this topic, with a reason. |
| `alternatives` | Other templates that fit, each with a reason.               |

Unspar only recommends tested templates. Experimental ones like Comparison or Op-Ed won't appear here, even if they fit the topic, though you can still use them by passing their ID as `template`.

## Make your own template

Built-in templates come with detailed writing instructions that a blank template lacks. Because of that, your own template always starts as a copy of the closest built-in, and you only change what you need.

1. Copy a template with `POST /templates/duplicate` and the body `{"template": "template:builtin:general_guide"}`. This gives you a team copy named "General Guide (Copy)".
2. Read the copy's current `revision` with `GET /templates/{template}`.
3. Send your changes with `PATCH /templates/{template}`. Any change to `configuration` requires that `revision` and a one-line `reason`.

In this example, the copy is at revision 3:

```sh
curl -X PATCH https://app.unspar.com/api/v1/templates/<template-id> \
  -H "Authorization: Bearer $UNSPAR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"revision": 3, "reason": "Use short headings.", "configuration": {"style_guardrails": {"heading_guidance": "Use short headings."}}}'
```

`PATCH` updates only the fields you send. Nested settings merge, lists are replaced as a whole, and `null` clears a field. If someone else edited the template since you read it, the API returns `409`. Fetch the template again and resend your update with the new `revision`. You don't need a revision to change the name, description, or status.

You can also create a template with `POST /templates` using the source you specify in `based_on`. Leaving out `based_on` only works if the team owner has enabled **Allow templates from scratch** in [Team settings](https://app.unspar.com/settings).

## Keep a copy up to date

A copy remembers which template it came from, and it won't change automatically when the source is updated later. You can use these calls to compare and manage your copies:

| What you want                  | How                                                                                                                                            |
| ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| See what changed               | `GET /templates/{template}/compare` shows what you changed in the copy, along with what changed in the source since you copied it.             |
| Take over the source's changes | Send them in a `PATCH` with the current `revision` and `"rebase_on_source": true`.                                                             |
| Hide a copy                    | Set `status` to `archived`. Projects and Project Auto setups that use it keep working.                                                         |
| Delete a copy                  | `DELETE /templates/{template}`. This fails while an active Project Auto uses it. The response lists the projects that had it as their default. |

`GET /image-presets` lists the available image styles, such as Editorial photo. You can use their IDs to set the [look of a project's images](https://www.unspar.com/docs/api/projects/#set-the-look-of-the-images).

## Use a voice

`GET /voices` lists every voice you can use, including built-in voices (with IDs like `voice:builtin:friendly_explainer`) and your team's active voices. If you don't specify a voice, an article uses the template's own style.

You can set a voice in one of two places:

| Where                                                                      | What it does                                   |
| -------------------------------------------------------------------------- | ---------------------------------------------- |
| `voice` in [`POST /articles`](https://www.unspar.com/docs/api/articles/#start-an-article)        | Sets the voice for this one article.           |
| `defaults.voice` on the [project](https://www.unspar.com/docs/api/projects/#change-the-settings) | Sets the voice for the project's new articles. |

When more than one voice applies, the article's voice takes priority, followed by the template's voice, and then the project's voice. An article keeps the voice it started with, even if you edit that voice later. To see how a voice shapes the writing, read [Voices](https://www.unspar.com/docs/guides/voices/).

## Make your own voice

Custom voices start out as drafts. You can edit a draft freely, though articles can't use it until you activate it. `GET /voices/manage` lists all of your team's voices along with their current state.

| Request                                | What happens                                                                                                                                                      |
| -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `POST /voices/builtin/{key}/duplicate` | Copies a built-in voice into a draft.                                                                                                                             |
| `POST /voices/{voice}/duplicate`       | Copies one of your own voices into a draft.                                                                                                                       |
| `POST /voices`                         | Creates a draft from scratch. It needs a `brief` with instructions for the writer and a short `preservation_brief` that says what must survive the editing steps. |
| `PATCH /voices/{voice}`                | Updates only the fields you send.                                                                                                                                 |
| `POST /voices/{voice}/activate`        | Makes the voice available for articles.                                                                                                                           |
| `POST /voices/{voice}/archive`         | Retires the voice.                                                                                                                                                |

You can't delete a voice or reactivate an archived one. If you want to bring an old voice back, duplicate it.

## Build a voice from your writing

Unspar can read your writing and build a voice from it for 5 credits. Make sure you only use texts that you wrote or have the right to use.

1. Send up to 10 article URLs, or your domain, as `inputs` to `POST /voice-extractions/sources`. Unspar finds the articles and returns them as candidates, each with an `id`. This step is free.
2. Start the analysis with `POST /voice-extractions`. Send a `name` and the candidate IDs as `source_candidate_ids`. Pasted text goes in `samples`. If you only have pasted text, skip step 1 and send `name` and `samples`.
3. Poll `GET /voice-extractions/{attempt}` until `status` is `completed`. The new voice starts as a draft, and its ID is in `resulting_voice_profile_id`.
4. Review the draft, adjust it with `PATCH /voices/{voice}` if needed, and activate it with `POST /voices/{voice}/activate`.

The request in step 2 looks like this:

```sh
curl -X POST https://app.unspar.com/api/v1/voice-extractions \
  -H "Authorization: Bearer $UNSPAR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "My blog voice", "source_candidate_ids": ["<candidate-id>", "<candidate-id>"]}'
```

How much text you provide affects how accurate the voice will be. Aim for at least 2,000 words.

| Amount of text         | What happens                |
| ---------------------- | --------------------------- |
| Fewer than 300 words   | Unspar can't build a voice. |
| 300 to 2,000 words     | The voice is less reliable. |
| More than 12,000 words | Unspar ignores the rest.    |

If the analysis fails, `POST /voice-extractions/{attempt}/retry` runs it again with new `samples`, such as `{"samples": "..."}`. Unspar holds another 5 credits.

## Endpoint reference

### GET /api/v1/templates

`listTemplates`: List reusable content templates.

Permission: `unspar:templates:read`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `status` | query | "active", "archived", "all" | no | Active by default. Archived returns team templates only. All includes visible built-ins and team templates in either state. Default "active". |
| `page` | query | integer | no | Minimum 1. |
| `per_page` | query | integer | no | Minimum 1. Maximum 100. |
| `q` | query | string | no |  |
| `origin` | query | "builtin", "team" | no |  |
| `language` | query | string | no |  |
| `mode` | query | "new_article", "refresh_existing_content", "translate_existing_content" | no |  |
| `selectable` | query | boolean | no |  |
| `sort` | query | "key", "-key", "created_at", "-created_at" | no |  |

Responses: 200 Content template list.

### POST /api/v1/templates

`createTemplate`: Create a recorded variant of an existing template.

Provide based_on with a selectable built-in or active same-team template id, a name, optional sparse settings and a one-line reason for changed reusable settings. A variant stores a copy and its source snapshot. Later source edits never change it. Without based_on, creation requires the owner-controlled allow_from_scratch_templates setting, default false; otherwise 422 names POST /api/v1/templates/duplicate. Existing source-less templates remain editable.

Permission: `unspar:templates:write`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | no | Optional client key that makes a repeated POST replay the first response instead of running twice. Up to 255 characters. |

| Body field | Type | Required | Description |
| --- | --- | --- | --- |
| `based_on` | string | no | Selectable built-in id or active same-team template public id. |
| `reason` | string | no | One-line reason, required when reusable settings differ from the source. Up to 500 characters. |
| `name` | string | yes | Up to 255 characters. |
| `description` | string | no | Up to 1000 characters. |
| `language` | string | no | Up to 20 characters. |
| `mode_scope` | "new_article", "refresh_existing_content", "translate_existing_content" | no |  |
| `article_depth` | string | no |  |
| `configuration` | object | no | Reusable article configuration. Nested voice and image preset references use public identifiers, for example `voice:builtin:friendly_explainer`, a team voice ULID, `image_preset:builtin:editorial_illustration`, or a team image preset ULID. |

Responses: 201 Content template.; 409 The request conflicts with current resource state or required confirmation.; 422 The request body failed validation; `error.details` lists the fields.

### POST /api/v1/templates/recommend

`recommendTemplates`: Recommend tested recipes without creating content or spending credits

Returns the resolved project default as preferred when available, including custom, experimental or archived defaults. Built-in recommendations and alternatives require tested review status and picker visibility. Experimental exact intents receive a tested fallback and warning. Expert Reply is restricted to journalist requests.

Permission: `unspar:templates:read`

| Body field | Type | Required | Description |
| --- | --- | --- | --- |
| `topic` | string | no | Up to 2000 characters. |
| `brief` | string | no | Up to 10000 characters. |
| `project` | string | no | Accessible project public id. |

Responses: 200 Deterministic recommendations.; 422 The request body failed validation; `error.details` lists the fields.

### POST /api/v1/templates/duplicate

`duplicateTemplate`: Duplicate a built-in or team template into the team library.

The right way to adapt a template. Duplicate the closest built-in, then update only the fields the requirement needs and keep its writing instructions. Note that updateTemplate replaces the whole configuration object, so send the complete duplicated configuration with your changes applied.

Permission: `unspar:templates:write`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | no | Optional client key that makes a repeated POST replay the first response instead of running twice. Up to 255 characters. |

| Body field | Type | Required | Description |
| --- | --- | --- | --- |
| `template` | string | yes | A team template public id or a built-in identifier such as `template:builtin:seo_blog`. |

Responses: 201 Content template.; 422 The request body failed validation; `error.details` lists the fields.

### GET /api/v1/templates/{template}/compare

`compareTemplate`: Compare the recorded source, saved variant and current source

Variant changes and later source changes are separate. Archived or deleted sources are unavailable; the copy and original snapshot remain usable. Source-less rows have null original and based_on. No settings change automatically. Embedded configuration references use public ids.

Permission: `unspar:templates:read`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `template` | path | string | yes |  |

Responses: 200 Source comparison; 404 The resource does not exist or belongs to another team (`resource_not_found`).

### GET /api/v1/templates/{template}

`getTemplate`: Show one content template.

Permission: `unspar:templates:read`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `template` | path | string | yes |  |

Responses: 200 Content template.

### PATCH /api/v1/templates/{template}

`updateTemplate`: Update a team content template.

Require the current revision for configuration, language, mode_scope or article_depth changes or rebase_on_source; it is optional for status, name and description edits and checked when supplied. Omitted fields survive; nested maps merge and lists replace, including empty lists. Voice references and individual media blocks replace atomically. Explicit null clears nullable fields. Changed reusable settings need a one-line reason. A stale revision returns 409; reload and reapply explicitly. The server computes overrides and increments revision.

Permission: `unspar:templates:write`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `template` | path | string | yes |  |
| `Idempotency-Key` | header | string | no | Optional client key that makes a repeated POST replay the first response instead of running twice. Up to 255 characters. |

| Body field | Type | Required | Description |
| --- | --- | --- | --- |
| `revision` | integer | no | Minimum 1. |
| `rebase_on_source` | boolean | no | With true and the current revision, refresh the recorded source snapshot and fingerprint and recompute overrides while keeping the template values. An unavailable source returns 422. |
| `reason` | string | no | Up to 500 characters. |
| `status` | "active", "archived" | no | Revision is optional for status changes and checked when supplied. Archived templates keep their configuration, ids and references. |
| `name` | string | no | Up to 255 characters. |
| `description` | string | no | Up to 1000 characters. |
| `language` | string | no | Up to 20 characters. |
| `mode_scope` | "new_article", "refresh_existing_content", "translate_existing_content" | no |  |
| `article_depth` | string | no |  |
| `configuration` | object | no | Reusable article configuration. Nested voice and image preset references use public identifiers, for example `voice:builtin:friendly_explainer`, a team voice ULID, `image_preset:builtin:editorial_illustration`, or a team image preset ULID. |

Responses: 200 Content template.; 409 The request conflicts with current resource state or required confirmation.; 422 The request body failed validation; `error.details` lists the fields.

### DELETE /api/v1/templates/{template}

`deleteTemplate`: Delete a team content template.

Permission: `unspar:templates:write`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `template` | path | string | yes |  |
| `Idempotency-Key` | header | string | no | Optional client key that makes a repeated POST replay the first response instead of running twice. Up to 255 characters. |

Responses: 200 Deleted content template and affected project defaults.; 409 The request conflicts with current resource state or required confirmation.; 422 The request body failed validation; `error.details` lists the fields.

### GET /api/v1/image-presets

`listImagePresets`: List image presets available for template configuration.

Permission: `unspar:templates:read`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `page` | query | integer | no | Minimum 1. |
| `per_page` | query | integer | no | Minimum 1. Maximum 100. |
| `q` | query | string | no |  |
| `origin` | query | "builtin", "team" | no |  |
| `selectable` | query | boolean | no |  |

Responses: 200 Image preset list.

### GET /api/v1/voices

`listVoices`: List writing voices.

Permission: `unspar:voices:read`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `page` | query | integer | no | Minimum 1. |
| `per_page` | query | integer | no | Minimum 1. Maximum 100. |
| `q` | query | string | no |  |
| `origin` | query | "builtin", "team" | no |  |
| `status` | query | "active" | no |  |
| `selectable` | query | boolean | no |  |
| `sort` | query | "key", "-key", "created_at", "-created_at" | no |  |

Responses: 200 Writing voice list.

### POST /api/v1/voices

`createVoice`: Create a draft team voice.

Permission: `unspar:voices:write`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | no | Optional client key that makes a repeated POST replay the first response instead of running twice. Up to 255 characters. |

| Body field | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | yes | Up to 255 characters. |
| `description` | string | no | Up to 1000 characters. |
| `profile` | object | yes |  |
| `brief` | string | yes | Up to 3500 characters. |
| `preservation_brief` | string | yes | Up to 1000 characters. |

Responses: 201 Writing voice.; 422 The request body failed validation; `error.details` lists the fields.

### GET /api/v1/voices/manage

`listManagedVoices`: List team voices across draft, active, and archived states.

Permission: `unspar:voices:write`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `page` | query | integer | no | Minimum 1. |
| `per_page` | query | integer | no | Minimum 1. Maximum 100. |
| `q` | query | string | no |  |
| `status` | query | "draft", "active", "archived" | no |  |
| `sort` | query | "name", "-name", "status", "-status", "created_at", "-created_at" | no |  |

Responses: 200 Writing voice list.

### POST /api/v1/voices/builtin/{key}/duplicate

`duplicateBuiltInVoice`: Duplicate a built-in voice into a team draft.

Permission: `unspar:voices:write`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `key` | path | string | yes |  |

Responses: 201 Writing voice.; 422 The request body failed validation; `error.details` lists the fields.

### GET /api/v1/voices/{voice}

`getVoice`: Show one writing voice.

Permission: `unspar:voices:read`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `voice` | path | string | yes |  |

Responses: 200 Writing voice.

### PATCH /api/v1/voices/{voice}

`updateVoice`: Partially update a team voice while preserving omitted fields.

Permission: `unspar:voices:write`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `voice` | path | string | yes |  |

| Body field | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | no | Up to 255 characters. |
| `description` | string | no | Up to 1000 characters. |
| `profile` | object | no |  |
| `brief` | string | no | Up to 3500 characters. |
| `preservation_brief` | string | no | Up to 1000 characters. |

Responses: 200 Writing voice.; 409 The request conflicts with current resource state or required confirmation.; 422 The request body failed validation; `error.details` lists the fields.

### POST /api/v1/voices/{voice}/activate

`activateVoice`: Activate a draft team voice.

Permission: `unspar:voices:write`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `voice` | path | string | yes |  |

Responses: 200 Writing voice.; 409 The request conflicts with current resource state or required confirmation.

### POST /api/v1/voices/{voice}/archive

`archiveVoice`: Archive a draft or active team voice.

Permission: `unspar:voices:write`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `voice` | path | string | yes |  |

Responses: 200 Archived writing voice and affected project defaults.; 409 The request conflicts with current resource state or required confirmation.

### POST /api/v1/voices/{voice}/duplicate

`duplicateVoice`: Duplicate a team voice into a new draft.

Permission: `unspar:voices:write`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `voice` | path | string | yes |  |

Responses: 201 Writing voice.; 422 The request body failed validation; `error.details` lists the fields.

### POST /api/v1/voice-extractions/sources

`discoverVoiceSources`: Discover voice source candidates from URLs and pasted samples.

Permission: `unspar:voices:write`

| Body field | Type | Required | Description |
| --- | --- | --- | --- |
| `inputs` | array of string | no |  |
| `pasted_samples` | string | no |  |

Responses: 200 Discovered voice source candidates.; 422 The request body failed validation; `error.details` lists the fields.

### POST /api/v1/voice-extractions

`createVoiceExtraction`: Queue extraction of a draft voice from samples and source candidates.

Accepted attempts reserve credits and dispatch extraction asynchronously.

Permission: `unspar:generation:write`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | no | Optional client key that makes a repeated POST replay the first response instead of running twice. Up to 255 characters. |

| Body field | Type | Required | Description |
| --- | --- | --- | --- |
| `samples` | string | no |  |
| `name` | string | yes | Up to 255 characters. |
| `description` | string | no | Up to 1000 characters. |
| `source_candidate_ids` | array of string | no |  |

Responses: 202 Voice extraction attempt.; 402 The team does not have enough credits for this operation.; 422 The request body failed validation; `error.details` lists the fields.

### GET /api/v1/voice-extractions/{attempt}

`getVoiceExtraction`: Show one voice extraction attempt.

Permission: `unspar:voices:write`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `attempt` | path | string | yes |  |

Responses: 200 Voice extraction attempt.

### POST /api/v1/voice-extractions/{attempt}/retry

`retryVoiceExtraction`: Retry a failed or cancelled extraction with fresh samples.

Permission: `unspar:generation:write`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | no | Optional client key that makes a repeated POST replay the first response instead of running twice. Up to 255 characters. |
| `attempt` | path | string | yes |  |

| Body field | Type | Required | Description |
| --- | --- | --- | --- |
| `samples` | string | yes |  |
| `name` | string | no | Up to 255 characters. |
| `description` | string | no | Up to 1000 characters. |

Responses: 202 Voice extraction attempt.; 402 The team does not have enough credits for this operation.; 409 The request conflicts with current resource state or required confirmation.; 422 The request body failed validation; `error.details` lists the fields.
