# Generating AI images inside of Sanity CMS

> Looking to use replicate directly inside of Sanity CMS? Well we've got just the plugin for you. You can download it here: https://www.npmjs.com/package/sanity-plugin-image-gen

**Published:** 2025-03-04 | **Updated:** 2026-08-11 | **Categories:** Tutorials

Watch: https://www.youtube.com/watch?v=2v2Yge5-eLY

---

## Transcript

Hey folks, how's it going? We're back again. So, um, I just want to show you something very cool that we've built in-house and I'm fairly certain that a lot of people are going to get a lot of use out of this.

So if you notice, we have this new little thing inside of Sanity called Generate Image. Now, the reason why we built this is we kept going to Replicate, we kept taking the data from there, and we kept throwing it back into our blogs. And depending on how good you are at doing that, um, it can take anywhere between like 15 seconds to a minute, which is very, very, you know, frustrating over time, especially when you're trying to create something on the fly and you just don't want to lose that editorial flow.

So, um, this is a plugin that you can now add into Sanity and it runs using the Next.js API routes. Um, I'm going to show you that in a second. It's going to show you how to set it up. Um, and if you are interested in seeing a whole video about how to set this thing up, we're more than happy to do that as well. But first of all, let's get some cute kittens in here, right? Let's generate that. So I'm just typing in "cute kittens." I'm going to hit generate and there you go. Boom! That is from Replicate. They look a little bit unsettling. That's exactly what we want.

But um, we have this whole Advanced Options section and we can do a lot of clever stuff in here. Everything from changing, like, the aspect ratio to the image size, um, and to the number of kittens that you're going to get generated. So, um, and of course we can do things like negative prompts. So we could put "ugly kittens" in here as a negative prompt. But you'll see, nice, very, very cute, very nice.

Um, and you can essentially just click any of these. So if I like this one best, I can hit it. It's going to upload that data. It's going to tell me we've got low battery, which is always great. And there we go. We've got it. That's it working.

Um, so if you're interested in using this, it's actually available here, which is Sanity plugin image gen. Um, it's been published 13 days ago, but we've been kind of just tweaking around with it for the last second. Um, so feel free to run this. Tell me if you get against uh any snags or anything that's kind of difficult to work with.

Um, and again, this is all the configuration that's inside of here. How to actually get it running. It has things like type safety built in, so it should in theory just work and should make it a lot easier for you to get it working. Um, and again, this still needs the Replicate uh ID inside of here. So it needs an API key. Um, but ultimately, all of this should in theory just work and you can tweak it to exactly the way you want. If you want to use a specific image model, you can tweak that. If you want to use specific prompts that start at the beginning (I've seen people use things like with iPhone camera setting so it looks more realistic), all of that is possible with this tool.

So yeah, hope you like it. Tell me how you get on. Take care. Bye-bye.

## Frequently asked questions

### What is Replicate AI?

Replicate is a platform that lets you run open-source AI models, including image generation models, through a single API. In this plugin we point at Replicate to generate images on demand from a text prompt, instead of opening another tab and pasting the result back into the CMS.

### How do you generate AI images inside Sanity CMS?

Install the sanity-plugin-image-gen plugin, add your Replicate API key, and an editor can type a prompt directly inside Sanity and get an image back without leaving the studio. The plugin runs through Next.js API routes and uploads the chosen image straight into the document.

### What does sanity-plugin-image-gen do?

It adds a "Generate image" action inside Sanity Studio so editors can turn a prompt into an image without leaving the CMS. It supports advanced options like aspect ratio, image size, the number of variants generated, and negative prompts.

### Does Sanity have AI image generation built in?

Not natively. Sanity itself does not ship an image generator. The sanity-plugin-image-gen plugin from Roboto Studio bridges Sanity Studio to Replicate so you can generate images from prompts inside the editor. You bring your own Replicate API key.

### Can I use Replicate with Sanity CMS?

Yes. The plugin calls the Replicate API from a Next.js API route in your app, which means any image model Replicate hosts is available from inside Sanity Studio. You can swap the underlying model and tweak the default prompt prefix to suit your house style.

### Is Sanity CMS good for AI image workflows?

Sanity is well suited because its plugin model and custom input components make it easy to embed generators directly in the editing experience. With this plugin, the AI step is part of the editor's normal flow rather than a separate tool, which is what makes it useful for blogs and landing pages.