{"id":15074,"library":"@anthropic-ai/sdk","title":"Anthropic: Official Node.js SDK","description":"The official TypeScript and Node.js SDK for the Anthropic API, providing seamless access to the Claude model family, including Claude 3.5 Sonnet, Haiku, and the Claude Opus 4.6 series. The SDK features a unified architecture, native streaming, structured data handling, and full support for advanced features like Prompt Caching, Tool Use (Function Calling), Computer Use, and the Model Context Protocol (MCP). It is optimized for server-side JavaScript runtimes (Node.js, Deno, Bun, Cloudflare Workers). It acts as the standard method for interacting with Anthropic's APIs, abstracting raw HTTP calls while providing robust type definitions and automatic retries.","status":"active","version":"0.90.0","language":"javascript","source_language":"typescript","source_url":"[https://github.com/anthropics/anthropic-sdk-typescript](https://github.com/anthropics/anthropic-sdk-typescript)","tags":["javascript","ai","llm","anthropic","claude","claude-3","claude-4","mcp","typescript"],"install":[{"cmd":"npm install @anthropic-ai/sdk","lang":"bash","label":"npm"},{"cmd":"yarn add @anthropic-ai/sdk","lang":"bash","label":"yarn"},{"cmd":"pnpm add @anthropic-ai/sdk","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The SDK exports the Anthropic client as a default export. Destructuring or using non-existent named exports like AnthropicApi will fail in ESM environments.","wrong":"import { Anthropic } from '@anthropic-ai/sdk';\nconst anthropic = new AnthropicApi();","symbol":"Anthropic","correct":"import Anthropic from '@anthropic-ai/sdk';\nconst anthropic = new Anthropic();"},{"note":"If you are using Anthropic models through AWS Bedrock or Google Cloud Vertex AI, you must install and import from their specific companion packages (@anthropic-ai/bedrock-sdk or @anthropic-ai/vertex-sdk), not the standard @anthropic-ai/sdk package.","wrong":"import { AnthropicBedrock } from '@anthropic-ai/sdk';","symbol":"AWS Bedrock / Google Vertex AI","correct":"import { AnthropicBedrock } from '@anthropic-ai/bedrock-sdk';\nimport { AnthropicVertex } from '@anthropic-ai/vertex-sdk';"},{"note":"Anthropic strictly namespaces its types under the default export object. It is highly recommended to use the namespace pattern (Anthropic.MessageParam) rather than attempting to destructure type definitions directly from the root.","wrong":"import { MessageParam } from '@anthropic-ai/sdk';","symbol":"MessageParam","correct":"import Anthropic from '@anthropic-ai/sdk';\nconst msg: Anthropic.MessageParam = { role: 'user', content: '...' };"}],"quickstart":{"code":"import Anthropic from '@anthropic-ai/sdk';\n\nconst anthropic = new Anthropic({\n  apiKey: process.env.ANTHROPIC_API_KEY,\n});\n\nasync function main() {\n  const message = await anthropic.messages.create({\n    model: 'claude-opus-4-6',\n    max_tokens: 1024,\n    system: 'You are a helpful and concise assistant.',\n    messages: [{ role: 'user', content: 'Explain quantum computing in one sentence.' }],\n  });\n  console.log(message.content[0].type === 'text' ? message.content[0].text : 'Non-text response');\n}\n\nmain();","lang":"typescript","description":"A basic Messages API request using the claude-opus-4-6 model, illustrating the required max_tokens parameter and the correct placement of the system prompt."},"warnings":[{"fix":"Update model strings in your code to explicitly point to supported versioned model strings (e.g., `claude-opus-4-6`).","message":"Version 0.89.0 marks standard Sonnet 4 and Opus 4 strings as deprecated in favor of more specific point-releases like `claude-opus-4-6` and `claude-opus-4-7`. Ensure your model strings match the currently supported availability list.","severity":"breaking","affected_versions":">=0.89.0"},{"fix":"Extract the system instructions and assign them directly to the `system` property at the root of the `create()` method configuration object.","message":"The `system` prompt is a top-level parameter in the Messages API, not a message role. If migrating from OpenAI, do not include `{ role: 'system', content: '...' }` inside the messages array, as this will trigger a validation error.","severity":"gotcha","affected_versions":"All"},{"fix":"Pass `dangerouslyAllowBrowser: true` to the constructor ONLY if you are absolutely sure about the security implications or are securely proxying requests.","message":"Attempting to use the SDK in a browser environment will intentionally throw an error by default to prevent leaking API keys to the client side.","severity":"gotcha","affected_versions":"All"}],"env_vars":["ANTHROPIC_API_KEY","ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"],"search_vec":"'-3':110 '-4':112 '3.5':25 '4.6':32 'abstract':92 'access':17 'act':81 'advanc':49 'ai':105 'anthrop':1,13,89,107 'api':14,91 'architectur':39 'automat':102 'bun':77 'cach':53 'call':57,95 'claud':20,24,30,108,109,111 'cloudflar':78 'comput':58 'context':63 'data':43 'definit':100 'deno':76 'famili':22 'featur':36,50 'full':46 'function':56 'haiku':27 'handl':44 'http':94 'includ':23 'interact':87 'javascript':73,104 'like':51 'llm':106 'mcp':65,113 'method':85 'model':21,62 'nativ':40 'node.js':3,9,75 'offici':2,6 'optim':68 'opus':31 'prompt':52 'protocol':64 'provid':15,97 'raw':93 'retri':103 'robust':98 'runtim':74 'sdk':4,10,35 'seamless':16 'seri':33 'server':71 'server-sid':70 'side':72 'sonnet':26 'standard':84 'stream':41 'structur':42 'support':47 'tool':54 'type':99 'typescript':7,114 'unifi':38 'use':55,59 'worker':79","created_at":"2026-04-20T18:54:12.864066+00:00","updated_at":"2026-04-20T18:54:12.864066+00:00","problems":[{"fix":"Add the `max_tokens` parameter to your request body, ensuring it is an integer up to the model's maximum output limit (e.g., `max_tokens: 4096`).","cause":"Unlike OpenAI, which often defaults to infinity or a specific model limit, the Anthropic Messages API strictly requires the developer to explicitly define the maximum number of tokens to generate for every request.","error":"400 Bad Request: max_tokens: required field"},{"fix":"Combine sequential 'user' messages into a single message object, or ensure your messages array strictly alternates the sequence: `user -> assistant -> user`.","cause":"Anthropic's Messages API enforces strict conversational turn-taking. You cannot send two 'user' messages sequentially, start a conversation with an 'assistant' message, or leave trailing 'assistant' messages without specific pre-fill techniques.","error":"400 Bad Request: roles must alternate between 'user' and 'assistant'"},{"fix":"Move the API call to a backend Node.js server or a serverless API route. If you must run it in the client for testing, instantiate the client with `new Anthropic({ dangerouslyAllowBrowser: true })`.","cause":"The SDK detected a browser environment (like React, Vue, or Next.js client-components). Anthropic blocks this to prevent developers from accidentally exposing their secret `ANTHROPIC_API_KEY` in client-side JavaScript bundles.","error":"Error: It looks like you're running in a browser-like environment. This is disabled by default"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":"https://www.anthropic.com","github":"https://github.com/anthropics/anthropic-sdk-typescript","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/@anthropic-ai/sdk","openapi_spec":null,"status_page":null,"smithery":null,"categories":["llm-agents","ai-ml","http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-04-21","next_check":"2026-07-20","install_tag":null}}