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

> ## Agent Instructions
> Install the Courier skill before writing code: `npx skills add trycourier/courier-skills`. It carries the verified SDK shapes and the rules you cannot get wrong.
> Authenticate every request with `Authorization: Bearer <API_KEY>`. A workspace has several environments and each has its own keys, which are plain `pk_` strings with no environment prefix. Start with Test.
> Send with `client.send.message` from the Node SDK (`@trycourier/courier` v7 and later, where the client is the default import). Reference a template by its `nt_` id or its alias.
> A send accepts a bare Elemental element list, but storing content on a template requires the top-level elements wrapped in a channel element.
> Templates and journeys can be built in the Courier app or created through the API. Either way they live in the workspace and are referenced by ID when you send.
> The hosted MCP server is https://mcp.courier.com. For a briefing on what Courier is and when to use it, read https://www.courier.com/llms.txt.
> Prefer the Guides tab for how-do-I questions and the Docs tab for how-does-it-behave questions. The API reference lives under /api-reference.

# Create Preview Run

> Render this template's email content on each of the requested devices.

Returns as soon as the run exists and its render is queued — the screenshots are produced asynchronously. Poll `GET /notifications/{id}/previews/runs/{previewRunId}` until every result reaches a terminal status.

Name the devices either with `device_set_id`, for a saved set, or with `device_ids`, for a one-off list. Exactly one of the two is required. Inline `device_ids` must be ids listed by `GET /previews/devices`; any other id is a 422, refused before the run exists or is billed.

A template that does not exist is a 404. One that exists but cannot be previewed — not a Design Studio template, no email channel, or no such `template_version` — is a 422, also refused before the run exists or is billed.

Preview runs are a metered add-on. A workspace without it, or with its billing suspended, receives a 402.



## OpenAPI

````yaml /openapi-specs/openapi.documented.yml post /notifications/{id}/previews/runs
openapi: 3.0.1
info:
  title: Courier
  description: The Courier REST API for sending and managing notifications across channels.
  version: 0.0.1
servers:
  - url: https://api.courier.com
    description: Production
security: []
tags:
  - name: Send
    description: >-
      Send a message to one or more recipients — users, lists, audiences, or
      tenants — across every channel you have configured.
  - name: Templates
    description: >-
      Create, update, version, publish, and localize notification templates and
      their content.
  - name: Brands
    description: >-
      Manage the logos, colors, and layout that give the templates you send a
      consistent look.
  - name: Routing Strategies
    description: >-
      Define reusable channel routing and failover strategies, and see which
      templates use them.
  - name: Journeys
    description: >-
      Build, version, publish, invoke, and cancel multi-step notification
      workflows, along with the templates scoped to them.
  - name: Broadcasts
    description: >-
      Create a one-off send to a list or audience, author its content, then send
      it immediately or schedule it for later.
  - name: Previews
    description: >-
      Render a template's email content on real email clients and read back the
      screenshots, so you can check how it looks before you send it.
  - name: User Profiles
    description: >-
      Store the contact information Courier delivers to for each user — email,
      phone number, push tokens, and any custom data you send to.
  - name: Tenants
    description: >-
      Manage tenants — the organizations, teams, or accounts your users belong
      to — along with their users and default preferences.
  - name: Audiences
    description: >-
      Define filter-based groups whose membership Courier recalculates as user
      profiles change.
  - name: Lists
    description: >-
      Manage static groups of users that you subscribe explicitly, and send to
      them by list id or list pattern.
  - name: Providers
    description: >-
      Configure the channel providers Courier delivers through, and browse the
      provider types it supports.
  - name: Preference Topics
    description: >-
      Manage the workspace catalog of subscription topics, the sections that
      group them, and publishing the preference page.
  - name: User Preferences
    description: >-
      Read and write a single user's notification preferences, per topic and per
      channel.
  - name: Messages
    description: >-
      Look up the messages Courier has accepted, inspect their delivery history
      and rendered output, and cancel, resend, or archive them.
  - name: Device Tokens
    description: >-
      Register and manage the APNS and FCM device tokens Courier delivers push
      notifications to.
  - name: Tenant Memberships
    description: >-
      Associate a user with one or more tenants, and read or remove those
      associations.
  - name: Tenant Templates
    description: >-
      Manage the templates and template versions scoped to a single tenant,
      including the ones authored in the embedded designer.
  - name: Automations
    description: >-
      Invoke a stored automation template or an ad hoc automation defined in the
      request.
  - name: Digests
    description: >-
      Inspect what has accumulated in a digest schedule and release a digest
      ahead of its next scheduled delivery.
  - name: Translations
    description: >-
      Store and retrieve the translation strings Courier uses to render
      localized template content.
  - name: Track Events
    description: >-
      Record an inbound event that triggers the journeys and automations mapped
      to it.
  - name: Audit Events
    description: >-
      Read the audit trail of configuration and access changes in your
      workspace.
  - name: Authentication
    description: >-
      Issue scoped, short-lived JWTs so client-side SDKs — Inbox, Preferences,
      and the embedded designer — can call Courier as a single user. Server-side
      requests authenticate with your workspace API key instead.
paths:
  /notifications/{id}/previews/runs:
    post:
      tags:
        - Previews
      summary: Create Preview Run
      description: >-
        Render this template's email content on each of the requested devices.


        Returns as soon as the run exists and its render is queued — the
        screenshots are produced asynchronously. Poll `GET
        /notifications/{id}/previews/runs/{previewRunId}` until every result
        reaches a terminal status.


        Name the devices either with `device_set_id`, for a saved set, or with
        `device_ids`, for a one-off list. Exactly one of the two is required.
        Inline `device_ids` must be ids listed by `GET /previews/devices`; any
        other id is a 422, refused before the run exists or is billed.


        A template that does not exist is a 404. One that exists but cannot be
        previewed — not a Design Studio template, no email channel, or no such
        `template_version` — is a 422, also refused before the run exists or is
        billed.


        Preview runs are a metered add-on. A workspace without it, or with its
        billing suspended, receives a 402.
      operationId: notifications_previews_runs_create
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
        - $ref: '#/components/parameters/IdempotencyExpiration'
        - name: id
          in: path
          description: Template ID (nt_ prefix). Must be a Design Studio template.
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreatePreviewRunRequest'
            examples:
              WithDeviceIds:
                value:
                  device_ids:
                    - pvd_1w6dgafr3aaycvv9a8bm996pkc
                    - pvd_34qvmj6p4dbqaa5mpys1ekt9jx
              WithSavedSet:
                value:
                  device_set_id: pvs_01kx4h2jdafq8bk9amzvy6hbv0
                  template_version: published
              WithTestData:
                value:
                  device_set_id: pvs_01kx4h2jdafq8bk9amzvy6hbv0
                  locale: fr-FR
                  data:
                    order_id: '1234'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PreviewRun'
              examples:
                Example:
                  value:
                    id: pvr_01kx4h2jdafq8bk9amzvy6hbv0
                    template_id: nt_01kx4h2jdafq8bk9amzvy6hbv0
                    status: PENDING
                    device_ids:
                      - pvd_1w6dgafr3aaycvv9a8bm996pkc
                      - pvd_34qvmj6p4dbqaa5mpys1ekt9jx
                    created_at: '2026-01-01T00:00:00.000Z'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequest'
              examples:
                MissingDevices:
                  value:
                    type: invalid_request_error
                    message: provide exactly one of device_set_id or device_ids
        '402':
          description: Payment Required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PaymentRequired'
              examples:
                AddOnRequired:
                  value:
                    type: authorization_error
                    message: >-
                      the cross-client previews add-on is required for this
                      workspace
        '404':
          description: Not Found — the template, or the named device set, does not exist.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFound'
              examples:
                TemplateNotFound:
                  value:
                    type: invalid_request_error
                    message: >-
                      notification template nt_01kx4h2jdafq8bk9amzvy6hbv0 not
                      found
        '422':
          description: >-
            Unprocessable Entity — the template cannot be previewed, or a device
            id is unknown.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnprocessableEntity'
              examples:
                UnknownDevice:
                  value:
                    type: validation_error
                    message: 'unknown device id: pvd_01nope'
                NoSuchVersion:
                  value:
                    type: validation_error
                    message: template nt_01kx4h2jdafq8bk9amzvy6hbv0 has no version v009
                NotDesignStudio:
                  value:
                    type: validation_error
                    message: not a Design Studio template
      security:
        - BearerAuth: []
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import Courier from '@trycourier/courier';


            const client = new Courier({
              apiKey: process.env['COURIER_API_KEY'], // This is the default and can be omitted
            });


            const previewRun = await
            client.notifications.previews.runs.create('id', {
              device_ids: ['pvd_1w6dgafr3aaycvv9a8bm996pkc', 'pvd_34qvmj6p4dbqaa5mpys1ekt9jx'],
            });


            console.log(previewRun.id);
        - lang: Python
          source: |-
            import os
            from courier import Courier

            client = Courier(
                api_key=os.environ.get("COURIER_API_KEY"),  # This is the default and can be omitted
            )
            preview_run = client.notifications.previews.runs.create(
                id="id",
                device_ids=["pvd_1w6dgafr3aaycvv9a8bm996pkc", "pvd_34qvmj6p4dbqaa5mpys1ekt9jx"],
            )
            print(preview_run.id)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/trycourier/courier-go/v4\"\n\t\"github.com/trycourier/courier-go/v4/option\"\n)\n\nfunc main() {\n\tclient := courier.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tpreviewRun, err := client.Notifications.Previews.Runs.New(\n\t\tcontext.TODO(),\n\t\t\"id\",\n\t\tcourier.NotificationPreviewRunNewParams{\n\t\t\tCreatePreviewRunRequest: courier.CreatePreviewRunRequestParam{},\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", previewRun.ID)\n}\n"
        - lang: Java
          source: >-
            package com.courier.example;


            import com.courier.client.CourierClient;

            import com.courier.client.okhttp.CourierOkHttpClient;

            import
            com.courier.models.notifications.previews.runs.CreatePreviewRunRequest;

            import com.courier.models.notifications.previews.runs.PreviewRun;

            import
            com.courier.models.notifications.previews.runs.RunCreateParams;


            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    CourierClient client = CourierOkHttpClient.fromEnv();

                    RunCreateParams params = RunCreateParams.builder()
                        .id("id")
                        .createPreviewRunRequest(CreatePreviewRunRequest.builder().build())
                        .build();
                    PreviewRun previewRun = client.notifications().previews().runs().create(params);
                }
            }
        - lang: Ruby
          source: |-
            require "courier"

            courier = Courier::Client.new(api_key: "My API Key")

            preview_run = courier.notifications.previews.runs.create("id")

            puts(preview_run)
        - lang: PHP
          source: >-
            <?php


            require_once dirname(__DIR__) . '/vendor/autoload.php';


            use Courier\Client;

            use Courier\Core\Exceptions\APIException;


            $client = new Client(apiKey: getenv('COURIER_API_KEY') ?: 'My API
            Key');


            try {
              $previewRun = $client->notifications->previews->runs->create(
                'id',
                data: ['foo' => 'bar'],
                deviceIDs: [
                  'pvd_1w6dgafr3aaycvv9a8bm996pkc', 'pvd_34qvmj6p4dbqaa5mpys1ekt9jx'
                ],
                deviceSetID: 'device_set_id',
                locale: 'locale',
                templateVersion: 'draft',
                idempotencyKey: 'order-ORD-456-user-123',
                xIdempotencyExpiration: '1785312000',
              );

              var_dump($previewRun);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: C#
          source: >-
            using System;

            using TryCourier;

            using TryCourier.Models.Notifications.Previews.Runs;


            CourierClient client = new();


            RunCreateParams parameters = new() { ID = "id" };


            var previewRun = await
            client.Notifications.Previews.Runs.Create(parameters);


            Console.WriteLine(previewRun);
        - lang: CLI
          source: |-
            courier notifications:previews:runs create \
              --api-key 'My API Key' \
              --id id
components:
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      description: >-
        A unique key that makes this request idempotent. If Courier receives
        another request with the same `Idempotency-Key`, it returns the stored
        response from the first request without performing the operation again
        (including the original status code and any error). Use it to safely
        retry `POST` requests after network failures without risking duplicate
        sends. The key is scoped to this endpoint.
      schema:
        type: string
      example: order-ORD-456-user-123
    IdempotencyExpiration:
      name: x-idempotency-expiration
      in: header
      required: false
      description: >-
        How long the idempotency key remains valid, as a Unix epoch timestamp in
        seconds or an ISO 8601 date string. Only applies when `Idempotency-Key`
        is provided. If omitted, the key is retained for 25 hours; the maximum
        is 1 year.
      schema:
        type: string
      example: '1785312000'
  schemas:
    CreatePreviewRunRequest:
      title: CreatePreviewRunRequest
      type: object
      description: >-
        Request body for creating a preview run of the template in the path.
        Provide exactly one of `device_set_id` or `device_ids`. The template is
        the path's `{id}`; a `template_id` here is an unknown key and a 400.
      additionalProperties: false
      properties:
        device_set_id:
          type: string
          description: >-
            A saved device set naming the devices to render on. Mutually
            exclusive with `device_ids`.
        device_ids:
          type: array
          description: >-
            The devices to render on, by `PreviewDevice.id`, for a one-off run.
            Mutually exclusive with `device_set_id`.
          items:
            type: string
        template_version:
          type: string
          description: >-
            Which version of the template to render. Omit for the latest saved
            draft, which always exists and is what the editor shows. `published`
            renders the live version; a zero-padded `v002` renders that specific
            publish. Versions are 1-based, so `v000` is not a version, and the
            unpadded `v2` is rejected — that spelling belongs to journeys'
            AutomationVersionId, a different scheme in which `v0` means
            published.
          example: draft
        locale:
          type: string
          description: Render the template's content for this locale, e.g. "fr-FR".
        data:
          type: object
          additionalProperties: true
          description: >-
            Template variables to render with, the same shape as the `data`
            object on a send.
    PreviewRun:
      title: PreviewRun
      type: object
      description: One render of a template across a set of devices. Billable.
      properties:
        id:
          type: string
          description: Unique identifier for the preview run.
        template_id:
          type: string
          description: The template that was rendered.
        template_version:
          type: string
          description: >-
            The version of the template that was rendered — `draft`, or a
            zero-padded published version such as `v002`. Absent until the
            render settles.
        status:
          $ref: '#/components/schemas/PreviewRunStatus'
        device_ids:
          type: array
          description: >-
            The devices this run was submitted for, snapshotted when the run was
            created.
          items:
            type: string
        failure_reason:
          $ref: '#/components/schemas/PreviewRunFailureReason'
        created_at:
          type: string
          description: ISO-8601 timestamp of when the run was created.
      required:
        - id
        - template_id
        - status
        - device_ids
        - created_at
    BadRequest:
      title: BadRequest
      type: object
      properties:
        type:
          type: string
          enum:
            - invalid_request_error
      required:
        - type
      allOf:
        - $ref: '#/components/schemas/BaseError'
    PaymentRequired:
      title: PaymentRequired
      type: object
      properties:
        type:
          type: string
          enum:
            - authorization_error
      required:
        - type
      allOf:
        - $ref: '#/components/schemas/BaseError'
    NotFound:
      title: NotFound
      type: object
      properties:
        type:
          type: string
          enum:
            - invalid_request_error
      required:
        - type
      allOf:
        - $ref: '#/components/schemas/BaseError'
    UnprocessableEntity:
      title: UnprocessableEntity
      type: object
      properties:
        type:
          type: string
          enum:
            - invalid_request_error
      required:
        - type
      allOf:
        - $ref: '#/components/schemas/BaseError'
    PreviewRunStatus:
      title: PreviewRunStatus
      type: string
      description: >-
        Where the run itself has got to. `PENDING` and `RENDERED` mean Courier
        is still preparing the email, `SUBMITTED` means it is with the rendering
        service, and `COMPLETED` means every device has reported. `FAILED` is
        the run as a whole failing — an individual device failing never fails
        the run.
      enum:
        - PENDING
        - RENDERED
        - SUBMITTED
        - COMPLETED
        - FAILED
    PreviewRunFailureReason:
      title: PreviewRunFailureReason
      type: string
      description: >-
        Why the run failed, when `status` is `FAILED`. `NO_EMAIL_CHANNEL` and
        `TEMPLATE_NOT_SUPPORTED` mean there was nothing to render;
        `ALL_DEVICES_UNSUPPORTED` means every requested device has been retired
        and the request can be fixed by choosing others.
      enum:
        - TEMPLATE_NOT_SUPPORTED
        - NO_EMAIL_CHANNEL
        - RENDER_FAILED
        - ALL_DEVICES_UNSUPPORTED
        - VENDOR_ERROR
    BaseError:
      title: BaseError
      type: object
      properties:
        message:
          type: string
          description: A message describing the error that occurred.
      required:
        - message
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer

````