OpenAI - AI agent tools

The @tiptap-pro/ai-toolkit-openai package provides tool definitions you can add to your AI agent built with OpenAI's JavaScript SDK.

The tool calls generated by the model can then be executed in the client-side using the executeTool method.

Example usage

Install the package.

npm install @tiptap-pro/ai-toolkit-openai

Supply the tool definitions to your OpenAI model.

import OpenAI from 'openai'
import { toolDefinitions } from '@tiptap-pro/ai-toolkit-openai'

const openai = new OpenAI()

const response = await openai.responses.create({
  model: 'gpt-5',
  input: [{ role: 'user', content: 'Help me edit this document' }],
  tools: toolDefinitions(),
})

Combine the tool definitions with your custom tools.

import OpenAI from 'openai'
import { toolDefinitions } from '@tiptap-pro/ai-toolkit-openai'

const openai = new OpenAI()

const customTools = [
  {
    type: 'function',
    name: 'get_weather',
    description: 'Get the weather in a location',
    parameters: {
      type: 'object',
      properties: {
        location: {
          type: 'string',
          description: 'The city and state, e.g. San Francisco, CA',
        },
      },
      required: ['location'],
    },
  },
]

const response = await openai.responses.create({
  model: 'gpt-5',
  input: [{ role: 'user', content: 'What is the weather like and help me edit this document' }],
  tools: [...toolDefinitions(), ...customTools],
})

API reference

toolDefinitions

Creates tool definitions for the Tiptap AI Toolkit compatible with OpenAI's responses API.

Parameters (ToolDefinitionsOptions)

  • tools?: EnabledTools - Enable/disable specific tools by setting the value to true (enabled) or false (disabled).
    • insertContent?: boolean - Enable/disable the insertContent tool (default: true)
    • applyPatch?: boolean - Enable/disable the applyPatch tool (default: true)
    • readNodeRange?: boolean - Enable/disable the readNodeRange tool (default: true)
    • readSelection?: boolean - Enable/disable the readSelection tool (default: true)
    • getThreads?: boolean - Enable/disable the getThreads tool (default: false)
    • editThreads?: boolean - Enable/disable the editThreads tool (default: false)

Returns

An array containing the enabled tool definitions that can be used with OpenAI's responses API. The returned array includes:

  • insertContent - Tool for inserting HTML content at a specific position
  • applyPatch - Tool for making small precise edits to the document
  • readNodeRange - Tool for reading part of the document by specifying a range of top-level nodes
  • readSelection - Tool for reading the currently selected content in the editor
  • getThreads - Tool for retrieving all threads and comments in the document (requires Comments extension)
  • editThreads - Tool for performing operations on threads and comments (requires Comments extension)

completionsApiToolDefinitions

Creates tool definitions for the Tiptap AI Toolkit compatible with OpenAI's completions API.

Parameters (ToolDefinitionsOptions)

  • tools?: EnabledTools - Enable/disable specific tools. All tools are enabled by default.
    • insertContent?: boolean - Enable/disable the insertContent tool (default: true)
    • applyPatch?: boolean - Enable/disable the applyPatch tool (default: true)
    • readNodeRange?: boolean - Enable/disable the readNodeRange tool (default: true)
    • readSelection?: boolean - Enable/disable the readSelection tool (default: true)
    • getThreads?: boolean - Enable/disable the getThreads tool (default: false)
    • editThreads?: boolean - Enable/disable the editThreads tool (default: false)

Returns

An array containing the enabled tool definitions that can be used with OpenAI's completions API. The returned array includes:

  • insertContent - Tool for inserting HTML content at a specific position
  • applyPatch - Tool for making small precise edits to the document
  • readNodeRange - Tool for reading part of the document by specifying a range of top-level nodes
  • readSelection - Tool for reading the currently selected content in the editor
  • getThreads - Tool for retrieving all threads and comments in the document (requires Comments extension)
  • editThreads - Tool for performing operations on threads and comments (requires Comments extension)