---
title: "Get started with the Anthropic Claude Messages API"
description: "Learn how to use the AI Agent extension with the Anthropic Claude Messages API."
canonical_url: "https://tiptap.dev/docs/content-ai/capabilities/agent/custom-llms/get-started/anthropic-messages"
---

# Get started with the Anthropic Claude Messages API

Learn how to use the AI Agent extension with the Anthropic Claude Messages API.

The [Anthropic Claude Messages API](https://docs.anthropic.com/) allows you to build an AI agent with Anthropic's models.

> **Code demo available:**
>
> This guide includes a code demo to help you get started. See the [GitHub
> repository](https://github.com/ueberdosis/ai-agent-custom-llm-demos).

## Client-side setup

First, install the AI Agent extension.

```bash
npm install @tiptap-pro/extension-ai-agent
```

Then, import the extension and configure it with the `AiAgentProvider` class.

```tsx
import { Editor } from '@tiptap/core'
import StarterKit from '@tiptap/starter-kit'
import AiAgent, { AiAgentProvider } from '@tiptap-pro/extension-ai-agent'

const provider = new AiAgentProvider()

const editor = new Editor({
  extensions: [
    StarterKit,
    AiAgent.configure({
      provider,
    }),
  ],
})
```

Inside `AiAgentProvider`, define a `resolver` function that calls your backend.

```tsx
import AiAgent, { AiAgentProvider } from '@tiptap-pro/extension-ai-agent'

const provider = new AiAgentProvider({
  // The `chatMessages` property contains the chat messages of the conversation
  resolver: async ({ chatMessages, schemaAwarenessData }) => {
    // Call the API endpoint of your backend
    const response = await fetch('/api-endpoint', {
      method: 'POST',
      body: JSON.stringify({ chatMessages, schemaAwarenessData }),
    })
    return await response.json()
  },
})
```

In the next section, we'll see how to implement the API endpoint that returns the response in the correct format.

## Server-side setup

First, install the AI Agent extension and Anthropic server libraries.

```bash
npm install @tiptap-pro/extension-ai-agent-server @anthropic-ai/sdk
```

Get the chat messages and schema awareness data from the request parameters.

```ts
// Code inside your API endpoint. Code depends on your backend framework
const { chatMessages, schemaAwarenessData } = request
```

Then, inside your API endpoint, create an `AiAgentToolkit` instance. It lets you configure the tools that will be available to the AI model.

```ts
import { AiAgentToolkit, anthropicMessagesAdapter } from '@tiptap-pro/extension-ai-agent-server'

const toolkit = new AiAgentToolkit({
  adapter: anthropicMessagesAdapter,
  schemaAwarenessData,
})
```

Also define a `ChatMessagesFormatter` instance. It lets you convert the chat messages to the format expected by the Anthropic Claude Messages API.

```ts
import {
  AiAgentToolkit,
  anthropicMessagesAdapter,
  ChatMessagesFormatter,
} from '@tiptap-pro/extension-ai-agent-server'

const formatter = new ChatMessagesFormatter({
  initialMessages: chatMessages,
  adapter: anthropicMessagesAdapter,
})
```

After creating the toolkit and the formatter, send the request to the Anthropic Claude Messages API.

```ts
import {
  AiAgentToolkit,
  anthropicMessagesAdapter,
  ChatMessagesFormatter,
} from '@tiptap-pro/extension-ai-agent-server'
import Anthropic from '@anthropic-ai/sdk'

const { chatMessages, schemaAwarenessData } = request

const toolkit = new AiAgentToolkit({
  adapter: anthropicMessagesAdapter,
  schemaAwarenessData,
})

const formatter = new ChatMessagesFormatter({
  // Get the chat messages from the request body
  initialMessages: chatMessages,
  adapter: anthropicMessagesAdapter,
})

// Initialize the Anthropic client
const anthropic = new Anthropic()

// Call the Anthropic Claude Messages API
const response = await anthropic.messages.create({
  model: 'claude-sonnet-4-0',
  max_tokens: 2048,
  system: `
<Your system prompt>
${toolkit.getSystemPrompt()}
`,
  messages: formatter.format(),
  // Provide the tools that the AI model can call
  tools: toolkit.format(),
})
```

At the end of the system prompt, include the system prompt generated by the `AiAgentToolkit` instance, like this: `toolkit.getSystemPrompt()`. This contains instructions on how to use the tools.

To write the system prompt, see the [system prompt guide](https://tiptap.dev/docs/content-ai/capabilities/agent/configure/system-prompt.md). It includes an example system prompt that you can use as a starting point.

Finally, use the `formatter` to convert the response to the format expected by the AI Agent extension.

```ts
formatter.addAiResponse(response)

const response = formatter.getResolverResponse()
```

The value returned from `formatter.getResolverResponse()` should be the response of your API endpoint and the return value of the resolver function.
