Script integration with Anthropic's AI API, including support for conversing with its Claude models. This object offers convenience over direct HTTP requests by:

  • Integrating with Drafts Credentials system to store your API key.
  • Handling request authorization headers for requests
  • Parsing results to JSON
  • Providing several convenience functions that wrap more complex API calls into simple requests.

NOTE: Drafts does not provide an API Key for use with Anthropic. To use Anthropic AI features, you will have to setup your own API Key for use with Drafts in the Anthropic Console.

Example

Translation

// build prompt
const targetLanguage = "Spanish"
const text = "Where is the library?"
const chatPrompt = `Translate the following text into ${targetLanguage}: "${text}"`

// create API object and use single response
// convenience function to send prompt
let ai = new AnthropicAI()
let answer = ai.quickPrompt(chatPrompt)

// answer == "¿Dónde está la biblioteca?"

Hierarchy

  • AnthropicAI

Convenience

  • Submit a single text prompt to Anthropic AI, and return only the message generated. Convenience method for single request prompts to the messages endpoint.

    Parameters

    • prompt: string

      Text prompt to submit

    • Optional options: object

    Returns string

Options

credentialIdentifier?: string

Optional identifier for API Key credentials. If an API Key is not provided as a parameter when instantiating the object, the user will be prompted to enter one of the first time they run an action requiring it. By default, these will be stored as Anthropic AI credentials.

Other

  • Create new instance.

    Parameters

    • Optional apiKey: string

    Returns AnthropicAI

timeout: number

Time in seconds to wait for a request to receive a response from the server. Default: 120 seconds.

  • Execute a request against the Anthropic AI API. For successful requests, the HTTPResponse object will contain an object or array or objects decoded from the JSON returned by the API as appropriate to the request made. Refer to Anthropic API documentation for details about the expected parameters and responses.

    Parameters

    • settings: {
          data?: {
              [x: string]: string;
          };
          headers?: {
              [x: string]: string;
          };
          method: string;
          parameters?: {
              [x: string]: string;
          };
          path: string;
      }
      • Optional data?: {
            [x: string]: string;
        }

        An object containing data to be encoded into the HTTP body of the request. Drafts will take care of the JSON conversion.

        • [x: string]: string
      • Optional headers?: {
            [x: string]: string;
        }

        An object contain key-values to be added as custom headers in the request. There is no need to provide authorization headers, Drafts will add those.

        • [x: string]: string
      • method: string

        The HTTP method, like "GET", "POST", etc.

      • Optional parameters?: {
            [x: string]: string;
        }

        An object containing key-values to be added to the request as URL parameters. Drafts will take care of encoding these.

        • [x: string]: string
      • path: string

        The path to the API endpoint in the Anthropic API.

    Returns HTTPResponse

  • Creates a new AnthropicAI object.

    Parameters

    • Optional apiKey: string

      A valid Anthropic API Key. This value is optional, and if not provided, the default Anthropic AI API key stored in Credentials will be used, or the user prompted to provide an API Key to store. Only provide a specific API Key if you desire to override the default.

    Returns OpenAI

  • Returns a list of current known model versions. Anthropic does not provide an API endpoint to request available models, so this list will be updated periodically with known models for the API. The list currently returns the current Clause Haiku, Sonnet, and Open model versions. If you are using these values to pass a model name to other functions, in general, the first model in this array will be the fastest, the last the most sophisticated. The only purpose of this function over statically defining model names in your actions is that it may be updated overtime if Anthropic releases updated model versions.

    Returns [string]

Generated using TypeDoc