# Sirv for Payload

![Payload CMS logo](https://sirv.sirv.com/website/payload-logo.svg)

Browse, search and pick media from your Sirv account without leaving the Payload admin panel.

Using an AI coding agent?

Install the [`image-optimization`](https://www.skills.sh/sirv/image-optimization-skill/image-optimization) skill, and your agent can set up Sirv images in your project. Ask in plain words, such as “Serve our product images from Sirv and make them load faster.” [See all 8 skills](/help/rest-api/sirv-skills-for-ai-agents/)

The Sirv plugin for Payload CMS adds a full Sirv DAM browser to your admin.

Editors pick **images**, **videos**, **[360 spins](/help/spin/getting-started/how-spin-files-are-created/)**, **[Sirv Media Viewer](/help/sirv-media-viewer/)** assets and **[3D models](/help/sirv-media-viewer/media-types/3d-model/)** (glTF/GLB) from Sirv.

Your frontend delivers them through Sirv’s global CDN, resized, optimized and in the best format for every visitor.

[Alt text](/help/image-management/add-alt-tags-images-automatically-ai/) and captions are filled in automatically from your Sirv asset metadata, and galleries support multi-select and drag-to-reorder.

Your Sirv **secret never reaches the browser**. It is stored encrypted on your own server and used only to mint short-lived access tokens.

## Requirements

-   A [Sirv account](https://app.sirv.com/signup) (free or paid) and its [REST API](/help/rest-api/sirv-rest-api/) **Client ID** and **Client Secret** from [Settings > API access](https://app.sirv.com/settings/api).
-   A Payload CMS **v3** project (React 19 / Next.js 15).

## Installation

The plugin is a standard Payload plugin published on npm. Install it, add it to your config, regenerate the import map and import the stylesheet - once.

1.  Install the package:
    
    ```bash
    pnpm add @sirv/payload-plugin
    ```
    
2.  Add `sirvPlugin()` to your Payload config and drop the field factories into any collection:
    
    ```tsx
    import { buildConfig } from 'payload';
    import {
      sirvPlugin,
      sirvMediaField,
      sirvMediaListField,
      sirvAssetUrlField,
    } from '@sirv/payload-plugin';
    
    
    export default buildConfig({
      plugins: [sirvPlugin()],
      collections: [
        {
          slug: 'posts',
          fields: [
            { name: 'title', type: 'text' },
            sirvMediaField({ name: 'hero' }),
            sirvMediaListField({ name: 'gallery' }),
            sirvAssetUrlField({ name: 'attachment' }),
          ],
        },
      ],
    });
    ```
    
3.  Regenerate Payload’s import map so the admin can resolve the plugin’s components. Run this after installing and after any upgrade that changes the component set:
    
    ```bash
    pnpm payload generate:importmap
    ```
    
4.  Import the admin stylesheet once, in your app’s `src/app/(payload)/custom.scss`:
    
    ```scss
    @import '@sirv/payload-plugin/styles.css';
    ```
    

Start your app - a **Sirv** link now appears in the admin sidebar.

## Connect your Sirv account

1.  In the Payload admin, click **Sirv** in the sidebar (or visit `/admin/sirv`).
    
2.  Paste your **Client ID** and **Client Secret** from [app.sirv.com > Settings > API access](https://app.sirv.com/settings/api) and click **Connect**.
    
3.  Choose the delivery domain to serve assets from (if your account has more than one).
    
    ![Connect your Sirv account in the Payload admin settings view](https://sirv.sirv.com/website/screenshots/payload/01-connect-account.png?profile=screenshots-grey-border)
    

Once connected, the settings view shows your account and the chosen delivery domain, with a button to disconnect.

![The connected Sirv settings view in the Payload admin](https://sirv.sirv.com/website/screenshots/payload/02-settings-page.png?profile=screenshots-grey-border)

The credentials are stored in an admin-only `sirv-settings` global.

The secret is **encrypted at rest** (AES-256-GCM, keyed by your `PAYLOAD_SECRET`) and never returned to the browser or the REST/GraphQL API.

When editors browse the DAM, the plugin mints a short-lived 20-minute token on your server; the admin talks to Sirv directly with that token only.

## Add Sirv fields to a collection

The plugin exports three field factories. Each returns a standard Payload field config, so you can add them to any collection or global.

-   `sirvMediaField({ name })` - a single asset, stored as a JSON object.
-   `sirvMediaListField({ name })` - a gallery: multi-select with drag-to-reorder, stored as a JSON array.
-   `sirvAssetUrlField({ name })` - a plain delivery URL string to any Sirv asset, including generic files such as PDFs and ZIPs.

All three accept the same options:

-   `name` - the field’s stored key (required).
    
-   `label` - a display label (optional).
    
-   `required` - mark the field required (optional).
    
-   `allowedTypes` - restrict the picker to a subset of `image`, `video`, `spin` (360 spins), `view` (Sirv Media Viewer files) and `model` (glTF/GLB 3D models).
    
    The URL field additionally allows `file` for generic documents. Default: the five media types.
    

Example - a hero image, a video/image gallery, a spin-only field and a PDF link:

```tsx
fields: [
  sirvMediaField({ name: 'hero', allowedTypes: ['image'] }),
  sirvMediaListField({ name: 'gallery', allowedTypes: ['image', 'video'] }),
  sirvMediaField({ name: 'spin', allowedTypes: ['spin'] }),
  sirvAssetUrlField({ name: 'datasheet', allowedTypes: ['file'] }),
]
```

Each field type renders in the document editor with a thumbnail preview, alt/caption inputs and its own picker:

![The Sirv field types in a Payload document: single media, gallery and asset URL](https://sirv.sirv.com/website/screenshots/payload/03-sirv-supported-field-types.png?profile=screenshots-grey-border)

## Using the picker

Editing a document, each Sirv field shows a **Pick from Sirv** button that opens the media library:

-   **Browse** folders with the breadcrumb trail, or **search** your entire account by filename.
-   **Filter chips** narrow results to images, videos, 360 spins, viewer files or 3D models.
-   Click an asset to **preview** it - spins, viewer files and 3D models load live, videos play - then confirm. In a gallery field, keep picking to add several assets, then drag to reorder them.

![Browse Sirv folders and assets in the DAM browser grid inside the Payload admin](https://sirv.sirv.com/website/screenshots/payload/04-dam-browser-grid.png?profile=screenshots-grey-border)

Click an asset to open its details: a live preview, its dimensions and size, and links to open the original or manage it on Sirv.

![Asset details with a live preview in the Sirv DAM browser](https://sirv.sirv.com/website/screenshots/payload/05-dam-browser-item-details.png?profile=screenshots-grey-border)

For a gallery field, select several assets across folders and searches, then add them together and drag to reorder.

![Selecting multiple assets in the Sirv DAM browser](https://sirv.sirv.com/website/screenshots/payload/06-dam-browser-multiple-selection.png?profile=screenshots-grey-border)

When an image or video is picked, its **alt text** and **caption** are filled in automatically from the asset’s title and description in Sirv. Editors can adjust them right in the field.

A completed document with several Sirv fields filled in:

![A Payload document with Sirv media fields filled in](https://sirv.sirv.com/website/screenshots/payload/07-post-with-sirv-assets.png?profile=screenshots-grey-border)

## What gets stored

The field saves plain JSON in your document - no file duplication, the media stays on Sirv:

```json
{
  "_type": "sirvMedia",
  "mediaType": "image",
  "sirvPath": "/products/shoe.jpg",
  "sirvAlias": "yourcompany.sirv.com",
  "originalUrl": "https://yourcompany.sirv.com/products/shoe.jpg",
  "width": 2000,
  "height": 1890,
  "alt": "Red running shoe",
  "caption": "Side view"
}
```

The gallery field stores an array of these objects; the URL field stores a plain URL string.

This is the same flat shape used by the Sirv plugins for Sanity, Storyblok, Contentful and Strapi.

## Rendering on your frontend

Because Payload v3 runs inside Next.js - the native home of [@sirv/react](https://www.npmjs.com/package/@sirv/react) - rendering is trivial.

The `@sirv/react` components are Client Components, so render them from a `'use client'` component and pass the stored value across the boundary:

```tsx
'use client';
import { SirvMedia, fromSanityMedia as fromStoredMedia } from '@sirv/react';

// `post.hero` is the stored sirvMedia object from your Payload document.
<SirvMedia value={fromStoredMedia(post.hero)} />

// A gallery:
{post.gallery.map((item, i) => (
  <SirvMedia key={i} value={fromStoredMedia(item)} />
))}
```

`fromStoredMedia` reads the flat `sirvMedia` shape directly, so no conversion layer is needed.

The `@sirv/react` components build responsive, optimized Sirv URLs and load sirv.js automatically for spins, viewers and 3D models.

A complete Next.js + Payload example is in the `examples/payload` folder of the repository.

## Common questions

Does the plugin store my Sirv secret in the browser?

No. The Client Secret is stored in an admin-only global, encrypted at rest with a key derived from your PAYLOAD\_SECRET, and its read access is denied so it is never returned to the admin UI or the API. The browser only ever receives a short-lived 20-minute access token, minted server-side, which it uses to browse the Sirv DAM directly.

Which media types does the plugin support?

Images, videos, 360 spins, Sirv Media Viewer (.view) files and 3D models (.glb/.gltf), plus generic files such as PDFs and ZIPs when "file" is added to allowedTypes (typically in the URL field).

My Sirv fields or settings view do not appear in the admin.

Run "payload generate:importmap" and restart the app. Payload resolves custom admin components through a generated import map, which is not re-run automatically after a production build, so it must be regenerated after installing or upgrading the plugin.

Does it replace Payload's built-in upload storage?

No. This plugin is a DAM picker: your media stays on Sirv and the field stores a small JSON reference. It does not change where Payload's native uploads are stored. A Sirv storage adapter for native uploads is a separate, future package.
