
# Create a preview

Build the site to a preview URL instead of deploying live. To check a large change before it reaches visitors, build a preview, read it back, then [promote](/api/previews/post-previews-promote) it.

Preview builds are metered like deploys (quota and cooldown), and create, rebuild, and promote all spend from the shared hourly budget described under [rate limiting](/api/overview#rate-limiting). Creating a preview expires the site's previous previews.

A `workspace` preview created with a token comes back with no `authUrl`, because a token is not a workspace member. To fetch the preview's content back, create it with `public` or `password` visibility.

```sh
POST https://sitepaste.com/api/v1/public/sites/{siteId}/previews
```

Requires the `deploy` scope.

## Usage

```bash
curl -X POST "https://sitepaste.com/api/v1/public/sites/default/previews" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "visibility": "public" }'
```

## Authorizations

| Header | Type | Required | Description |
|--------|------|----------|-------------|
| Authorization | string | Yes | Bearer token (`Authorization: Bearer sp_...`). Created in the dashboard under Account > Tokens. See [authentication](/api/authentication). |

## Body

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| visibility | string | Yes | `public`, `password`, or `workspace`. It decides who can open the preview, whatever protects the live site. A page with its own password still asks for it in a `public` or `password` preview. Members signed in to a `workspace` preview can read it without its password. |
| password | string | For password visibility | The preview's password, at most 72 bytes. A longer one is refused with 422 and `fields.password` before anything else happens. |

## Response

202 Accepted with the preview record (`status: "building"`, and `createdByName` set to the token's name), in the shape [list previews](/api/previews/get-previews) describes, and a `Location` header naming the preview to poll. Poll that URI, which is also [GET /sites/{siteId}/previews/{previewId}](/api/previews/get-previews-previewid), until `ready`, then open `url`.

402 with `"code": "pro_features_in_use"` when the workspace is not on Pro but the site uses Pro features, as for a [deploy](/api/deployments/post-deployments#errors).