API plugins
The api_plugins module provides a flexible foundation for building API integrations in Drupal. It offers plugin management, request execution, and authentication handling, allowing developers to create reusable connections to external services without extensive custom code for each integration.
Extensible API integration framework for Drupal.
API Plugins provides a shared, plugin-based foundation for connecting Drupal with external APIs. Define endpoint-specific API plugins while reusing consistent request execution, Key module authentication, timeout handling, and error handling.
Features
- API plugin discovery and management
- Shared HTTP request, timeout, and error handling
- Key module based authentication
- Base classes for creating custom API integrations
- Provider integrations for OpenAI, Anthropic, MCP, Ollama, and Docker Model Runner
- Optional API endpoint fields, field mapping, and queued remote-data imports
Requirements
- Drupal 10 or 11
- PHP 8.1 or later
- Key module
Installation
composer require drupal/api_plugins drush en api_plugins
Enable only the optional submodules you need:
drush en api_plugins_openai drush en api_plugins_anthropic drush en api_plugins_mcp drush en api_plugins_ollama drush en api_plugins_field_mapping drush en api_plugins_import_ui
Basic Usage
Call a configured API plugin through the shared request service:
$api_service = \Drupal::service('api_plugins.request'); $result = $api_service->sendRequest('openai_chat_completions', [ 'prompt' => 'What is the capital city of Czechia?', 'model' => 'gpt-4o-mini', 'temperature' => 0.0, ]);
Custom API Plugins
Create a plugin in src/Plugin/ApiPlugin/ in your custom module, extending the provided base classes. API Plugins handles plugin discovery, request execution, authentication, and common error handling while your plugin defines its endpoint, payload, headers, and response formatting.
Field Mapping and Imports
The optional Field Mapping submodule provides an api_endpoint field type for storing remote data-source URLs and import settings. It can detect structured data, map source values to entity fields, and queue imports for cron processing. The Import UI submodule adds manual import actions to supported entity edit forms.
Remote endpoint requests are protected against common server-side request forgery risks: non-HTTP(S), loopback, private, link-local, and reserved addresses are rejected, and redirects are disabled.
Provider Integrations
- OpenAI: Chat Completions and Embeddings
- Anthropic: Claude Messages API
- MCP: Model Context Protocol, including Apify MCP
- Ollama: Local Chat Completions and Embeddings
- Docker Model Runner: Local OpenAI-compatible chat completions
Security
Store credentials with the Key module, restrict API Plugins administration permissions, and use provider credentials with only the permissions required for the integration. For Field Mapping deployments, retain outbound network controls as an additional protection layer.
Summary
API Plugins is for developers and site builders who need maintainable, reusable API integrations without creating separate request, authentication, and error-handling services for every provider.
Depends on
Dependencies of the latest stable release
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.