# Revolutionising visual content creation with Sanity.io and OpenAI

> How to add AI image generation to Sanity Studio using OpenAI's API, from the original DALL-E plugin to the newer options available today.

**Published:** 2023-01-31 | **Updated:** 2026-07-23 | **Categories:** AI, Sanity
---

We originally wrote this in January 2023, when DALL-E 2 was the only game in town and sticking it inside Sanity Studio felt like a neat trick. The landscape has shifted quite a bit since then, so we've updated this with what actually matters now.

The core idea hasn't changed: let editors generate images without leaving the CMS. The tools have.

## The original approach: sanity-plugin-asset-source-openai

We built [sanity-plugin-asset-source-openai](https://www.npmjs.com/package/sanity-plugin-asset-source-openai) as a quick way to wire DALL-E into Sanity Studio. It adds an "OpenAI" option to any image field, lets you type a prompt, and uploads the result as a Sanity asset.

### Installation

```bash
pnpm add sanity-plugin-asset-source-openai
```

### Config

```javascript
import { defineConfig } from 'sanity'
import { openaiImageAsset } from 'sanity-plugin-asset-source-openai'

export default defineConfig({
  // ...
  plugins: [
    openaiImageAsset({
      API_KEY: process.env.SANITY_STUDIO_OPENAI_API_KEY,
    }),
  ],
})
```

> Store your API key in an environment variable prefixed with `SANITY_STUDIO_`. Add it to `.env.local` and keep that file in `.gitignore`.

### Schema

Any standard image field works. Nothing special needed:

```javascript
export default {
  name: 'post',
  type: 'document',
  title: 'Post',
  fields: [
    {
      name: 'title',
      type: 'string',
      title: 'Title',
    },
    {
      name: 'image',
      type: 'image',
      title: 'Image',
    },
  ],
}
```

### Using it

Click the image field, select "Open AI Image" from the asset source dropdown:

![ai-plugin](https://qxvqs298ldvynvwd.public.blob.vercel-storage.com/revolutionizing-visual-content-creation-with-sanityio-and-openai-blog-ai-plugin.png)

Type your prompt and hit Generate:

![prompt-dialog](https://qxvqs298ldvynvwd.public.blob.vercel-storage.com/revolutionizing-visual-content-creation-with-sanityio-and-openai-blog-prompt-dialog.png)

If you like the result, click Confirm to save it as a Sanity asset. If not, generate again until you get something usable.

![ai-image](https://qxvqs298ldvynvwd.public.blob.vercel-storage.com/revolutionizing-visual-content-creation-with-sanityio-and-openai-blog-ai-image.png)

Here's a demo of the full flow:

[https://www.loom.com/share/267fed477cf4458394eb2c2e4c964efc](https://www.loom.com/share/267fed477cf4458394eb2c2e4c964efc)

## What's changed since 2023

Quite a lot, actually.

### DALL-E 2 and 3 are being retired

OpenAI is shutting down both DALL-E 2 and DALL-E 3 on **May 12, 2026**. The replacements are `gpt-image-1` (released April 2025) and `gpt-image-1.5` (December 2025), which are built on the GPT-4o architecture. They're better at following instructions, rendering text in images, and producing photorealistic output. Pricing moved to a per-token model, starting around $0.02 per image at low quality.

If you're using the plugin above, it will need updating before the deprecation deadline.

### Sanity has native AI image generation now

This is the bigger story. Since Sanity 3.26, the official [@sanity/assist](https://www.sanity.io/docs/studio/install-and-configure-sanity-ai-assist) plugin includes built-in image generation. You configure `options.aiAssist.imageInstructionField` on an image field and your editors get prompt-based generation without any third-party plugin.

[Agent Actions](https://www.sanity.io/docs/agent-actions/agent-actions-image-generation) takes it further, generating images as part of whole-document creation. If you're on Sanity's Growth plan or above, this is probably where you should start now rather than wiring up your own OpenAI key.

### Other plugins worth knowing about

- **[sanity-plugin-gemini-ai-images](https://github.com/ncklrs/sanity-ai-image-video)** uses Google's Gemini 2.5 Flash for text-to-image and image-to-image editing, including background swaps and lighting changes.
- **[sanity-plugin-image-gen](https://www.sanity.io/plugins/sanity-plugin-image-gen)** (also ours) routes through Next.js API routes and Replicate, which gives you access to models like Flux and Stable Diffusion.

## Which approach should you use?

If you're starting fresh today, use **Sanity AI Assist**. It's first-party, maintained, and doesn't require managing your own API keys.

If you need a specific model (say you prefer Flux's aesthetic over what Sanity's built-in option produces), one of the third-party plugins gives you that control.

The `sanity-plugin-asset-source-openai` approach from this original post still works, but you'll want to make sure it's updated for `gpt-image-1` before May 2026. We're evaluating whether to update it or deprecate it in favour of our Replicate-based plugin, which is more model-agnostic.

The point remains the same as when we first wrote this: editors shouldn't have to leave their CMS to get an image. How you wire that up is just an implementation detail.

If you're interested in AI inside Sanity more broadly, [Sanity Canvas](/blog/sanity-canvas-a-better-way-of-writing-content) covers AI-assisted writing directly inside the CMS, not just images.

> **Sanity CMS development**: We configure AI image plugins, schema design, and editorial tooling for Sanity teams. [Learn more](/services/sanity)