---
title: "Register a custom command and prompt"
description: "Create custom AI commands with tailored prompts by extending the AI Generation extension for specialized content transformation workflows."
canonical_url: "https://tiptap.dev/docs/content-ai/capabilities/generation/text-generation/custom-commands"
---

# Register a custom command and prompt

Create custom AI commands with tailored prompts by extending the AI Generation extension for specialized content transformation workflows.

- **1. Activate trial or subscribe**

  Start a [free trial](https://cloud.tiptap.dev/v2?trial=true) or [subscribe to the Start plan](https://cloud.tiptap.dev/v2/billing) in your account.
- **2. Integrate an AI provider**

  Configure OpenAI in your [AI settings](https://cloud.tiptap.dev/v2/cloud/ai) or review the [Custom LLM guides](https://tiptap.dev/docs/content-ai/capabilities/generation/custom-llms.md).
- **3. Install from private registry**

  To install the frontend extensions, authenticate to Tiptap’s private npm registry by following the [setup guide](https://tiptap.dev/docs/guides/pro-extensions.md).

The AI Generation extension provides a list of [built-in commands](https://tiptap.dev/docs/content-ai/capabilities/generation/text-generation/built-in-commands.md), but you can extend it to define your own. These custom commands can be used to call the LLM with your custom prompt.

> **Interactive demo:** [AiCustomCommandUsingAiTextPrompt](https://embed-pro.tiptap.dev/preview/Extensions/AiCustomCommandUsingAiTextPrompt)

## Register a custom command

To register your own AI commands, simply extend the AI Generation extension, add your command in `addCommands()` (don't forget to inherit the predefined commands in `this.parent?.()`), and execute `aiTextPrompt()` to run your individual prompt.

Please note that this example uses your prompt on the client-side, which means that users could read it. If you're looking to use a custom Language Model (LLM) or a prompt on your backend, please refer to the [custom LLM guide](https://tiptap.dev/docs/content-ai/capabilities/generation/custom-llms.md).

```js
import { Ai, getHTMLContentBetween } from '@tiptap-pro/extension-ai'

// … other imports

// Declare extension types if TypeScript is used.
// More info: https://tiptap.dev/docs/guides/typescript
//
// declare module '@tiptap/core' {
//   interface Commands<ReturnType> {
//     ai: {
//       aiCustomTextCommand: (options?: TextOptions) => ReturnType,
//     }
//   }
// }

const AiExtended = Ai.extend({
  addCommands() {
    return {
      ...this.parent?.(),

      aiCustomTextCommand:
        (options = {}) =>
        ({ editor, state }) => {
          const { from, to } = state.selection
          const selectedText = getHTMLContentBetween(editor, from, to)

          return editor.commands.aiTextPrompt({
            text: `Translate the following text to French and add some emojis: ${selectedText}`,
            ...options,
          })
        },
    }
  },
})

// Initialize your Tiptap editor instance and register the extended extension

const editor = new Editor({
  extensions: [
    StarterKit,
    AiExtended.configure({
      /* … */
    }),
  ],
  content: '',
})

// Run your custom command
// editor.chain().focus().aiCustomTextCommand().run()
```
