# Sirv for DatoCMS

![DatoCMS logo](https://sirv.sirv.com/website/datocms-logo.svg)

Add Sirv as a media source inside DatoCMS.

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/)

Connect your Sirv account, browse your Sirv DAM, and pick images, videos, [360 spins](/help/spin/getting-started/how-spin-files-are-created/), [Sirv Media Viewers](/help/sirv-media-viewer/) and [3D models](/help/sirv-media-viewer/media-types/3d-model/) without leaving the DatoCMS editor.

Your assets **stay on Sirv** and are delivered from Sirv’s global CDN, in the optimal image format (often WebP) at the perfect dimensions.

Typical file size is 40-70% smaller than the original, for faster pages, **happier users** and **higher conversions**.

Unlike copying files into DatoCMS’s Media Area, the Sirv plugin stores only a small JSON reference to each asset (its path, delivery domain and dimensions).

The file is never duplicated, so you keep Sirv’s dynamic imaging, responsive `srcset`, 360 spins and the Sirv Media Viewer on your live site.

The plugin is built on the DatoCMS Plugin SDK and installs into any project. It ships **zero credentials** - you connect with your own Sirv [REST API](/help/rest-api/sirv-rest-api/) keys, once.

## Installation

1.  In DatoCMS, go to **Configuration > Plugins**, click the **+** button, find [**Sirv** on the Marketplace](https://www.datocms.com/marketplace/plugins/i/datocms-plugin-sirv) and click **Install**.
2.  DatoCMS opens the plugin’s settings screen so you can connect your Sirv account (next section).
3.  That’s it - the plugin is ready to attach to your models’ fields.

## Connect your Sirv account

On the plugin settings screen, paste your Sirv account’s REST API **Client ID** and **Client secret**, then click **Connect**.

![Connect your Sirv account on the DatoCMS plugin settings screen by pasting your REST API Client ID and secret](https://sirv.sirv.com/website/screenshots/datocms/01-connect-sirv-account.png?profile=screenshots-grey-border)

If your account has more than one delivery domain, you’ll be asked to choose which one to serve assets from.

The connection is saved automatically and reused afterwards - you only connect once.

### Find your API credentials

In Sirv, go to [Settings > API access](https://app.sirv.com/settings/api). Copy the **Client ID** and **Client secret** shown there. Don’t have a Sirv account yet? [Create a free account](https://app.sirv.com/signup) first.

## Add a Sirv field to a model

Sirv assets live in dedicated fields on your models. To add one:

1.  Open **Schema > Models**, choose a model and click **Add new field**. Select **JSON** (for a single asset or a gallery), or **Single-line string** (to store just an asset URL).
    
    ![Choosing the JSON field type when adding a new field to a DatoCMS model](https://sirv.sirv.com/website/screenshots/datocms/02-add-new-field-type-selection.png?profile=screenshots-grey-border)
    
2.  Give the field a name, for example “Hero media”, then open the field’s **Presentation** tab.
    
3.  Under **Field editor**, choose **Sirv media** (single asset), **Sirv media list** (gallery) or **Sirv asset URL** (string fields), and optionally restrict the **Allowed asset types**.
    
    ![Selecting the Sirv media editor on the Presentation tab of a DatoCMS JSON field](https://sirv.sirv.com/website/screenshots/datocms/03-field-presentation-sirv-editor.png?profile=screenshots-grey-border)
    
4.  Save the field. The Sirv picker now appears whenever you edit a record of that model.
    

### Field extensions

-   **Sirv media** - one image, video, 360 spin, Sirv Media Viewer or 3D model. Attached to a **JSON** field.
-   **Sirv media list** - multiple assets, with multi-select and drag-to-reorder. Attached to a **JSON** field.
-   **Sirv asset URL** - any Sirv asset (including PDFs and other files) stored as a plain delivery URL. Attached to a **Single-line string** field.

Use **Allowed asset types** in the field’s plugin settings to limit the picker to specific kinds: `image`, `video`, `spin`, `view`, `model` (and `file` for the URL field).

Leave all unchecked to allow every media type.

## Pick assets from Sirv

Open a record that uses a Sirv field and click **Pick from Sirv**.

![The Pick from Sirv button on a Sirv field in the DatoCMS record editor](https://sirv.sirv.com/website/screenshots/datocms/04-edit-record-with-sirv-field.png?profile=screenshots-grey-border)

The Sirv media browser opens. Navigate your folders, search the whole account, and filter by type using the chips (**Image**, **Video**, **360 Spin**, **Sirv Media Viewer**, **3D Model**).

You can also create folders and upload files right from the browser.

![Browsing and filtering a Sirv account's folders and assets inside the DatoCMS media browser](https://sirv.sirv.com/website/screenshots/datocms/05-sirv-dam-browser.png?profile=screenshots-grey-border)

Click an asset to preview it - images, videos, 360 spins, viewers and 3D models all preview live - then click **Use this asset**.

![Previewing a selected Sirv image with its dimensions before confirming the choice](https://sirv.sirv.com/website/screenshots/datocms/06-sirv-media-details.png?profile=screenshots-grey-border)

The asset is added to the field. For images and videos, the **[Alt text](/help/image-management/add-alt-tags-images-automatically-ai/)** and **Caption** are auto-filled from the asset’s Sirv metadata, and you can fine-tune them inline.

![A Sirv image added to a DatoCMS field showing its path, alt text and caption controls](https://sirv.sirv.com/website/screenshots/datocms/07-edit-record-sirv-image-added.png?profile=screenshots-grey-border)

## Render on your website

The field stores a small JSON value (or a URL string for the Asset URL field).

Render it on your frontend with the free [@sirv/react](https://www.npmjs.com/package/@sirv/react) package, which delivers responsive images, videos, 360 spins and combined Sirv Media Viewer galleries.

```bash
npm install @sirv/react
```

DatoCMS returns JSON field values as strings in its GraphQL API - parse them, then pass the value straight to the Sirv components:

```jsx
import { SirvProvider, SirvMedia, SirvGallery, fromSanityMedia as fromSirvMedia } from '@sirv/react';

export function Product({ record }) {
  const hero = JSON.parse(record.heroMedia);      // Sirv media field
  const gallery = JSON.parse(record.gallery);     // Sirv media list field

  return (
    <SirvProvider alias="youraccount.sirv.com" quality={82}>
      {/* Single media field (image, video, 360 spin, viewer or 3D model) */}
      <SirvMedia value={fromSirvMedia(hero)} width={640} />

      {/* Gallery field, as one combined Sirv Media Viewer */}
      <SirvGallery
        items={gallery.map(fromSirvMedia)}
        layout="viewer"
        width={640}
        height={480}
      />
    </SirvProvider>
  );
}
```

For an Asset URL field, the value is already a delivery URL - use it directly in an `<img>`, `<a>` or your own component.

## Add Sirv media to modular content

To place Sirv media inside DatoCMS’s modular content or structured text, use a block:

1.  Create a block model, for example **Sirv Media Block**, with one **JSON** field whose Presentation editor is **Sirv media**.
2.  Add the block to your modular-content or structured-text field’s allowed blocks. Editors insert it like any other block and pick the asset with the usual Sirv browser.
3.  When rendering, map the block to a Sirv component exactly as in the example above.

## 360 spins, viewers and 3D models

Sirv is more than an image CDN. Pick a **360 spin**, a **Sirv Media Viewer** or a **3D model** (.glb) in the same browser, and store it on a Sirv field.

Render it with `<SirvMedia>` or `<SirvGallery layout="viewer">`. The viewer combines images, videos and spins into one interactive gallery with zoomable images, on desktop and mobile.

## Common questions

Do my images get copied into DatoCMS?

No. The Sirv field stores only a small JSON reference (the asset's path, delivery domain and dimensions). The file stays on Sirv and is served from the Sirv CDN, so you keep dynamic imaging, responsive srcset, 360 spins and the Sirv Media Viewer.

Which DatoCMS field types can use Sirv?

A JSON field (for a single asset or a gallery) and a Single-line string field (to store an asset URL). Open the field's Presentation tab and choose the Sirv media, Sirv media list or Sirv asset URL editor.

Does it support videos, 360 spins, viewers and 3D models?

Yes. The media browser lets you pick images, videos, 360 spins, Sirv Media Viewers and 3D models, with a live preview of each. They render on your website with the @sirv/react package.

Are my Sirv credentials safe?

You paste your own Sirv REST API Client ID and secret once, on the plugin settings screen. They are stored as the plugin's parameters in your DatoCMS project and used only to talk to Sirv. Project collaborators who can use the plugin can read them, so use a dedicated key - you can revoke it any time at app.sirv.com. The plugin bundles no credentials of its own.

Can I import Sirv images into DatoCMS's Media Area?

The recommended model keeps assets on Sirv - DatoCMS uploads are file copies, which would lose dynamic imaging and 360 spins. Use the Sirv fields instead of the native Media Area for Sirv-hosted assets.
