Anthropic SDK reference

Ask the Community

Full API reference for Cord's Anthropic chatbot SDK, npm package @cord-sdk/chatbot-anthropic


Overview #

This page is a detailed reference of the Anthropic chatbot SDK. For a beginner's overview of how this all fits together, see our Getting Started document, which includes chatbot example code.

The Anthropic chatbot SDK sits on top of the base SDK. The goal of this SDK is to provide utility functions and helpers to connect Anthropic to the base SDK. In particular, the main helpers here provide a getResponse function to use when defining a Chatbot with the base SDK.

The functions exported from the package are:


anthropicCompletion #

Provides a getResponse function which connects to Anthropic's messages API and streams the response back to Cord.

What this function returns #

A function which can be used as the getResponse for a Chatbot definition in the base SDK.

Arguments this function takes #


apiKey #

required
string
An Anthropic API key. You can get this from the Anthropic console.


getAnthropicMessages #

required
(messages: CoreMessageData[], thread: CoreThreadData) => MessageParam[] | Promise<MessageParam[]> | MessageCreateParams | Promise<...>
The core of your AI logic: a function which takes a Cord thread and message (the same parameters as getResponse) and returns data suitable for sending to Anthropic. This "suitable" data can be any of the following:
  1. An array of Anthropic messages (MessageParam). In this case, a default model will be used (currently, claude-3-haiku-20240307, though this may change in the future).
  2. A full set of Anthropic MessageCreateParams, which can specify any model (or any other parameters) that you wish. The stream parameter will be forced to true since this Cord SDK supports streaming.
  3. A promise which resolves to one of the above.

anthropicSimpleAssistant #

Uses Anthropic's messages API to create a simple AI assistant. This is a simple wrapper on top of anthropicCompletion which just injects the system prompt at the top of the list of messages. It uses a default model (currently, claude-3-haiku-20240307, though this may change in the future).

What this function returns #

A function which can be used as the getResponse for a Chatbot definition in the base SDK.

Arguments this function takes #


apiKey #

required
string
An Anthropic API key. You can get this from the Anthropic console.


systemPrompt #

required
string
The system prompt to use to set the behavior of the AI.

messageToAnthropicMessage #

Converts a message from Cord's format to a one compatible with Anthropic's completion API.

What this function returns #

Message data in Anthropic's MessageParam format.

Arguments this function takes #


message #

required
CoreMessageData
Message data returned by any of Cord's message or thread APIs.

This is an object with the following fields:

Show property details


Not finding the answer you need? Ask our Developer Community

Ask Cordy