Everything *[NYC] 2026: see what we announced. →
Skip to content

GenMagic: AI image generator

Adds 'Generate with GenMagic' to every image field's Select menu. Pick one of 60+ AI image models (Nano Banana, GPT Image, FLUX, Seedream and more), see its price, write a prompt, and use the result as a normal Sanity asset. Optional video clips for file fields. Uses your own GenMagic key; a free key with starter credit takes a minute.

Install command

npm install sanity-plugin-genmagic

sanity-plugin-genmagic

Generate images with more than 60 AI models from inside Sanity Studio, at the moment an editor needs one.

The plugin adds Generate with GenMagic to the Select menu of every image field. It opens a dialog where the editor picks a model, writes a prompt, chooses a size, and sees the picture and what it cost before using it. Use this image puts it in your dataset as a normal image asset.

  • Choose the model. FLUX, Nano Banana, GPT Image, Seedream, Recraft, Qwen and more, all through one GenMagic key. The list is read live from GenMagic, so new models appear without a plugin update.
  • See the price first. Every model shows its estimated price per image next to its name. After a generation the dialog shows the exact cost and the balance left.
  • Pay as you go. One prepaid balance for every model. No subscription, no per-model account.
  • Optional video. Add a clip generator to file fields (see Video clips).

Install

npm install sanity-plugin-genmagic

Add it to sanity.config.ts:

import {defineConfig} from 'sanity'
import {genmagicAssetSource} from 'sanity-plugin-genmagic'

export default defineConfig({
  // ...
  plugins: [genmagicAssetSource()],
})

Open any document with an image field, open the field's Select menu, and choose Generate with GenMagic.

Requires Sanity Studio v5 or v6 (React 19.2 or newer).

The API key

Generating needs a GenMagic API key. A free key is at genmagic.co/get-api-key. Browsing the model list needs no key.

There are two ways to provide it.

Each editor pastes their own (the default). The dialog shows a key field. Once a generation works, the key is kept in that browser's localStorage and is never sent anywhere except genmagic.co. Forget key removes it.

You set one key for the whole Studio:

plugins: [genmagicAssetSource({apiKey: process.env.SANITY_STUDIO_GENMAGIC_KEY})]

When a key is set this way the dialog shows no key field.

A key in your Studio configuration is part of the JavaScript your Studio serves, so anyone who can load the Studio can read it. GenMagic bills a prepaid balance, which caps what a key can spend. Use a key from an account that holds only what you are happy to spend, and combine it with allowedModels to keep to prices you accept. If that does not suit you, leave apiKey unset and let each editor use their own.

Options

All optional.

OptionTypeWhat it does
apiKeystringOne GenMagic key for every editor, so nobody pastes one. See the note above.
defaultModelstringModel id preselected the first time an editor opens the dialog. After that their last choice is remembered. Without it, the first model in GenMagic's list (newest first) is used.
allowedModelsstring[]Limit the picker to these model ids. Handy with a shared apiKey.
videobooleanAlso add Generate video with GenMagic to every file field. Default false.

Model ids are listed at https://genmagic.co/api/v1/models?category=image.

genmagicAssetSource({
  apiKey: process.env.SANITY_STUDIO_GENMAGIC_KEY,
  allowedModels: ['black-forest-labs/flux-3-image-klein', 'bytedance-seed/seedream-5-0-flash'],
})

One field only

To offer the generator on a single field instead of all of them, leave the plugin out and use the source directly:

import {defineField} from 'sanity'
import {createGenmagicImageSource} from 'sanity-plugin-genmagic'

defineField({
  name: 'cover',
  title: 'Cover image',
  type: 'image',
  options: {sources: [createGenmagicImageSource({defaultModel: 'openai/gpt-image-2'})]},
})

options.sources sets the complete list of sources for that field, so Sanity's own Browse option is not shown unless you list it too. See Sanity's documentation on asset sources.

What the editor sees

  1. Model. Each option reads like Black Forest Labs: FLUX 3 Image ($0.072), the estimated price of one image. If the list cannot be loaded, the dialog offers a retry and still generates with GenMagic's own default model.
  2. Size. Square 1024x1024, landscape 1792x1024 or portrait 1024x1792.
  3. Prompt. Press Ctrl+Enter (Cmd+Enter on Mac) to generate.
  4. Generate. The button shows the estimated price. When it finishes, the picture appears with the cost of that generation and the balance left.
  5. Use this image. The file is downloaded and uploaded to your dataset like any other upload, so it does not depend on genmagic.co afterwards. Generate again as often as you like before choosing.

Errors are shown exactly as GenMagic words them. A low balance, for example, explains how to top up.

What is stored on the asset

Each image asset records where it came from, so it can be found and labelled later:

  • description: the prompt
  • creditLine: Generated with GenMagic (<model name>)
  • source: {name: 'genmagic', id: <file address>, url: <file address>}

Video clips

A file field can offer Generate video with GenMagic, which makes a short clip from a prompt and stores it as a file. It is off by default, because file fields are often for PDFs.

For one field:

import {createGenmagicVideoSource} from 'sanity-plugin-genmagic'

defineField({
  name: 'heroClip',
  type: 'file',
  options: {accept: 'video/*', sources: [createGenmagicVideoSource()]},
})

For every file field, use genmagicAssetSource({video: true}).

Only text-to-video models are listed, with the aspect ratios 16:9, 9:16 and 1:1. A clip takes a few minutes to render. Nothing is charged until it finishes. Closing the dialog while it renders stops the waiting, but the clip may still finish and be billed.

In Sanity's types, the form.file.assetSources setting that this relies on is marked beta.

Troubleshooting

  • "Add your GenMagic API key": paste a key into the dialog, or set apiKey.
  • "Invalid API key": the key is wrong or revoked. Use Forget key and paste a new one.
  • A low balance message: GenMagic's message says how to top up.
  • "Could not download the image from GenMagic": the browser could not read the generated file. If your Studio sets a Content Security Policy, allow https://genmagic.co in connect-src and img-src (and media-src for clips).
  • "This field accepts ...": the field's accept option does not allow the file type the model produced. Pick another model or relax accept.

Notes

  • Each call identifies this package to GenMagic with an X-GenMagic-Client: sanity-plugin/<version> header.
  • Prompts go to GenMagic and the model providers it routes to. Do not put confidential text in a prompt that you would not send to an AI service.
  • Images are produced by AI. The creditLine on each asset makes that visible in your own content tools.

License

MIT © GenMagic. genmagic.co/developers