← Blog

Claude API SDK for Node.js: Setup & Usage Guide

2026-10-15 · 5 min read · SubToAPI Team

Claude API SDK for Node.js: What You Actually Need

If you're searching for "Claude API SDK for Node.js," you're probably trying to do one of two things: call Anthropic's official @anthropic-ai/sdk package from a Node or TypeScript backend, or find a simpler way to get Claude into your app without juggling SDK versions, Anthropic account billing, and separate API keys for every teammate. Both paths are covered below.

The short answer: Anthropic publishes an official Node.js SDK that wraps their REST API with typed methods for messages, streaming, and tool use. It's solid, actively maintained, and the right choice if you already have an Anthropic developer account with billing set up. If you want the same Claude capabilities without managing a separate Anthropic account — for example, because you already pay for Claude as an individual or team subscriber — a service like SubToAPI gives you an HTTPS API with its own SDK-compatible endpoints, application keys, and usage dashboards, built on top of your existing Claude access.

Installing and Using the Official SDK

Start with the package:

npm install @anthropic-ai/sdk

Basic usage in a Node script or server route:

import Anthropic from '@anthropic-ai/sdk';

const anthropic = new Anthropic({
  apiKey: process.env.ANTHROPIC_API_KEY,
});

const message = await anthropic.messages.create({
  model: 'claude-3-5-sonnet-20241022',
  max_tokens: 1024,
  messages: [
    { role: 'user', content: 'Explain event loops in Node.js in two sentences.' },
  ],
});

console.log(message.content[0].text);

This covers the core use case: one request, one response, synchronous-feeling call. The SDK handles retries, typed responses, and error classes out of the box.

Streaming Responses

For chat UIs or long completions, streaming avoids making users stare at a blank screen:

const stream = anthropic.messages.stream({
  model: 'claude-3-5-sonnet-20241022',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'Write a short product changelog entry.' }],
});

for await (const event of stream) {
  if (event.type === 'content_block_delta') {
    process.stdout.write(event.delta.text);
  }
}

This pattern maps directly to server-sent events if you're piping it to a frontend — most Node frameworks (Express, Fastify, Next.js route handlers) can forward this stream with minimal glue code.

Tool Use (Function Calling)

Claude's tool use lets the model call functions you define, which is essential for anything beyond plain text generation:

const response = await anthropic.messages.create({
  model: 'claude-3-5-sonnet-20241022',
  max_tokens: 1024,
  tools: [
    {
      name: 'get_weather',
      description: 'Get current weather for a city',
      input_schema: {
        type: 'object',
        properties: { city: { type: 'string' } },
        required: ['city'],
      },
    },
  ],
  messages: [{ role: 'user', content: 'What is the weather in Lisbon?' }],
});

You then parse response.content for a tool_use block, run your actual function, and send the result back in a follow-up message with role tool_result. The SDK's typed objects make this loop manageable, but you still have to write the state machine yourself.

Where the Official SDK Gets Complicated

The SDK itself is fine. The friction usually shows up around it:

If you just need to call Claude from one script, none of this matters. If you're building a product — an internal tool, a SaaS feature, a team of developers hitting Claude from different services — these gaps add real engineering time.

Using SubToAPI as a Node.js-Compatible Alternative

SubToAPI turns your existing Claude access into a straightforward HTTPS API with application keys (sub_live_...), so you don't need to stand up a separate Anthropic billing account just to let your Node app call Claude. Requests look the same as a typical REST call:

const res = await fetch('https://api.subtoapi.app/v1/messages', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.SUBTOAPI_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    model: 'claude-3-5-sonnet-20241022',
    max_tokens: 1024,
    messages: [{ role: 'user', content: 'Summarize this changelog in one line.' }],
  }),
});

const data = await res.json();
console.log(data.content[0].text);

Because it's plain HTTPS, it works fine with fetch, axios, or the Anthropic SDK's HTTP client pattern — you don't need a special package, just point your requests at the SubToAPI endpoint and use your sub_live_ key.

What you get on top of raw API access:

Plans start at €9/month for solo developers, €19/seat for teams, and €49/seat for scale usage, with a free trial at signup — see /pricing. If you're evaluating this path, the /docs/quickstart and /docs/messages pages walk through the first request end to end, and /signup gets you a key in a couple of minutes.

Which Approach to Pick

Use the official @anthropic-ai/sdk directly if you're a solo developer prototyping, you already have Anthropic billing sorted, or you need SDK-level typings tightly coupled to Anthropic's release cadence.

Reach for SubToAPI if you want to skip separate Anthropic billing, need per-app or per-teammate keys without building that layer yourself, or want usage visibility and streaming/tool support ready out of the box on top of Claude access you already have.

Questions

Does Anthropic have an official Node.js SDK? Yes — @anthropic-ai/sdk on npm, maintained by Anthropic, with TypeScript types and support for messages, streaming, and tool use.

Can I use Claude in Node.js without an Anthropic developer account? Yes, if you use a service like SubToAPI, which exposes Claude through a standard HTTPS API using your existing Claude access, authenticated with its own application keys instead of a separate Anthropic billing setup.

Is streaming supported in Node.js for Claude responses? Yes, both the official SDK and SubToAPI support streaming responses, which you can pipe into server-sent events or WebSocket connections for live chat UIs — see /docs/streaming for the request format.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →