apex_ai
Apex AI — Multi-Provider AI Orchestration for Drupal
Apex AI bridges 9 AI providers into Drupal's AI ecosystem through the MonkeysLegion Apex orchestration engine. One provider plugin — every model, every middleware, zero vendor lock-in.
Why Apex AI?
Drupal's AI module gives you a provider API. Apex AI gives you an AI operations platform:
- 9 providers, 24+ models — Anthropic, OpenAI, Google, xAI, Cohere, DeepSeek, Groq, Mistral, Ollama
- Smart routing — Auto-select models by cost, quality, or latency
- Middleware pipeline — Retry, rate limiting, caching, guardrails, telemetry
- Fallback chains — Automatic failover when a provider goes down
- Full observability — Cost dashboard with filters, pipeline run history, audit logs, Drush CLI
- Enterprise guardrails — Token budgets, PII filtering, content moderation
- GDPR compliance — Per-user data export and deletion, audit retention policies
- Google Service Account support — Auto-exchanges JSON credentials for OAuth2 tokens
Any Drupal module that uses the AI API — CKEditor AI, AI Automators, AI Search, AI Chatbot, AI Translate — works with Apex AI automatically.
What's New in v2.0.0
Feature Description Cost Dashboard Real-time cost tracking with period/provider filters, summary cards, CSV export Run Recording Every AI call records provider, model, tokens, cost, latency, and status Audit Trail Full audit log entity: who triggered, what prompt, which model, what response GDPR Compliance Per-user data export and deletion REST endpoints PII Redaction Auto-redact emails, phones, SSNs, credit cards from audit logs Content Governance AI watermarking, quality scoring, brand voice enforcement Google OAuth2 Auto-detect service account JSON and exchange for Bearer tokens Dual Auth Google provider supports both API keys (AIza...) and OAuth2 tokens (ya29...) HTTP/1.1 Forced Fixes HTTP/2 PROTOCOL_ERROR in Docker/containerized environments Extended Timeout 120s default timeout for all providers (configurable) External Integrations Langfuse, OpenTelemetry, Slack, Microsoft Teams webhook support MCP Server Model Context Protocol server for Claude Desktop, Cursor, and other MCP clients ECA Actions Auto-tag, summarize, alt text, quality score, translate — all no-code Agent Crews Multi-agent team orchestration with role-based collaboration Circuit Breaker Automatic provider disable/recovery after consecutive failures Upgrade Hooks Automatic entity schema creation on module upgradeSupported Providers & Models
Provider Models Auth Strengths Anthropic Claude Sonnet 4, Opus 4, Haiku 4 API Key Reasoning, safety, long context OpenAI GPT-4.1, Mini, Nano, o3, o4-mini Bearer Broad capability, tool use Google Gemini 2.5 Pro, Flash API Key or Service Account JSON Multimodal, cost-effective xAI Grok 3, Mini, Fast Bearer Real-time knowledge Cohere Command R+, Command R Bearer RAG, enterprise search DeepSeek Chat, Reasoner Bearer Math, code, reasoning Groq LLaMA 3.3 70B, Mixtral 8x7B Bearer Ultra-low latency Mistral Large, Small Bearer European compliance, multilingual Ollama Any local model None Air-gapped, private, zero costSmart Routing Modes
Select a routing strategy instead of a specific model:
- apex:auto — Intelligent model selection based on prompt analysis
- apex:cost — Route to the cheapest available provider
- apex:quality — Route to the highest-capability model
- apex:latency — Route to the fastest provider
Combined with fallback chains and the circuit breaker, your AI requests survive provider outages automatically.
Cost Dashboard
Enterprise-grade cost monitoring at /admin/config/ai/apex/costs:
- Summary cards — All-time cost, today, this month, total requests, input/output tokens, avg latency
- Period filter — Today, last 7 days, this month, last 3 months, last year, all time
- Provider filter — Drill down to a single provider
- Cost breakdown table — Per-provider aggregation of requests, tokens, cost, and latency
- Recent runs — Last 50 AI calls with full metadata and status indicators
- CSV export — Download all run data for billing reconciliation
- Middleware status — Visual overview of active pipeline components
- Theme compatible — Works with Claro, Gin, Seven, or any admin theme
Middleware Pipeline
Every request passes through a configurable middleware stack:
Middleware Purpose Config Retry Exponential backoff on transient failures Max attempts, delay (ms) Rate Limit Per-provider request throttling Requests/minute Response Cache TTL-based caching to reduce API costs TTL (seconds) Guardrails Token limits, PII blocking, content moderation Max tokens, filter toggle Telemetry Automatic cost, token, and latency recording Sink (Drupal logger, Langfuse, OTEL)Observability & Governance
Audit Trail
- Full audit log entity: user, prompt, response, model, tokens, cost
- PII redaction (email, phone, SSN, credit card — configurable)
- Retention policy with auto-purge after N days
- Admin review at
/admin/config/ai/apex/audit
GDPR Compliance
GET /api/apex-ai/gdpr/export/{uid}— Export all AI interactions for a userDELETE /api/apex-ai/gdpr/delete/{uid}— Permanently erase a user's AI data
Content Governance
- AI-generated content watermarking (metadata flag)
- Quality scoring for AI outputs
- Brand voice enforcement via guardrail rules
External Integrations
- Langfuse — LLM observability platform
- OpenTelemetry — Distributed tracing
- Slack / Microsoft Teams — Budget alert notifications
Submodules
Apex AI Orchestration
Pipeline and crew management with a full cost dashboard.
- Named AI workflows (pipelines) with configurable models
- Multi-agent crew collaboration
- Content safety guardrails (PII filtering, token budgets)
- Cost Dashboard — Real-time per-provider cost tracking with filters
- Pipeline Runs — Full execution history with status and metrics
- Audit Logs — Complete interaction history with PII redaction
Apex AI Agents
Autonomous AI agents using a ReAct-style reasoning loop.
- Config entity-based agent definitions with goals, tools, and memory
- Multi-step reasoning with tool calling
- 5 built-in tools: CreateNode, UpdateField, SearchContent, QueryViews, SendEmail
- Async execution via queue workers or webhook triggers
- Crew orchestrator for multi-agent team coordination
Apex AI Prompts
Reusable prompt template library.
- Config entity for prompt templates with token variables (
{{ variable }}) - Version tracking and live preview
- Categorization and tagging
Apex AI ECA
No-code AI automation via ECA.
- AutoTagAction — Auto-tag content using AI classification
- GenerateSummaryAction — Generate content summaries on save
- GenerateAltTextAction — Generate image alt text
- QualityScoreAction — Score content quality
- TranslateFieldAction — Translate field values
Apex AI MCP Server
JSON-RPC 2.0 Model Context Protocol server.
- Exposes Drupal content as MCP resources
- Registers Drupal operations as MCP tools
- Compatible with Claude Desktop, Cursor, and other MCP clients
Apex AI Vector Database
Zero-dependency VDB provider for the AI Search module.
- SQLite-based vector storage with cosine similarity
- Full Search API integration
- Automatic content chunking and embedding
REST API
Method Endpoint DescriptionPOST
/api/apex-ai/generate
Generate AI response
POST
/api/apex-ai/stream
Streaming AI response (SSE)
GET
/api/apex-ai/health
Provider health check
GET
/api/apex-ai/models
List available models
GET
/api/apex-ai/costs
Cost summary (JSON)
GET
/api/apex-ai/costs/export
Full run data (CSV)
GET
/api/apex-ai/gdpr/export/{uid}
Export user AI data
DELETE
/api/apex-ai/gdpr/delete/{uid}
Delete user AI data
POST
/api/apex-ai/search
RAG semantic search
POST
/api/apex-ai/mcp
MCP JSON-RPC endpoint
Drush Commands
Command Alias Descriptiondrush apex:test <prompt>
axt
Test a provider with a prompt
drush apex:providers
axp
List all 9 providers with status
drush apex:costs
axc
Cost breakdown by provider
drush apex:runs
axr
Recent pipeline execution log
drush apex:agent:run <id> <goal>
axag
Execute an AI agent
Architecture
Drupal AI Module (CKEditor AI, AI Automators, AI Search...) │ ▼ ┌─────────────────────────────────────────────────┐ │ ApexProvider Plugin │ │ ChatInterface + EmbeddingsInterface │ │ │ │ translateInput → generate → recordRun → output │ └─────────────┬───────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────┐ │ ApexFactory │ │ │ │ resolveProvider → resolveApiKey → createProvider │ │ Google: JSON → JWT → OAuth2 → Bearer Token │ └─────────────┬───────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────┐ │ MonkeysLegion Apex SDK (v1.0.4) │ │ │ │ Anthropic │ OpenAI │ Google │ DeepSeek │ Groq │ │ Mistral │ xAI │ Cohere │ Ollama │ │ │ │ HTTP/1.1 forced · Dual auth · 120s timeout │ └─────────────────────────────────────────────────┘
Installation
composer require drupal/apex_ai drush en apex_ai -y
Quick Start Recipe
php core/scripts/drupal recipe web/modules/custom/apex_ai/recipes/apex_ai_quickstart
Enterprise Recipe
php core/scripts/drupal recipe web/modules/custom/apex_ai/recipes/apex_ai_enterprise
Requirements
- Drupal ≥ 11.2
- PHP ≥ 8.4
- drupal/ai ≥ 1.4
- drupal/key ≥ 1.18
- monkeyscloud/monkeyslegion-apex ≥ 1.0.4
Docker & Containerized Environments
- HTTP/1.1 forced — SDK forces
CURL_HTTP_VERSION_1_1to prevent HTTP/2 stream errors - 120s timeout — Extended timeout for slow container networking
- OPcache — Restart PHP-FPM after code changes (
docker compose restart php)
Security
- API keys stored via the Key module — never in config YAML
- Google service account JSON exchanged for short-lived OAuth2 tokens (1-hour TTL)
- All admin routes require
administer apex_aipermission - PII auto-redaction in audit logs
- GDPR-compliant per-user data export and deletion
Links
- Issue queue: drupal.org/project/issues/apex_ai
- Source code: git.drupalcode.org/project/apex_ai
- MonkeysLegion Apex SDK: packagist.org/packages/monkeyscloud/monkeyslegion-apex
Maintained by MonkeysCloud