npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

payloadcms-openai-textgen

v0.2.0

Published

AI text generation plugin for Payload CMS v3 — adds an OpenAI-powered text generator to the Lexical rich text editor toolbar

Readme

payloadcms-openai-textgen

npm version npm downloads license

AI text generation plugin for Payload CMS v3. Adds an "AI Generate" button to the Lexical rich text editor toolbar that opens a drawer where users can enter a prompt and insert AI-generated content directly into the editor.

Uses OpenAI's chat completions API under the hood.

Features

  • Sparkles button in both the fixed and inline Lexical toolbars
  • Drawer UI with a prompt textarea
  • Generated HTML is parsed and inserted as proper Lexical nodes (headings, lists, paragraphs, etc.)
  • Configurable model, max tokens, system prompt, and endpoint path
  • Works with OpenAI SDK v4, v5, and v6

Requirements

  • Payload CMS v3
  • @payloadcms/richtext-lexical v3
  • Node.js 18+

Installation

pnpm add payloadcms-openai-textgen

Set the OPENAI_API_KEY environment variable (or pass apiKey in plugin options).

Usage

// payload.config.ts
import { buildConfig } from 'payload'
import { lexicalEditor } from '@payloadcms/richtext-lexical'
import { aiTextGenPlugin, AIGenerateFeature } from 'payloadcms-openai-textgen'

export default buildConfig({
  // 1. Register the plugin (adds the API endpoint)
  plugins: [
    aiTextGenPlugin({
      model: 'gpt-4o-mini', // optional, default: 'gpt-4o-mini'
    }),
  ],
  // 2. Add the feature to the Lexical editor
  editor: lexicalEditor({
    features: ({ defaultFeatures }) => [
      ...defaultFeatures,
      AIGenerateFeature(),
    ],
  }),
  // ... rest of config
})

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | model | string | 'gpt-4o-mini' | OpenAI model to use | | maxTokens | number | 1024 | Maximum tokens for the response | | systemPrompt | string | (built-in CMS prompt) | Custom system prompt for content generation | | apiKey | string | process.env.OPENAI_API_KEY | OpenAI API key | | endpointPath | string | '/ai-generate' | Custom endpoint path |

How It Works

  1. The plugin registers a Payload API endpoint (POST /api/ai-generate) that proxies requests to OpenAI
  2. The Lexical feature adds a sparkles icon button to both the fixed and inline toolbars
  3. Clicking the button opens a drawer with a prompt textarea
  4. On submit, the prompt is sent to the endpoint, which calls OpenAI and returns HTML
  5. The HTML is parsed and inserted into the editor as Lexical nodes

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

# Clone the repo
git clone https://github.com/sgordeychuk/payloadcms-openai-integration.git
cd payloadcms-openai-textgen

# Install dependencies
pnpm install

# Build
pnpm build

# Watch mode
pnpm dev

Local development with a Payload project

Use pnpm link to test changes locally:

# In this plugin directory
pnpm link --global

# In your Payload project
pnpm link --global payloadcms-openai-textgen

License

MIT