Integrating CKEditor AI with your application
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.
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( /* ... */ );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.
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.
Read more about installing plugins and toolbar configuration.
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( /* ... */ );
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' |
Learn more about model capabilities such as Web Search and Reasoning.
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.
You can verify which models are compatible with your service version using a dedicated API. Learn more.
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( /* ... */ );
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.
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.
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.
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:
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( /* ... */ );
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;
}
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( /* ... */ );
Learn how to toggle the AI overlay using a dedicated toolbar button.
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( /* ... */ );
The user interface can be easily toggled by the users using the 'toggleAi' 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( /* ... */ );
If you wish to initially hide the overlay until a user opens it with a button, you can use the dedicated configuration.
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.
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.
The maximize button 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-maximizedCSS 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%;
}
Learn more about the permissions system used in CKEditor AI in a dedicated guide.
Learn more about integrating the Chat feature in a dedicated guide.
Learn more about integrating the Quick Actions feature in a dedicated guide.
Learn more about integrating the Review feature in a dedicated guide.