Skip to content

anthropic-api

Use when integrating Claude via the Anthropic API — messages, tool use, vision, streaming, or building AI features. Also use when working with the Anthropic SDK, managing API keys, or optimizing Claude API usage.

ModelSource
sonnetpack: ai
Full Reference

┏━ 🔧 anthropic-api ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Use when integrating Claude via the Anthropic … ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

Direct Claude API access via the @anthropic-ai/sdk package. Uses a Messages API with a structured messages array, content blocks, and optional streaming. All models share a 200K token context window (1M beta for Opus/Sonnet 4.6).

FactValue
Installnpm install @anthropic-ai/sdk
Base URLhttps://api.anthropic.com/v1
API version headeranthropic-version: 2023-06-01
Env varANTHROPIC_API_KEY
Opus 4.6 pricing$5/MTok input · $25/MTok output · 128K max output
Sonnet 4.6 pricing$3/MTok input · $15/MTok output · 64K max output
Haiku 4.5 pricing$1/MTok input · $5/MTok output · 64K max output
Prompt cachingCache write 1.25x · Cache read 0.1x (90% savings)
Batch API50% discount · 24hr processing · 100K requests/batch
I want to…File
Install the SDK and initialize the clientreference/setup.md
Send a message, configure parameters, or build multi-turn conversationsreference/messages.md
Stream responses with async iterator or SSE eventsreference/streaming.md
Define tools and run the tool use loopreference/tool-use.md
Send images or PDFs and understand format limitsreference/vision.md
Use prompt caching or the Batches API for cost savingsreference/prompt-caching.md
Enable extended thinking or Opus adaptive modereference/extended-thinking.md
Handle errors, retry with backoff, and understand rate limitsreference/error-handling.md

Usage: Read the reference file matching your current task from the index above. Each file is self-contained with code examples and inline gotchas.