ai_writer
AI Writer adds an OpenAI-powered writing assistant directly to your content forms. When creating or editing an article or any other content type, authors can type a plain-language instruction — like "Write a 300-word news article about our upcoming spring festival" — and the module generates a draft and drops it right into the body editor, ready to review and refine. It turns a blank page into a starting point, without leaving Drupal or copying and pasting from another AI tool.
Features
The basic functionality: an AI Writer panel appears on node add/edit forms with a prompt box and a Generate draft button. Behind the scenes the module calls the OpenAI Chat Completions API server-side, sanitizes the response, and inserts the resulting HTML into the body field's CKEditor 5 editor (falling back to a plain textarea when no WYSIWYG is present).
Unique features this module adds:
- A single admin config page to set your OpenAI API key, model, system prompt, temperature, and max tokens — no code required.
- Environment-variable support for the API key (
OPENAI_API_KEY), which takes precedence over the stored config value, so secrets can stay out of your database and exported configuration. - Server-side API calls: the key is never exposed to the browser.
- Output passed through Drupal's XSS filter before it reaches the editor.
- Permission-gated (Use AI Writer) and CSRF-protected requests.
- Works on every content type automatically — no per-type configuration.
When and why to use it: any site where editors regularly draft articles, news posts, or landing-page copy and would benefit from a fast first draft. Typical use cases include newsrooms, university and marketing sites, and multi-author blogs where reducing "blank page" friction speeds up publishing.
Post-Installation
After enabling the module:
- Go to Administration → Configuration → Content authoring → AI Writer (
/admin/config/content/ai-writer) and provide your OpenAI API key (or set theOPENAI_API_KEYenvironment variable instead — it wins over the config value). Optionally adjust the model, system prompt, temperature, and max tokens. - Grant the Use AI Writer permission to the roles that should have the assistant (e.g. Author, Editor) at
/admin/people/permissions. - Create or edit any content item. You'll see the AI Writer panel above the fields — enter an instruction, click Generate draft, and the draft is inserted into the body editor.
There is no new content type to look for and no text-format changes are required. The module targets the body field's CKEditor 5 instance automatically; if a form has no WYSIWYG, the text is appended to the raw textarea instead. Clear caches after enabling (drush cr) so the form additions and library attach correctly.
Additional Requirements
- Drupal core
^10 || ^11with the Node module (a core module, and a declared dependency). - An OpenAI API key with access to a chat model (default
gpt-4o-mini) — see platform.openai.com. - Outbound HTTPS access from your server to
api.openai.com.
No additional contributed modules or third-party PHP libraries are required — the module uses Drupal's built-in Guzzle HTTP client.
Recommended modules/libraries
- Any CKEditor 5 configuration (core) — the generated HTML lands in the body editor, so an editor set up for the tags the model returns (headings, lists, links) gives the best result.
- Key or environment-based secret management (e.g. Pantheon Secrets, or the Key module pattern) to keep the API key out of exported configuration.
Similar projects
The AI (Artificial Intelligence) ecosystem provides a broad, provider-agnostic framework with many sub-modules and integrations. AI Writer is intentionally narrower: a small, self-contained module focused on one job — generating body content from a prompt on node forms — with minimal configuration and no dependency on a larger AI framework. Choose AI Writer when you want a lightweight, drop-in assistant; choose the AI framework when you need multiple providers, agents, or deeper platform integration.
Supporting this Module
Add your Patreon, Open Collective, GitHub Sponsors, or contact links here.
Community Documentation
Add links to walkthrough videos, a demo site (via DrupalPod), or extended docs here. See the module's README.md for full configuration, security notes, and testing instructions.