anthropics / anthropic-sdk-typescript

Access to Anthropic's safety-first language model APIs

Home Page:https://www.npmjs.com/package/@anthropic-ai/sdk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

I keep getting the 'Anthropic is not a constructor' error, and the Client is not functioning properly.

FE-Lex-Kim opened this issue · comments

I have tried repeatedly, but strangely, I can't reference the Client class. So, I directly called the Client to make requests, but I received a 404 error, and it is not functioning properly. In my view, it's odd that there is no reference at all.

const Anthropic = require("@anthropic-ai/sdk");
console.log("Anthropic: ", Anthropic);

const anthropic = new Anthropic({
  apiKey: process.env["ANTHROPIC_API_KEY"], // This is the default and can be omitted
});

async function main() {
  const message = await anthropic.messages.create({
    max_tokens: 1024,
    messages: [{ role: "user", content: "Hello, Claude" }],
    model: "claude-3-opus-20240229",
  });

  console.log(message.content);
}

main();
Anthropic:  {
  HUMAN_PROMPT: '\n\nHuman:',
  AI_PROMPT: '\n\nAssistant:',
  Client: [class Client]
}
/Users/eojin-kim/dev/tistory-auto-posting/src/api/js.js:4
const anthropic = new Anthropic({
                  ^

TypeError: Anthropic is not a constructor
    at Object.<anonymous> (/Users/eojin-kim/dev/tistory-auto-posting/src/api/js.js:4:19)
    at Module._compile (node:internal/modules/cjs/loader:1369:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
    at Module.load (node:internal/modules/cjs/loader:1206:32)
    at Module._load (node:internal/modules/cjs/loader:1022:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49

Node.js v20.12.2

This has been fixed; please update to the latest SDK version.