Install and configure
npm install @anthropic-ai/sdkimport Anthropic from "@anthropic-ai/sdk";
const anthropic = new Anthropic({
baseURL: "https://devsaio.lol",
apiKey: process.env.DEVSAIO_API_KEY,
});Send a message
const msg = await anthropic.messages.create({
model: "claude-sonnet-4-6",
max_tokens: 800,
system: "Answer in plain English for non-technical readers.",
messages: [{ role: "user", content: "What is two-factor authentication?" }],
});
for (const block of msg.content) if (block.type === "text") console.log(block.text);
console.log(msg.usage);Stream
const stream = anthropic.messages.stream({
model: "claude-sonnet-4-6",
max_tokens: 1024,
messages: [{ role: "user", content: "Draft a friendly welcome email." }],
});
stream.on("text", (t) => process.stdout.write(t));
const final = await stream.finalMessage();
console.log("\nTokens:", final.usage);When to use this vs the OpenAI SDK
Use the Anthropic SDK when your app only uses Claude and you want Claude-specific response details. Use the OpenAI SDK if you want one code path for every lab.
Claude, GPT, Gemini, DeepSeek, image and video models through one OpenAI- and Anthropic-compatible endpoint. Prepaid, pay only for what you use.