Sign up (with export icon)

Integrating CKEditor AI with your application

Show the table of contents

This guide will take you step-by-step through the process of running CKEditor AI in your editor integration. It also presents possible configuration and customization options.

Installation

Copy link

After installing the editor, add the feature to your plugin list and provide essential configuration:

import { ClassicEditor } from 'ckeditor5';
import { AIChat, AIQuickActions, AIActions, AIReviewMode, AIBalloon, TrackChanges } from 'ckeditor5-premium-features';

ClassicEditor
	.create( document.querySelector( '#editor' ), {
		licenseKey: '<YOUR_LICENSE_KEY>',

		plugins: [
			// AI plugins responsible for the core functionality.
			AIChat, AIQuickActions, AIReviewMode,

			// Recommended TrackChanges dependency. Follow the guide to learn more.
			TrackChanges,

			/* ... */
		],

		// AI feature configuration.
		ai: {
			// Mandatory UI configuration.
			container: {
				/* ... */
			},

			/* ... */
		}

		/* Other configurations. Follow the guide to learn more. */
	} )
	.then( /* ... */ )
	.catch( /* ... */ );
Copy code
Note

You must configure a user interface type for the AI features to work. Learn more about the available options in the UI placement section or use the sample implementation as a reference.

Note

Using AI features with the TrackChanges plugin requires the Users plugin integration. Learn more about the Track Changes plugin integration or refer to the sample implementation for more details.

Note

Sample implementation

Copy link

An example CKEditor AI configuration is presented below. You can learn more about specific configurations such as UI types and positioning or Track Changes dependency in the later sections of this guide.

To learn more about toolbar configuration, refer to the toolbar configuration guide.

// Simplified integration of the Users plugin needed for TrackChanges integration.
class UsersIntegration extends Plugin {
    static get requires() {
        return [ 'Users' ];
    }

    init() {
        const users = this.editor.plugins.get( 'Users' );

        // Just add a minimal dummy user
        users.addUser( { id: 'user-1', name: 'John Doe' } );
        users.defineMe( 'user-1' );
    }
}

ClassicEditor
    .create( editorElement, {
        licenseKey: '<YOUR_LICENSE_KEY>',

        plugins: [ AIChat, AIQuickActions, AIReviewMode, TrackChanges, UsersIntegration, /* ... */ ],

        // Extend the main editor toolbar configuration with additional buttons:
        // - 'aiQuickActions': opens the AI Quick Actions menu,
        // - 'ask-ai': moves the user focus to the AI Chat,
        // - 'improve-writing': executes the "Improve Writing" quick action.
        //
        // You can add more AI Quick actions to the toolbar configuration if needed.
        toolbar: [ 'aiQuickActions', 'ask-ai', 'improve-writing', /* ... */ ],

        // You can use the same AI feature buttons in the balloon toolbar configuration for contextual convenience.
        balloonToolbar: {
            items: [
                /* ... */

                'aiQuickActions', 'ask-ai', 'improve-writing', /* ... */
            ]
        },

        // Configure the document identifier for AI chat history and context preservation.
        // This should be a unique identifier for the document/article being edited.
        collaboration: {
            channelId: 'channelId' // Replace with your actual document ID
        },

        // Main configuration of AI feature.
        ai: {
            // ⚠️ Mandatory UI configuration.
            // Display the AI user interface in a dedicated DOM element. The interface can be also displayed
            // in an overlay or in a custom way, learn more in the next chapters of this guide.
            container: {
                type: 'sidebar',
                element: document.querySelector( '.ai-sidebar' )
            },

            // (Optional) Configure the AI Chat feature by configuring available context resources.
            chat: {
                context: {
                    // Configuration of the built-in context options.
                    document: {
                        enabled: true
                    },
                    urls: {
                        enabled: false
                    },
                    files: {
                        enabled: true
                    },

                    // (Optional) Additional sources for the AI Chat context.
                    sources: [
                        {
                            id: 'my-docs',
                            label: 'My Documents',
                            getResources: ( query?: string ) => fetchMyDocuments( query ),
                            getData: ( id ) => fetchDocumentContent( id )
                        },
                        models: {
                            defaultModelId: OpenAI,
                            modelSelectorAlwaysVisible: true,
                            displayedModels: OpenAI, Anthropic, Gemini
                        }
                    ]
                }
            },

            // (Optional) Configure the AI Quick Actions feature by adding a new command.
            quickActions: {
                extraCommands: [
                    // An action that opens the AI Chat interface for interactive conversations.
                    {
                        id: 'explain-like-i-am-five',
                        displayedPrompt: 'Explain like I am five',
                        prompt: 'Explain the following text like I am five years old.',
                        type: 'CHAT'
                    },

                    // ... More custom actions ...
                ],
            },
        }
    } )
    .then( /* ... */ )
    .catch( /* ... */ );
Copy code

Configuration

Copy link

Supported AI models

Copy link

CKEditor AI supports OpenAI, Anthropic, and Gemini AI models. By default, the automatically selected model will be used for optimal cost and performance.

You can narrow down the list of available models. Learn how to configure the list of available models in Chat.

Here’s a detailed list of available models with their capabilities:

Model Description Web Search Reasoning Configuration id
Auto (default) Automatically selects best model for speed, quality, and cost. Yes Yes 'auto' (also 'agent-1', learn more about compatibility versions)
GPT-5 OpenAI’s flagship model for advanced reasoning, creativity, and complex tasks Yes Yes 'gpt-5'
GPT-5 Mini A lightweight version of GPT-5 – faster, more cost-efficient Yes Yes 'gpt-5-mini'
Claude 4.5 Haiku Cost-efficient model for quick interactions with improved reasoning Yes Yes 'claude-4-5-haiku'
Claude 4 Sonnet Advanced model with strong reasoning and reliability for complex tasks Yes Yes 'claude-4-sonnet'
Claude 4.5 Sonnet Advanced model with improved creativity, reliability, and reasoning Yes Yes 'claude-4-5-sonnet'
Gemini 2.5 Flash Lightweight Gemini model for fast, cost-efficient interactions Yes Yes 'gemini-2-5-flash'
GPT-4.1 OpenAI’s model for reliable reasoning, speed, and versatility Yes No 'gpt-4.1'
GPT-4.1 Mini A lighter variant of GPT-4.1 that balances speed and cost while maintaining solid accuracy Yes No 'gpt-4.1-mini'
Claude 3.5 Haiku Anthropic’s fast, cost-efficient model for simpler tasks Yes No 'claude-3-5-haiku'
Note

Learn more about model capabilities such as Web Search and Reasoning.

Note

We intend to expand this list of supported agents further with time. In the future, it will also be possible to use custom models and your own API keys in the on-premises version. Share your feedback on model availability.

Note

You can verify which models are compatible with your service version using a dedicated API. Learn more.

Document ID

Copy link

The config.collaboration.channelId configuration serves as the document identifier corresponding to the edited resource (article, document, etc.) in your application. This ID is essential for maintaining Chat history, ensuring that AI conversations are properly associated with the specific document being edited. When users interact with AI features, their chat history is preserved and linked to this document ID.

ClassicEditor
    .create( document.querySelector( '#editor' ), {
        /* ... */

        collaboration: {
            channelId: 'DOCUMENT_ID'
        },

        /* ... */
    } )
    .then( /* ... */ )
    .catch( /* ... */ );
Copy code
Note

The channelId configuration uses the collaboration namespace in the configuration, which may not be immediately understandable for integrators who are not using collaboration features in their setup. This namespace is subject to change in future versions as we continue to refine the AI integration architecture.

Track Changes dependency

Copy link

CKEditor AI can leverage the TrackChanges plugin to enhance the user experience, for instance, by allowing users to turn AI-generated content into suggestions that can later be reviewed, accepted, or rejected. Without the TrackChanges plugin, the CKEditor AI will work, but some functionalities may be limited. For the most complete integration, we highly recommend using TrackChanges along with CKEditor AI.

Note

Please keep in mind that the TrackChanges plugin requires the Users plugin, and as such, it will require you to provide a minimal user integration, even for non-collaborative setups.

The sample implementation above shows a basic UsersIntegration class that adds a dummy user. For production applications, replace the dummy user with actual user data from your authentication system. Learn more about configuring the Users plugin in a dedicated guide.

UI types and positioning

Copy link

CKEditor AI gives you flexible options for displaying the AI user interface. The config.ai.container property allows you to choose from three different UI placement modes:

Copy link

When in AIContainerSidebar mode, the AI user interface is displayed in a specific DOM element, allowing you to inject it into your existing user interface.

ClassicEditor
    .create( document.querySelector( '#editor' ), {
        // ... Other configuration options ...

        ai: {
            container: {
                type: 'sidebar',

                // Existing DOM element to use as the container for the AI user interface.
                element: document.querySelector( '#ai-sidebar-container' )

                // (Optional) The preferred side for positioning the tab buttons.
                side: 'right'
            },
        }
    } )
    .then( /* ... */ )
    .catch( /* ... */ );
Copy code

In addition to the above, we recommend using the following or similar CSS to style the sidebar container for the AI user interface (tabs) to render optimally:

#ai-sidebar-container .ck.ck-ai-tabs {
    /* An arbitrary fixed width to limit the space consumed by the AI tabs. */
    width: 500px;

    /* A fixed height that enables vertical scrolling (e.g., in the AI Chat feed). */
    height: 800px;
}
Copy code

Overlay

Copy link

When in AIContainerOverlay mode, the AI user interface is displayed on top of the page, allowing you to position it on your preferred side. This mode is best suited for integrations with limited space.

ClassicEditor
    .create( document.querySelector( '#editor' ), {
        // ... Other configuration options ...

        ai: {
            container: {
                type: 'overlay',
                side: 'right'
            },
        }
    } )
    .then( /* ... */ )
    .catch( /* ... */ );
Copy code

Learn how to toggle the AI overlay using a dedicated toolbar button.

Custom

Copy link

When in AIContainerCustom mode, the AI user interface is displayed in a custom way, allowing you to use the building blocks of the AI user interface to create your own and satisfy the specific needs of your application.

ClassicEditor
    .create( document.querySelector( '#editor' ), {
        // ... Other configuration options ...

        ai: {
            container: {
                type: 'custom'
            },
        }
    } )
    // A custom integration of the AI user interface placing the tab buttons and panels separately in custom containers.
    .then( editor => {
        const tabsPlugin = editor.plugins.get( 'AITabs' );

        for ( const id of tabsPlugin.view.getTabIds() ) {
            const tab = tabsPlugin.view.getTab( id );

            // Display tab button and panel in a custom container.
            myButtonsContainer.appendChild( tab.button.element );
            myPanelContainer.appendChild( tab.panel.element );
        }
    } )
    .catch( /* ... */ );
Copy code

Toggling the UI

Copy link

The user interface can be easily toggled by the users using the 'toggleAi' Ask AI toolbar button. The button becomes available for configuration when the AIEditorIntegration plugin is enabled.

The following example shows how to enable the 'toggleAi' button in the main editor toolbar:

import { ClassicEditor } from 'ckeditor5';
import { /* ... */, AIEditorIntegration } from 'ckeditor5-premium-features';

ClassicEditor
    .create( document.querySelector( '#editor' ), {
        licenseKey: '<YOUR_LICENSE_KEY>',
        plugins: [ AIEditorIntegration, /* ... */ ],

        // Enable the `'toggleAi'` button in the main editor toolbar.
        toolbar: [ 'toggleAi', /* ... */ ],

        ai: {
            container: {
                // ...
            },

            /* ... */
        }
    } )
    .then( /* ... */ )
    .catch( /* ... */ );
Copy code

If you wish to initially hide the overlay until a user opens it with a button, you can use the dedicated configuration.

Note

When the AIEditorIntegration plugin is enabled, the 'toggleAi' button gets displayed automatically in the menu bar. To remove this button, please refer to the menu bar configuration guide.

Hiding the UI on initialization

Copy link

By default, the AI interface will be visible when editor is created (and the related toolbar button will be active). If you wish to have it hidden until the user opens it (e.g. via toolbar button), set config.ai.container.visibleByDefault property to false.

Maximizing the UI

Copy link

The maximize button Maximize in the upper-right corner allows changing the width of the CKEditor AI user interface. Users can use this button to interact with the AI features more comfortably, especially while chatting and interacting with large chunks of content.

Clicking this button will toggle the .ck-ai-tabs_maximized CSS class on the .ck-ai-tabs DOM element. The integrator can then style the geometry of the element based on the specific requirements of the integration.

  • When the UI is configured in the sidebar mode, the decision on how to style the maximized state of the user interface is left to the integrator due to many possible integration types and configurations.
  • When the UI is configured in the overlay mode, integrators can override the --ck-ai-tabs-overlay-width-maximized CSS custom property to change the width of the overlay.
:root {
    /* The CKEditor AI interface will consume 40% of the space when maximized */
    --ck-ai-tabs-overlay-width-maximized: 40%;
}
Copy code

Permissions

Copy link

Learn more about the permissions system used in CKEditor AI in a dedicated guide.

Chat

Copy link

Learn more about integrating the Chat feature Chat in a dedicated guide.

Quick Actions

Copy link

Learn more about integrating the Quick Actions feature Quick Actions in a dedicated guide.

Review

Copy link

Learn more about integrating the Review feature Review in a dedicated guide.