{"id":29111,"date":"2026-04-07T09:55:15","date_gmt":"2026-04-07T13:55:15","guid":{"rendered":"https:\/\/plumrocket.com\/docs\/?p=29111"},"modified":"2026-04-07T12:01:31","modified_gmt":"2026-04-07T16:01:31","slug":"how-to-use-the-ai-connector-in-custom-extensions","status":"publish","type":"post","link":"https:\/\/plumrocket.com\/docs\/magento-ai-connector\/v1\/devguide\/php-api","title":{"rendered":"How to Use the AI Connector in Custom Extensions"},"content":{"rendered":"\n<h2 id=\"h-available-php-services\">Available PHP Services<\/h2>\n\n\n\n<p>The <a href=\"https:\/\/plumrocket.com\/magento-ai-connector\">Plumrocket AI Connector extension<\/a> exposes two public PHP services that can be used in any Magento 2 module to interact with AI integrations:<\/p>\n\n\n\n<ul><li><strong>\\Plumrocket\\AiConnector\\Api\\IntegrationProviderInterface <\/strong>&#8211; retrieves information about available AI integrations<\/li><li><strong>\\Plumrocket\\AiConnector\\Api\\PromptProcessorInterface<\/strong> &#8211; sends a prompt to an AI integration and returns the generated text<\/li><\/ul>\n\n\n\n<h2 id=\"h-using-the-plumrocket-aiconnector-api-integrationproviderinterface-service\">Using the \\Plumrocket\\AiConnector\\Api\\IntegrationProviderInterface Service<\/h2>\n\n\n\n<p>This service allows you to retrieve all registered AI integrations or fetch a specific one by its code. Each returned object implements <strong>\\Plumrocket\\AiConnector\\Api\\Data\\IntegrationInfoInterface<\/strong> and exposes the following methods:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Method<\/td><td>Return type<\/td><td>Description<\/td><\/tr><tr><td>getCode()<\/td><td>string<\/td><td>Unique integration identifier (e.g. OpenAI, Anthropic, Google)<\/td><\/tr><tr><td>getLabel()<\/td><td>string<\/td><td>Human-readable name (e.g. OpenAI (GPT))<\/td><\/tr><tr><td>isEnabled()<\/td><td>bool<\/td><td>Whether the integration is enabled in the Admin Configuration<\/td><\/tr><tr><td>getSupportedModels()<\/td><td>string[]<\/td><td>List of available model codes for this integrationList of available model codes for this integration<\/td><\/tr><tr><td>getDefaultModel()<\/td><td>string|null<\/td><td>Default model configured in Admin, or null if not set<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 id=\"h-example-1-get-all-registered-integrations-and-check-their-status\">Example 1. Get all registered integrations and check their status<\/h3>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">use Plumrocket\\AiConnector\\Api\\IntegrationProviderInterface;\n\nclass YourClass\n{\n    private $integrationProvider;\n\n    public function __construct(\n        IntegrationProviderInterface $integrationProvider\n    ) {\n        $this->integrationProvider = $integrationProvider;\n    }\n\n    public function listIntegrations(): void\n    {\n        $integrations = $this->integrationProvider->getAllIntegrations();\n\n        foreach ($integrations as $integration) {\n            if ($integration->isEnabled()) {\n                $models = $integration->getSupportedModels();\n                $default = $integration->getDefaultModel();\n                \/\/ use $models and $default as needed\n            }\n        }\n    }\n}\n<\/code><\/pre><\/div>\n\n\n\n<h3 id=\"h-example-2-get-a-specific-integration-by-code\">Example 2. Get a specific integration by code<\/h3>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">use Magento\\Framework\\Exception\\LocalizedException;\nuse Plumrocket\\AiConnector\\Api\\IntegrationProviderInterface;\n\nclass YourClass\n{\n    private $integrationProvider;\n\n    public function __construct(\n        IntegrationProviderInterface $integrationProvider\n    ) {\n        $this->integrationProvider = $integrationProvider;\n    }\n\n    public function getOpenAiModels(): array\n    {\n        $integration = $this->integrationProvider->getIntegration('openai');\n\n         if ($integration->isEnabled()) {\n            return $integration->getSupportedModels();\n         }\n        \n        return [];\n    }\n}\n<\/code><\/pre><\/div>\n\n\n\n<h2>Using the \\Plumrocket\\AiConnector\\Api\\PromptProcessorInterface Service<\/h2>\n\n\n\n<p>This service processes a text prompt through the specified AI integration and returns the generated response as a plain string. It validates that both the module and the selected integration are enabled before making the API call, and logs the request result automatically.<\/p>\n\n\n\n<p>Method signature:<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">public function processPrompt(string $integrationCode, string $prompt, ?string $model = null): string;<\/code><\/pre><\/div>\n\n\n\n<p>Parameters:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Parameter<\/td><td>Type<\/td><td>Required<\/td><td>Description<\/td><\/tr><tr><td>$integrationCode<\/td><td>string<\/td><td><span style=\"color:#00a337\" class=\"has-inline-color\">Yes<\/span><\/td><td>Integration to use: openai, anthropic, or google<\/td><\/tr><tr><td>$prompt<\/td><td>string<\/td><td><span style=\"color:#00a337\" class=\"has-inline-color\">Yes<\/span><\/td><td>The text prompt to send to the AI<\/td><\/tr><tr><td>$model<\/td><td>string|nul<\/td><td><span style=\"color:#8300a3\" class=\"has-inline-color\">No<\/span><\/td><td>Specific model code to use. If null, uses the default model from Admin configuration<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 id=\"h-example-1-generate-content-using-the-default-configured-model\">Example 1. Generate content using the default configured model<\/h3>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">use Magento\\Framework\\Exception\\LocalizedException;\nuse Plumrocket\\AiConnector\\Api\\PromptProcessorInterface;\n\nclass YourClass\n{\n    private $promptProcessor;\n\n    public function __construct(\n        PromptProcessorInterface $promptProcessor\n    ) {\n        $this->promptProcessor = $promptProcessor;\n    }\n\n    public function generateProductDescription(string $productName): string\n    {\n        return $this->promptProcessor->processPrompt(\n            'openai',\n            'Write a short product description for: ' . $productName\n        );\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<h3 id=\"h-example-2-generate-content-using-a-specific-model\">Example 2. Generate content using a specific model<\/h3>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">use Magento\\Framework\\Exception\\LocalizedException;\nuse Plumrocket\\AiConnector\\Api\\PromptProcessorInterface;\n\nclass YourClass\n{\n    private $promptProcessor;\n\n    public function __construct(\n        PromptProcessorInterface $promptProcessor\n    ) {\n        $this->promptProcessor = $promptProcessor;\n    }\n\n    public function generateSeoMetaDescription(string $pageContent): string\n    {\n        try {\n            return $this->promptProcessor->processPrompt(\n                'anthropic',\n                'Write an SEO meta description (max 160 characters) for: ' . $pageContent,\n                'claude-sonnet-4-5'\n            );\n        } catch (LocalizedException $e) {\n            return '';\n        }\n    }\n}<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Available PHP Services The Plumrocket AI Connector extension exposes two public PHP services that can be used in any Magento 2 module to interact with AI integrations: \\Plumrocket\\AiConnector\\Api\\IntegrationProviderInterface &#8211; retrieves information about available AI integrations \\Plumrocket\\AiConnector\\Api\\PromptProcessorInterface &#8211; sends a prompt to an AI integration and returns the generated text Using the \\Plumrocket\\AiConnector\\Api\\IntegrationProviderInterface Service This service &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/plumrocket.com\/docs\/magento-ai-connector\/v1\/devguide\/php-api\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Use the AI Connector in Custom Extensions&#8221;<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[431],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v17.2 (Yoast SEO v17.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Use the AI Connector in Custom Extensions - Plumrocket Documentation<\/title>\n<meta name=\"description\" content=\"Available PHP Services The Plumrocket AI Connector extension exposes two public PHP services that can be used in any Magento 2 module to interact with AI\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/plumrocket.com\/docs\/magento-ai-connector\/v1\/devguide\/php-api\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Use the AI Connector in Custom Extensions\" \/>\n<meta property=\"og:description\" content=\"Available PHP Services The Plumrocket AI Connector extension exposes two public PHP services that can be used in any Magento 2 module to interact with AI\" \/>\n<meta property=\"og:url\" content=\"https:\/\/plumrocket.com\/docs\/magento-ai-connector\/v1\/devguide\/php-api\" \/>\n<meta property=\"og:site_name\" content=\"Plumrocket Documentation\" \/>\n<meta property=\"article:published_time\" content=\"2026-04-07T13:55:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-07T16:01:31+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Anna Vyhura\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Use the AI Connector in Custom Extensions - Plumrocket Documentation","description":"Available PHP Services The Plumrocket AI Connector extension exposes two public PHP services that can be used in any Magento 2 module to interact with AI","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/plumrocket.com\/docs\/magento-ai-connector\/v1\/devguide\/php-api","og_locale":"en_US","og_type":"article","og_title":"How to Use the AI Connector in Custom Extensions","og_description":"Available PHP Services The Plumrocket AI Connector extension exposes two public PHP services that can be used in any Magento 2 module to interact with AI","og_url":"https:\/\/plumrocket.com\/docs\/magento-ai-connector\/v1\/devguide\/php-api","og_site_name":"Plumrocket Documentation","article_published_time":"2026-04-07T13:55:15+00:00","article_modified_time":"2026-04-07T16:01:31+00:00","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Anna Vyhura","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/plumrocket.com\/docs\/#website","url":"https:\/\/plumrocket.com\/docs\/","name":"Plumrocket Documentation","description":"Extensions docs, troubleshootings etc.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/plumrocket.com\/docs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/plumrocket.com\/docs\/magento-ai-connector\/v1\/devguide\/php-api#webpage","url":"https:\/\/plumrocket.com\/docs\/magento-ai-connector\/v1\/devguide\/php-api","name":"How to Use the AI Connector in Custom Extensions - Plumrocket Documentation","isPartOf":{"@id":"https:\/\/plumrocket.com\/docs\/#website"},"datePublished":"2026-04-07T13:55:15+00:00","dateModified":"2026-04-07T16:01:31+00:00","author":{"@id":"https:\/\/plumrocket.com\/docs\/#\/schema\/person\/83d6ca862f1c9fc125ee120302a59a7d"},"description":"Available PHP Services The Plumrocket AI Connector extension exposes two public PHP services that can be used in any Magento 2 module to interact with AI","breadcrumb":{"@id":"https:\/\/plumrocket.com\/docs\/magento-ai-connector\/v1\/devguide\/php-api#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/plumrocket.com\/docs\/magento-ai-connector\/v1\/devguide\/php-api"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/plumrocket.com\/docs\/magento-ai-connector\/v1\/devguide\/php-api#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Magento 2 Extensions","item":"https:\/\/plumrocket.com\/magento-extensions"},{"@type":"ListItem","position":2,"name":"Magento 2 AI Connector","item":"https:\/\/plumrocket.com\/magento-ai-connector"},{"@type":"ListItem","position":3,"name":"Documentation","item":"https:\/\/plumrocket.com\/docs\/magento-ai-connector"},{"@type":"ListItem","position":4,"name":"v1","item":"https:\/\/plumrocket.com\/docs\/magento-ai-connector\/v1"},{"@type":"ListItem","position":5,"name":"Developer Guide","item":"https:\/\/plumrocket.com\/docs\/magento-ai-connector\/v1\/devguide"},{"@type":"ListItem","position":6,"name":"How to Use the AI Connector in Custom Extensions"}]},{"@type":"Person","@id":"https:\/\/plumrocket.com\/docs\/#\/schema\/person\/83d6ca862f1c9fc125ee120302a59a7d","name":"Anna Vyhura","image":{"@type":"ImageObject","@id":"https:\/\/plumrocket.com\/docs\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/d8f0a4fcfec77b8b3d835d1c3c8148ed?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d8f0a4fcfec77b8b3d835d1c3c8148ed?s=96&d=mm&r=g","caption":"Anna Vyhura"}}]}},"_links":{"self":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts\/29111"}],"collection":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/comments?post=29111"}],"version-history":[{"count":8,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts\/29111\/revisions"}],"predecessor-version":[{"id":29119,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts\/29111\/revisions\/29119"}],"wp:attachment":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/media?parent=29111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/categories?post=29111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/tags?post=29111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}