---
title: "Using OpenAI/ChatGPT in Drupal"
date: "2023-03-06T21:28:18+00:00"
summary:
image:
type: "article"
url: "/acquia-cloud-platform/help/89296-using-openaichatgpt-drupal"
id: "0ba38275-74d4-4cc2-8786-f9378126ef57"
---

Table of contents will be added

Goal
----

This tutorial will show you how to install, enable, and use the OpenAI Drupal module.

Prerequisites
-------------

*   A Drupal 10 site
*   Composer must be installed on your local machine.
*   An OpenAI account

Overview
--------

If you read [Dries'](https://dri.es/) blog post, [Artificial Intelligence, the future of Content Management and the Web](https://dri.es/artificial-intelligence-the-future-of-content-management-and-the-web), you will know that he references [Drupal integrations for ChatGPT](https://www.drupal.org/project/openai) created by [Kevin Quillen](https://dev.acquia.com/person/partner/kevin-quillen). In this tutorial, we are going to deep dive on two of the modules from [Drupal integrations for ChatGPT](https://www.drupal.org/project/openai). Let's walk through installing and configuring the core OpenAI module and the OpenAI CKEditor integration, to start using OpenAI inside of a Drupal application.

1.  Add OpenAI module
    -----------------
    
    To add OpenAI to a [Drupal 10](/drupal10) application, we need to add the [OpenAI](https://www.drupal.org/project/openai) module.
    
    Run the Composer command to add the OpenAI module to the codebase.
    
        
        composer require 'drupal/openai:^1.0@alpha'
        
    
2.  Enable OpenAI and OpenAI CKEditor
    ---------------------------------
    
    To use the OpenAI module, we have to enable the core OpenAI module and one or more submodules.
    
    For this tutorial we are going to use the OpenAI CKEditor integration module so we need enable OpenAI and OpenAI CKEditor integration.
    
    Run the Drush command to enable OpenAI and OpenAI CKEditor integration modules.
    
        
        drush en openai openai_ckeditor -y
        
    
3.  Create OpenAI API key
    ---------------------
    
    Before we can configure the OpenAI module, we need to create an OpenAI API key.
    
    When logged into your OpenAI account, you can visit "[View API Keys](https://platform.openai.com/account/api-keys)" to create a new API key.
    
    To create an API Key, click on "+ Create new secret key."
    
    ![API keys setup page with a button labeled "Create new secret key" and a dropdown for default organization selection.](https://acquia.widen.net/content/c6fc4169-780d-46fa-a4e7-952b0854aca0/web/url_f30a4a443cba400f916b7cd0ac41f468.webp)
    
    Once you have generated the API key, copy the key and save it. You will not be able to view the key again.
    
    ![Popup message showing generated API key with a warning to save it securely, as it won't be viewable again.](https://acquia.widen.net/content/5d49551f-9366-41e5-b057-9c1e6b5c1349/web/url_59cb7508e4413bcc523da45764658b2f.webp)
    
4.  Add OpenAI settings
    -------------------
    
    We are now able to configure the OpenAI module.
    
    Navigate to Configuration → OpenAI → Settings and paste in the API key and save configuration, you do not need to add an Organization name/ID for this tutorial.
    
5.  Add the CKEditor OpenAI Text Generator toolbar button
    -----------------------------------------------------
    
    Before we can use the OpenAI Text Generator toolbar button, we need to add it to our text editor.
    
    Navigate to Configuration → Content authoring → Text formats and editors and configure the text format where you want to use OpenAI Text Generator button. For this tutorial, we are going to add the OpenAI Text Generator button to the Basic HTML text format.
    
    Click "Configure" on Basic HTML and under Toolbar configuration, drag the OpenAI Text Generator button to the Active toolbar, and save configuration.
    
    ![Toolbar configuration interface showing available and active buttons for customization, including text styling options and dropdown menus.](https://acquia.widen.net/content/787b86e8-be94-4b23-9b40-eada25a0f506/web/url_3d638bfde1ecba7fa25b316a2aa8b53d.gif?animate=true)
    
6.  Using the OpenAI Text Generator button
    --------------------------------------
    
    Now that we have the OpenAI Text Generator button added to our text editor, we can prompt it to generate text for us.
    
    ![Text editor interface with formatting options, a text input field, and a tags section for entering comma-separated list of locations.](https://acquia.widen.net/content/c1c83e47-24a3-4a47-afab-f727274d29bd/web/url_42eb646dfa13c3d4cd5a37fad8b6fc88.gif?animate=true)
    

Adding the OpenAI and the OpenAI CKEditor modules is only the beginning of using OpenAI within a Drupal application. Now that you have configured the core module, you can begin experimenting with the other features that come with the module.