# Sirv for Contentful

![Contentful logo](https://sirv.sirv.com/website/contentful-logo.png?w=230)

Add Sirv as a media source inside Contentful.

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/) and [Sirv Media Viewers](/help/sirv-media-viewer/) without leaving the Contentful 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 Contentful’s media library, the Sirv app 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 app is built on the Contentful App Framework and installs into any space. It ships **zero credentials** - you connect with your own Sirv [REST API](/help/rest-api/sirv-rest-api/) keys, once.

## Installation

1.  In Contentful, open your space and go to **Apps > Custom apps** (or the Marketplace), find **Sirv** and click **Install**.
2.  Contentful opens the app’s configuration screen so you can connect your Sirv account (next section).
3.  After connecting, click **Install to selected environments** (top right) to finish. That’s it - the app is ready to add to your content types.

## Connect your Sirv account

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

![Connect your Sirv account on the Contentful app configuration screen by pasting your REST API Client ID and secret](https://sirv.sirv.com/website/screenshots/contentful/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.

Then click **Save** (or **Install to selected environments** on first install) at the top right of Contentful to store the connection.

Your credentials are saved as the app’s installation parameters and reused automatically 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 content type

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

1.  Open **Content model**, choose a content type and click **Add field**. Select **JSON object** (for a single asset or a gallery), or **Short text** (to store just an asset URL).
    
    ![Choosing the JSON object field type in Contentful's Add new field dialog](https://sirv.sirv.com/website/screenshots/contentful/02-add-new-field-type-selection.png?profile=screenshots-grey-border)
    
2.  Give the field a name, for example “Sirv Single Media”, and click **Add and configure**.
    
    ![Naming a new JSON object field Sirv Single Media in Contentful](https://sirv.sirv.com/website/screenshots/contentful/03-add-new-field.png?profile=screenshots-grey-border)
    
3.  On the **Appearance** tab, select **Sirv** as the field editor. Then set **Field type** to the kind of content this field holds, and optionally restrict the **Allowed asset types** and the gallery **render mode**.
    
    ![Selecting Sirv as the field appearance and choosing Single media as the field type in Contentful](https://sirv.sirv.com/website/screenshots/contentful/04-add-new-field-configure.png?profile=screenshots-grey-border)
    
4.  Save the field and the content type. The Sirv picker now appears whenever you edit an entry of that type.
    

### Field types

Choose a **Field type** in the appearance settings to control what a field stores:

-   **Single media** - one image, video, 360 spin or Sirv Media Viewer. Stored on a **JSON object** field.
-   **Gallery** - multiple assets, with multi-select and drag-to-reorder. Stored on a **JSON object** field.
-   **Asset URL** - any Sirv asset stored as a plain delivery URL string. Stored on a **Short text** field.

Use **Allowed asset types** to limit the picker to specific kinds, with a comma-separated list of `image`, `video`, `spin`, `view` and `file`. Leave it blank to allow all media types.

## Pick assets from Sirv

Open an entry that uses a Sirv field and click **Add asset from Sirv**.

![The Add asset from Sirv button on a Sirv field in the Contentful entry editor](https://sirv.sirv.com/website/screenshots/contentful/05-edit-content-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**).

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

Click an asset to preview it - images, videos, 360 spins and Sirv Media Viewers 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/contentful/07-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 (and image quality) inline.

![A Sirv image added to a Contentful field showing its path, alt text, caption and quality controls](https://sirv.sirv.com/website/screenshots/contentful/08-edit-content-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
```

Pass the stored field value straight to the Sirv components:

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

export function Product({ entry }) {
  return (
    <SirvProvider alias="youraccount.sirv.com" quality={82}>
      {/* Single media field (image, video, 360 spin or viewer) */}
      <SirvMedia value={fromSirvMedia(entry.fields.sirvSingleMedia)} width={640} />

      {/* Gallery field, as one combined Sirv Media Viewer */}
      <SirvGallery
        items={entry.fields.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 a Rich Text field

Contentful’s Rich Text editor uses its own **\+ Embed** menu, which apps cannot add a custom source to. To place Sirv media inside rich text, use Contentful’s built-in **embedded entry** feature:

1.  Create a small content type, for example **Sirv Media**, with one **JSON object** field set to Appearance > **Sirv**, Field type **Single media**.
    
2.  In your Rich Text field, click **\+ Embed > Entry** (or **Inline entry**) and insert a _Sirv Media_ entry, picking the asset with the usual Sirv browser.
    
    You can restrict the Rich Text field’s validations to only allow embedding the _Sirv Media_ type for a clean, Sirv-only embed.
    
3.  When you render the rich text on your website, map the embedded-entry node to a Sirv component:
    
    ```jsx
    import { documentToReactComponents } from '@contentful/rich-text-react-renderer';
    import { BLOCKS } from '@contentful/rich-text-types';
    import { SirvMedia, fromSanityMedia as fromSirvMedia } from '@sirv/react';
    
    
    const options = {
      renderNode: {
        [BLOCKS.EMBEDDED_ENTRY]: (node) => {
          const entry = node.data.target;            // the resolved "Sirv Media" entry
          return entry?.fields?.media?.mediaType
            ? <SirvMedia value={fromSirvMedia(entry.fields.media)} width={640} />
            : null;
        },
      },
    };
    
    
    documentToReactComponents(richTextDocument, options);
    ```
    

Make sure your Delivery API query resolves the linked entries so the embedded entry’s fields are populated.

## 360 spins and the Sirv Media Viewer

Sirv is more than an image CDN. Pick a **360 spin** or a **Sirv Media Viewer** in the same browser, store it on a Sirv field, and 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 Contentful?

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 Contentful field types can use Sirv?

A JSON object field (for a single asset or a gallery) and a Short text field (to store an asset URL). Set the field's Appearance to Sirv, then choose the Field type: Single media, Gallery, or Asset URL.

Does it support videos, 360 spins and the Sirv Media Viewer?

Yes. The media browser lets you pick images, videos, 360 spins and Sirv Media Viewers, 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 app's configuration screen. They are stored as the app's installation parameters and used only to talk to Sirv. The app bundles no credentials of its own.

Can I add Sirv to Contentful's native media field?

No. Contentful does not allow apps to add a source to its native Media reference field, and that field can only store links to Contentful assets. To keep assets on Sirv, use a JSON object field (Single media or Gallery) or a Short text field (Asset URL) instead.

Can I add Sirv media to a Rich Text field?

Yes, using Contentful's built-in embedded entries. Create a small content type with a Sirv field, then use + Embed > Entry in the Rich Text editor to insert it. Apps cannot add a custom item to the + Embed menu itself, so this embedded-entry approach is the supported way.
