Drupal + AI 2026-11-05 ยท 7 min read

Integrating Anthropic Claude & OpenAI into the Drupal 11 Editorial Workflow

Carlos Del Hierro
Carlos Del Hierro
Senior Drupal 10/11 & AI Architect ยท 10+ years Drupal experience
Integrating Anthropic Claude & OpenAI into the Drupal 11 Editorial Workflow

Editorial teams in universities, media groups, and public administrations spend up to 60% of their time on repetitive tasks: translating content into English, writing SEO meta descriptions, summarizing long documents, and assigning taxonomy tags. By integrating Anthropic Claude or OpenAI directly into the Drupal 11 node edit form, we turn a 20-minute task into a 5-second review.

1. Architecture of a Native Drupal 11 AI Module

In my open-source module Drupal AI Assistant, the integration follows strict Drupal enterprise best practices:

  • Key Management: Never store API keys in plain configuration. Use the key module or environment variables outside the webroot.
  • Service Layer: Create an injectable service (drupal_ai_assistant.client) wrapping Drupal's http_client (Guzzle) with timeouts and structured system prompts.
  • Form Alter & AJAX Callbacks: Attach non-intrusive action buttons directly to node edit forms via hook_form_BASE_FORM_ID_alter().

2. Structured Prompts for Reliable JSON Output

When auto-generating SEO metadata or taxonomy suggestions, instruct Claude to return strict JSON so your Drupal AJAX callback can populate the form fields deterministically:

$response = $this->httpClient->post("https://api.anthropic.com/v1/messages", [
  "headers" => [
    "x-api-key" => $apiKey,
    "anthropic-version" => "2023-06-01",
    "content-type" => "application/json",
  ],
  "json" => [
    "model" => "claude-3-5-sonnet-latest",
    "max_tokens" => 1024,
    "system" => "You are a Drupal editorial assistant. Return valid JSON with keys: summary, seo_description, suggested_tags.",
    "messages" => [
      ["role" => "user", "content" => $nodeBodyText],
    ],
  ],
  "timeout" => 30,
]);

3. Human-in-the-Loop Validation

AI should assist editors, never publish blindly. Combined with Drupal Content Validator, every AI-generated translation or summary passes through business-rule validators before a node can transition to Published.

#Drupal 11 #Anthropic Claude #OpenAI #Custom Modules #AJAX

Want to implement this in your Drupal platform?

Have questions about this architecture, Drupal 11 + PHP 8.4, or AI/MCP workflows? Feel free to reach out and connect.