ashbuilds

payload ai

by ashbuilds
AI content generation
v3
^3.90.2
NOASSERTION

Overview

Summary generated from the README

Adds AI-assisted content generation to the Payload admin, covering text, rich text, images and voice. It is enabled per collection or global through the plugin config, and a Lexical editor feature adds compose, proofread, translate and rephrase actions. Provider API keys come from environment variables or plugin config, and it requires Payload 3.90.2 or later.

Features

  • Compose, proofread, translate and rephrase actions inside Lexical rich-text fields
  • Image generation with OpenAI DALL-E and GPT-Image-1 on upload fields
  • Voice generation with ElevenLabs and OpenAI text-to-speech
  • Field-level prompts with a prompt editor and seeded default prompts
  • Supports OpenAI, Anthropic, Google and MiniMax providers, plus custom models
  • Access control for generation and settings, with a custom media upload callback for multi-tenant setups

Use cases

  • Draft and rewrite blog post content directly from the Payload editor
  • Generate images or voice-overs and store them in a media collection
  • Translate rich-text content between enabled languages in a multilingual site

From the author

TypeScript AI plugin for Payload CMS: text, image and voice generation with extensible providers, field-level prompts, access control and rich-text integration.

Installation

npm i @ai-stack/payloadcms

568

Stars

66

Forks

2

Open Issues

1 weeks ago

Last Updated

3.5k

Weekly Downloads

v4.2.1

npm Version

816.0 KB

Unpacked Size

25

Dependencies

GitHub stars

568+24 since Sep 6

Show data
GitHub stars by day (UTC)
DateStars
Dec 5, 2026568
Dec 4, 2026568
Dec 3, 2026568
Dec 2, 2026567
Dec 1, 2026566
Nov 30, 2026566
Nov 29, 2026566
Nov 28, 2026566
Nov 27, 2026566
Nov 26, 2026565
Nov 25, 2026565
Nov 24, 2026565
Nov 23, 2026564
Nov 22, 2026564
Nov 21, 2026564
Nov 20, 2026564
Nov 19, 2026565
Nov 18, 2026565
Nov 17, 2026564
Nov 16, 2026564
Nov 15, 2026564
Nov 14, 2026564
Nov 13, 2026564
Nov 12, 2026564
Nov 11, 2026564
Nov 10, 2026564
Nov 9, 2026562
Nov 8, 2026562
Nov 7, 2026561
Nov 6, 2026561
Nov 5, 2026560
Nov 4, 2026560
Nov 3, 2026560
Nov 2, 2026560
Nov 1, 2026559
Oct 31, 2026559
Oct 30, 2026559
Oct 29, 2026559
Oct 28, 2026558
Oct 27, 2026558
Oct 26, 2026558
Oct 25, 2026558
Oct 24, 2026558
Oct 23, 2026558
Oct 22, 2026558
Oct 21, 2026558
Oct 20, 2026558
Oct 19, 2026558
Oct 18, 2026558
Oct 17, 2026558
Oct 16, 2026558
Oct 15, 2026558
Oct 14, 2026558
Oct 13, 2026558
Oct 12, 2026558
Oct 11, 2026557
Oct 10, 2026557
Oct 9, 2026557
Oct 8, 2026557
Oct 7, 2026557
Oct 6, 2026557
Oct 5, 2026555
Oct 4, 2026555
Oct 3, 2026554
Oct 2, 2026554
Oct 1, 2026554
Sep 30, 2026554
Sep 29, 2026553
Sep 28, 2026553
Sep 27, 2026552
Sep 26, 2026552
Sep 25, 2026552
Sep 24, 2026551
Sep 23, 2026550
Sep 22, 2026549
Sep 21, 2026548
Sep 20, 2026548
Sep 19, 2026547
Sep 18, 2026547
Sep 17, 2026547
Sep 16, 2026547
Sep 15, 2026546
Sep 14, 2026546
Sep 13, 2026546
Sep 12, 2026546
Sep 11, 2026546
Sep 10, 2026545
Sep 9, 2026545
Sep 8, 2026545
Sep 7, 2026545
Sep 6, 2026544
npm weekly downloads

3.2K−2.7K since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 20263,196
Dec 4, 20263,134
Dec 3, 20263,291
Dec 2, 20263,467
Dec 1, 20263,476
Nov 30, 20263,592
Nov 29, 20263,592
Nov 28, 20263,612
Nov 27, 20263,705
Nov 26, 20263,741
Nov 25, 20263,656
Nov 24, 20263,650
Nov 23, 20263,548
Nov 22, 20263,383
Nov 21, 20263,262
Nov 20, 20263,261
Nov 19, 20263,100
Nov 18, 20262,958
Nov 17, 20262,807
Nov 16, 20263,348
Nov 15, 20263,312
Nov 14, 20263,612
Nov 13, 20263,725
Nov 12, 20263,625
Nov 11, 20263,604
Nov 10, 20263,749
Nov 9, 20263,237
Nov 8, 20263,508
Nov 7, 20263,449
Nov 6, 20263,361
Nov 5, 20263,233
Nov 4, 20263,361
Nov 3, 20263,428
Nov 2, 20263,533
Nov 1, 20263,266
Oct 31, 20263,203
Oct 30, 20263,016
Oct 29, 20262,615
Oct 28, 20262,083
Oct 27, 20262,130
Oct 26, 20262,061
Oct 25, 20262,251
Oct 24, 20262,114
Oct 23, 20261,635
Oct 22, 20262,372
Oct 21, 20262,914
Oct 20, 20262,852
Oct 19, 20262,871
Oct 18, 20262,949
Oct 17, 20263,002
Oct 16, 20263,390
Oct 15, 20263,089
Oct 14, 20262,922
Oct 13, 20262,745
Oct 12, 20262,714
Oct 11, 20262,385
Oct 10, 20262,308
Oct 9, 20262,481
Oct 8, 20262,548
Oct 7, 20262,772
Oct 6, 20263,110
Oct 5, 20263,072
Oct 4, 20263,318
Oct 3, 20263,354
Oct 2, 20263,321
Oct 1, 20263,214
Sep 30, 20262,945
Sep 29, 20262,573
Sep 28, 20262,588
Sep 27, 20262,543
Sep 26, 20263,328
Sep 25, 20264,097
Sep 24, 20265,159
Sep 23, 20265,463
Sep 22, 20265,639
Sep 21, 20265,865
Sep 20, 202611,596
Sep 19, 202613,885
Sep 18, 202613,592
Sep 17, 202613,259
Sep 16, 202613,518
Sep 15, 202614,804
Sep 14, 202615,110
Sep 13, 20269,547
Sep 12, 20266,929
Sep 11, 20266,959
Sep 10, 20266,565
Sep 9, 20266,256
Sep 8, 20265,104
Sep 7, 20265,280
Sep 6, 20265,913

Each point is npm's rolling 7-day download count.

Health Score

83/100Excellent

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/829724738-root.svg)](https://payloaddirectory.dev/plugins/829724738-root)
HTML
<a href="https://payloaddirectory.dev/plugins/829724738-root"><img src="https://payloaddirectory.dev/badge/829724738-root.svg" alt="Payload Directory"></a>
Updated Nov 27, 2026Created Jul 17, 2024Published Nov 27, 2026

README

Payload AI Plugin

Upgrading to 4.0.0? Read the migration guide. Reference images and extracted prompt attachments now require an explicit storage resolver.

Payload AI Plugin

Transform content creation with intelligent automation — your models, your way

Supported AI Providers


🚀 What is this?

Payload AI adds AI-assisted content workflows to Payload CMS. Generate and edit text, create images and synthesize voice from the CMS, with configurable providers, field-level prompts and access control.

Engineering overview

  • CMS integration: AI controls sit alongside content fields and the rich-text editor.
  • Extensibility: provider and model configuration lets projects adapt generation to their requirements.
  • Permissions: generation and document/media access follow explicitly configured access rules; see the advanced configuration below.
  • Contributor workflow: the repository includes a development app, Vitest integration tests and Playwright end-to-end tests.

🎥 See It in Action


⚠️ Beta Notice

This plugin is actively evolving. We're constantly shipping improvements and new features. Tested with Payload v3.88.0.

Quick Start Tip: Try it out with Payload's website template for the smoothest experience.


✨ Features

📝 Text & RichText Fields

Content Generation Magic:

  • ✅ Compose - Generate content from scratch
  • ✅ Proofread - Polish your prose (Beta)
  • ✅ Translate - Break language barriers
  • ✅ Rephrase - Find better ways to say it (Beta)
  • 🔜 Expand - Elaborate on ideas
  • 🔜 Summarize - Distill the essence
  • 🔜 Simplify - Make complex things clear

🎨 Upload Fields

  • 🎙️ Voice Generation - Powered by ElevenLabs & OpenAI
  • 🖼️ Image Generation - Powered by OpenAI (DALL-E & GPT-Image-1)

🔧 Power User Features

  • 🔌 Bring Your Own Model - Not limited to our defaults
  • 🎛️ Field-Level Prompts - Customize AI behavior per field
  • 🔐 Access Control - Lock down who can use AI features
  • 🧠 Prompt Editor - Fine-tune AI instructions
  • 🌍 i18n Support - Works with your multilingual setup
  • 🎨 Custom Components - Extend with your own UI

🔜 Coming Soon

  • 📊 Document Analyzer
  • ✅ Fact Checking
  • 🔄 Automated Workflows
  • 💡 Editor Suggestions
  • 💬 AI Chat Assistant

📦 Installation

pnpm add @ai-stack/payloadcms

That's it! Now let's configure it.


🛠️ Quick Setup

Step 1: Configure the Plugin

Add to src/payload.config.ts:

import { payloadAiPlugin } from '@ai-stack/payloadcms'

export default buildConfig({
  plugins: [
    payloadAiPlugin({
      collections: {
        [Posts.slug]: true,
      },
      debugging: false,
    }),
  ],
  // ... rest of your config
})

Step 2: Enable AI in Your Fields

Add to your RichText fields (e.g., src/collections/Posts/index.ts):

import { PayloadAiPluginLexicalEditorFeature } from '@ai-stack/payloadcms'

fields: [
  {
    name: 'content',
    type: 'richText',
    editor: lexicalEditor({
      features: ({ rootFeatures }) => {
        return [
          HeadingFeature({ enabledHeadingSizes: ['h1', 'h2', 'h3', 'h4'] }),
          // Add this line:
          PayloadAiPluginLexicalEditorFeature(),
        ]
      },
    }),
  },
]

Step 3: Add Your API Keys

Payload AI can read provider credentials in two ways:

  1. Environment variables.
  2. Plugin config, useful when credentials are resolved before Payload starts, such as per-instance multi-tenant setups, external secret managers, or tests.
Option A: Environment Variables

Create a .env file in your project root. Add the keys for the providers you want to use:

# Text Generation - Choose your provider(s)
OPENAI_API_KEY=your-openai-api-key           # OpenAI models (GPT-4, etc.)
ANTHROPIC_API_KEY=your-anthropic-api-key     # Claude models
GOOGLE_GENERATIVE_AI_API_KEY=your-google-key # Gemini models
MINIMAX_API_KEY=your-minimax-api-key         # MiniMax M3 / M2.7 models

# Image Generation - Choose your provider(s)
OPENAI_API_KEY=your-openai-api-key           # DALL-E (uses same key as above)
# OPENAI_ORG_ID=your-org-id                  # Required only for GPT-Image-1 model
GOOGLE_GENERATIVE_AI_API_KEY=your-google-key # Imagen (uses same key as above)

# Audio/Voice Generation - Choose your provider(s)
ELEVENLABS_API_KEY=your-elevenlabs-api-key   # ElevenLabs voices
OPENAI_API_KEY=your-openai-api-key           # OpenAI TTS (uses same key as above)

# Optional: Use custom OpenAI-compatible endpoint
# OPENAI_BASE_URL=https://api.openai.com/v1

You only need the keys for the providers you plan to use. Mix and match based on your preferences!

Option B: Plugin Config

If you prefer to resolve secrets yourself at startup, pass them through providers. Config values take priority over environment variables, and omitted values still fall back to .env.

payloadAiPlugin({
  collections: {
    [Posts.slug]: true,
  },
  providers: {
    openai: {
      apiKey: process.env.PAYLOAD_AI_OPENAI_API_KEY,
      baseURL: process.env.PAYLOAD_AI_OPENAI_BASE_URL,
      orgId: process.env.PAYLOAD_AI_OPENAI_ORG_ID,
    },
  },
})

Supported provider keys: openai, anthropic, google, elevenLabs, and minimax.

Important: Restart your server after updating .env or plugin settings!

You may also need to regenerate the import map:

payload generate:importmap

⚙️ Advanced Configuration

🔐 Access Control & Multi-Tenant Setup

Generation requires authentication and permission from access.generate. Source documents, instructions, and built-in media creation also enforce the caller's collection, field, and per-document permissions. Configure overrideInstructions.access to restrict who can read or edit instructions; access.settings controls the settings UI and does not replace these collection rules. Custom mediaUpload callbacks must enforce their own access checks, as shown below. Trusted initialization and instruction seeding run separately from user requests.

Reference images and storage

Reference images now require a server-side resolveReferenceImage callback. This is a breaking change for image editing with sample images or image URLs in prompts, and for text generation with extractAttachments enabled. Text-to-image generation without references is unchanged. The plugin does not fetch reference URLs, forward login credentials, or require Node DNS/HTTP APIs for reference resolution.

For selected sample images, the plugin reloads the media document from uploadCollectionSlug (default: media) with the caller's Payload read permissions and depth: 0 before invoking the resolver. Use that document's ID to retrieve bytes from a fixed storage bucket or other application-controlled store. Do not use a document's URL or filename as an unchecked network destination or filesystem path. Fields hidden by access control will not be available to the resolver.

The resolver receives { source, request, signal, maxBytes } and must return a PNG, JPEG, or WebP Blob. source.kind is media (with collection and the authorized document) or url (with an untrusted URL extracted from a prompt). Reject URL sources unless your application can map them to an explicitly approved storage object and authorize access. Merely checking that a URL uses HTTPS is insufficient. Prefer storage SDKs with a fixed bucket/account over arbitrary URL fetching; do not forward request cookies or tokens.

For example, connect your application's storage reader:

resolveReferenceImage: async ({ source, signal, maxBytes }) => {
  if (source.kind !== 'media') {
    throw new Error('Only selected media can be used as reference images.')
  }
  // Application-owned helper: map this authorized ID to your fixed bucket/object key.
  // Enforce maxBytes during loading and honor signal to cancel outstanding work.
  return readReferenceBlobFromStorage({
    collection: source.collection,
    id: source.document.id,
    signal,
    maxBytes,
  })
},

readReferenceBlobFromStorage above is an application helper, not a Payload or plugin API. Its implementation depends on your storage adapter. The plugin validates the returned Blob, rejects empty files or files over 20 MiB, and stops waiting after 30 seconds. The resolver must enforce the limit while loading to avoid buffering oversized objects; cancellation is cooperative and requires honoring signal. MIME checks do not verify image file contents. Built-in text models resolve extracted attachments through the same callback and pass bytes to the AI SDK. Automatic SDK attachment downloads are disabled. URLs remain ordinary text when attachment extraction is disabled. Custom generation models remain responsible for any network requests they make themselves.

import { payloadAiPlugin } from '@ai-stack/payloadcms'

export default buildConfig({
  plugins: [
    payloadAiPlugin({
      collections: {
        [Posts.slug]: true,
      },

      // Enable AI for globals too
      globals: {
        [Home.slug]: true,
      },

      // Development helpers
      debugging: false,
      disableSponsorMessage: false,
      generatePromptOnInit: process.env.NODE_ENV !== 'production',

      // Specify media collection for GPT-Image-1
      uploadCollectionSlug: 'media',

      // Lock down AI features
      access: {
        generate: ({ req }) => req.user?.role === 'admin',
        settings: ({ req }) => req.user?.role === 'admin',
      },

      // Customize language options
      options: {
        enabledLanguages: ['en-US', 'zh-SG', 'zh-CN', 'en'],
      },

      // Reference additional fields in prompts
      promptFields: [
        {
          name: 'url',
          collections: ['images'],
        },
        {
          name: 'markdown',
          async getter(doc, { collection }) {
            return docToMarkdown(collection, doc)
          },
        },
      ],

      // Control initial prompt generation
      seedPrompts: ({ path }) => {
        if (path.endsWith('.meta.description')) {
          return {
            data: {
              prompt: 'Generate SEO-friendly meta description: {{markdown}}',
            },
          }
        }
        if (path.endsWith('.slug')) return false // Disable for slugs
        return undefined // Use defaults
      },

      // Custom media upload (useful for multi-tenant)
      mediaUpload: async (result, { request, collection }) => {
        return request.payload.create({
          collection,
          data: result.data,
          file: result.file,
          overrideAccess: false,
          req: request,
        })
      },
    }),
  ],
})
🎨 Custom Components & Fields

Custom fields don't automatically inherit AI capabilities. If your AI-enabled fields don't show Compose settings, manually add this component path:

@ai-stack/payloadcms/fields#ComposeField

Debug Tip: Enable debugging: true in your plugin config to see which fields have AI enabled.


📚 Documentation

Need more details? Check out the Complete Setup Guide for:

  • Custom model configuration
  • Advanced prompt engineering
  • Field-specific customization
  • Troubleshooting tips

🤝 Support This Project

Built with ❤️ in my free time. If this plugin saves you hours of work, consider fueling future development!

Buy Me A Coffee

Every coffee keeps the AI models running and new features shipping. Thank you! 🙏


👥 Contributing

We love contributors! Whether you're fixing typos, suggesting features, or building new capabilities, all contributions are welcome.

Ways to Contribute

  • 🐛 Report bugs
  • 💡 Suggest features
  • 📖 Improve documentation
  • 🔧 Submit pull requests

Join the conversation on Payload's Discord and let's build something amazing together!

Local Development

Want to hack on the plugin? Here's how:

Prerequisites
  • Node.js (version in .nvmrc)
  • pnpm
  • Database connection (Postgres or MongoDB)
  • Optional: AI provider API keys
Setup
# 1. Install dependencies
pnpm install

# 2. Set up environment
cp dev/.env.example dev/.env
# Edit dev/.env with your DATABASE_URI, PAYLOAD_SECRET, and API keys

# 3. Start development server
pnpm dev
# Admin UI available at http://localhost:3000

# 4. Generate types/importmap if needed
pnpm generate:importmap
pnpm generate:types
Development Workflow
  • Plugin source: src/
  • Test app: dev/
  • Edit files in src/ and refresh to see changes
Testing & Quality
pnpm test                    # Run all tests
pnpm lint                    # ESLint
pnpm prettier --write .      # Format code
pnpm build                   # Build plugin
Test in Another Project
pnpm pack
# In your other project:
pnpm add /path/to/ai-plugin-*.tgz
Project Structure
├── src/              # Plugin source code
├── dev/              # Test Payload app
│   ├── int.spec.ts   # Integration tests
│   └── e2e.spec.ts   # E2E tests
└── README.md         # You are here!

Made with ❤️ and ☕ by the community

Star on GitHub • Join Discord • Read the Guide

Similar plugins