npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@llm-ports/adapter-anthropic

v0.1.0-alpha.18

Published

Direct @anthropic-ai/sdk adapter for llm-ports. Implements LLMPort with prompt caching, vision, and tool use support for Claude models.

Readme

@llm-ports/adapter-anthropic

Direct @anthropic-ai/sdk adapter for llm-ports. Implements LLMPort for Claude models with prompt caching, vision, and tool use.

Install

pnpm add @llm-ports/core @llm-ports/adapter-anthropic @anthropic-ai/sdk zod

Configure

import { createRegistryFromEnv } from "@llm-ports/core";
import { createAnthropicAdapter } from "@llm-ports/adapter-anthropic";

const registry = createRegistryFromEnv({
  adapters: {
    anthropic: createAnthropicAdapter({
      apiKey: process.env.ANTHROPIC_API_KEY!,
    }),
  },
});

const llm = registry.getPort();

const result = await llm.generateText({
  taskType: "triage",
  prompt: "Classify this email: ...",
});

.env:

LLM_PROVIDER_FAST=anthropic|claude-haiku-4-5|cost:5/day
LLM_PROVIDER_SMART=anthropic|claude-sonnet-4-6-20250514|cost:50/day
LLM_TASK_ROUTE_TRIAGE=fast,smart

Adapter options

interface AnthropicAdapterOptions {
  apiKey: string;
  baseURL?: string;                            // typically only useful for testing
  fetch?: typeof fetch;                        // inject custom fetch (tests, proxies)
  validationStrategy?: ValidationStrategy;
  pricingOverrides?: Record<string, ModelPricing>;
  imageSizeLimitBytes?: number;                // default 5 MB (Anthropic's per-image limit)
  dangerouslyAllowBrowser?: boolean;           // opt in to browser execution (alpha.9)
  onRetry?: OnRetry;                           // observability hook for retries
}

dangerouslyAllowBrowser (alpha.9+)

The Anthropic SDK refuses to construct in a browser environment unless dangerouslyAllowBrowser: true is passed explicitly. When enabled, the SDK auto-adds the anthropic-dangerous-direct-browser-access header on every request. Set this option only when the API key is NOT a long-lived secret: short-lived proxy tokens, BYO-key UIs where the end user supplies their own key, or trusted internal tools running behind auth. For server-side proxy patterns where the secret stays on the server, leave it unset.

const adapter = createAnthropicAdapter({
  apiKey: ephemeralUserKey,
  dangerouslyAllowBrowser: true,
});

Bundled pricing

The bundled ANTHROPIC_PRICING table covers Claude Opus 4.5, Sonnet 4.5/4.6, Haiku 4.5 with full cache-read / cache-write rates. Override per model via pricingOverrides.

Supported features

| Feature | Status | |---------|--------| | generateText | ✓ | | generateStructured (Zod schemas) | ✓ with retry-with-feedback (default) | | streamText | ✓ (yields text chunks) | | streamStructured (partial JSON) | ✓ (best-effort partial parse) | | runAgent (multi-turn tool use) | ✓ | | Prompt caching | ✓ — reported in cost via cacheReadTokens / cacheWriteTokens | | Vision input — base64 images | ✓ | | Vision input — URL images | ✓ | | Audio input | ✗ — throws ContentBlockUnsupportedError | | Embeddings | ✗ — Anthropic ships no embedding models | | AbortSignal cancellation | ✓ entry + in-flight (alpha.6) |

Content blocks supported

text, image (base64 + URL), tool_use, tool_result. Throws ContentBlockUnsupportedError for audio.

Cancellation

Full AbortSignal support shipped in 0.1.0-alpha.6. The signal is threaded into both client.messages.create (non-streaming) and client.messages.stream, so controller.abort() cancels the in-flight HTTP request. runAgent also re-checks the signal between steps so cancellation propagates mid-loop. See the Cancellation guide.

Temperature handling on reasoning models

Claude 4.5+ reasoning models (claude-opus-4-5*, claude-sonnet-4-5*) reject custom temperature values. The adapter learns this constraint at runtime (or via the static KNOWN_TEMPERATURE_REJECTORS catalog) and strips the parameter automatically. The onRetry hook fires once with reason: "capability-fallback" + capability: "temperatureLocked". See docs/known-quirks.md for the full catalog.

SDK version compatibility

The adapter is tested against @anthropic-ai/sdk 0.32.0 ≤ v < 0.50.0. If your installed SDK is outside that range, a one-time console.warn fires at adapter creation with guidance.

Reading next