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

anthropic-llm-bridge

v0.0.3

Published

Universal Anthropic Claude LLM Bridge - supports all Claude models

Downloads

6

Readme

Anthropic LLM Bridge

Universal Anthropic Claude LLM Bridge supporting all Claude models (Opus 4.1, Sonnet 4, Sonnet 3.7, Haiku 3.5) with a unified interface.

🚀 Features

  • Universal Claude Support: Single package supporting all Claude models
  • Latest API Integration: Built with Anthropic SDK v0.30+
  • Type Safety: Full TypeScript support with comprehensive type definitions
  • Streaming Support: Native streaming API support
  • Tool Calling: Support for Anthropic tool calling capabilities
  • Long Context: 1M token context window support (Sonnet 4)
  • Extended Output: 128K output tokens with beta headers
  • Error Handling: Robust error handling with standardized error types
  • Flexible Configuration: Easy configuration management
  • Token Usage Tracking: Built-in token consumption monitoring

📦 Installation

# pnpm (권장)
pnpm add anthropic-llm-bridge llm-bridge-spec @anthropic-ai/sdk zod

# npm
npm install anthropic-llm-bridge llm-bridge-spec @anthropic-ai/sdk zod

# yarn
yarn add anthropic-llm-bridge llm-bridge-spec @anthropic-ai/sdk zod

🎯 Quick Start

Basic Usage

import { createAnthropicBridge } from 'anthropic-llm-bridge';

// Create bridge with API key
const bridge = createAnthropicBridge({
  apiKey: process.env.ANTHROPIC_API_KEY,
  model: 'claude-sonnet-4',
  temperature: 0.7,
  maxTokens: 8192,
});

// Simple chat
const response = await bridge.invoke({
  messages: [{ role: 'user', content: [{ type: 'text', text: 'Hello!' }] }],
});

console.log(response.content.value);

Streaming

// Streaming chat
const stream = bridge.invokeStream({
  messages: [{ role: 'user', content: [{ type: 'text', text: 'Tell me a story' }] }],
});

for await (const chunk of stream) {
  const text = chunk.content.value;
  if (text) {
    process.stdout.write(text);
  }
}

Long Context (1M tokens)

// Enable 1M context window for Sonnet 4
const bridge = createAnthropicBridge({
  apiKey: process.env.ANTHROPIC_API_KEY,
  model: 'claude-sonnet-4',
  useLongContext: true,
  useExtendedOutput: true,
});

// Process large documents
const response = await bridge.invoke({
  messages: [
    {
      role: 'user',
      content: [{ type: 'text', text: `Analyze this large codebase: ${largecodebase}` }],
    },
  ],
});

Tool Calling

const response = await bridge.invoke(
  {
    messages: [
      { role: 'user', content: [{ type: 'text', text: "What's the weather like in Seoul?" }] },
    ],
  },
  {
    tools: [
      {
        name: 'get_weather',
        description: 'Get the current weather in a given location',
        parameters: {
          type: 'object',
          properties: {
            location: { type: 'string', description: 'The city name' },
          },
          required: ['location'],
        },
      },
    ],
  }
);

// Handle tool calls
if (response.toolCalls) {
  for (const toolCall of response.toolCalls) {
    console.log(`Function: ${toolCall.name}`);
    console.log(`Arguments:`, toolCall.arguments);
  }
}

🔧 Factory Functions

Main Factory

import { createAnthropicBridge } from 'anthropic-llm-bridge';

const bridge = createAnthropicBridge({
  apiKey: process.env.ANTHROPIC_API_KEY, // Required
  model: 'claude-sonnet-4', // Required
  temperature: 0.7,
  maxTokens: 8192,
  topP: 1.0,
  useLongContext: true,
  useExtendedOutput: true,
});

Convenience Factories

import {
  createClaudeOpusBridge,
  createClaudeSonnetBridge,
  createClaudeHaikuBridge,
  createDefaultAnthropicBridge,
} from 'anthropic-llm-bridge';

// Claude Opus 4.1 with defaults (최고 성능)
const opusBridge = createClaudeOpusBridge({
  apiKey: process.env.ANTHROPIC_API_KEY,
  temperature: 0.8,
});

// Claude Sonnet 4 with defaults (균형잡힌 성능)
const sonnetBridge = createClaudeSonnetBridge({
  apiKey: process.env.ANTHROPIC_API_KEY,
  temperature: 0.7,
  useLongContext: true,
});

// Claude Haiku 3.5 with defaults (빠르고 경량)
const haikuBridge = createClaudeHaikuBridge({
  apiKey: process.env.ANTHROPIC_API_KEY,
  temperature: 0.5,
});

// Default configuration (Sonnet 4)
const defaultBridge = createDefaultAnthropicBridge({
  apiKey: process.env.ANTHROPIC_API_KEY,
  temperature: 0.5, // Override defaults
});

📋 Supported Models

Claude Opus 4.1

  • claude-opus-4.1 - Highest intelligence and capability
  • Context: 200K tokens
  • Max output: 128K tokens
  • Pricing: $15/$75 per 1M tokens

Claude Sonnet 4

  • claude-sonnet-4 - Balanced performance and speed
  • Context: 200K tokens (1M with beta header)
  • Max output: 128K tokens
  • Pricing: $3/$15 per 1M tokens ($6/$22.50 for >200K context)

Claude Sonnet 3.7

  • claude-sonnet-3.7 - Previous generation
  • Context: 200K tokens
  • Max output: 8K tokens
  • Pricing: $3/$15 per 1M tokens

Claude Haiku 3.5

  • claude-haiku-3.5 - Fast and lightweight
  • Context: 200K tokens
  • Max output: 8K tokens
  • Pricing: $0.8/$4 per 1M tokens

⚙️ Configuration

interface AnthropicConfig {
  apiKey: string; // Anthropic API key (required)
  model: string; // Model name (required)
  temperature?: number; // 0.0 - 1.0
  maxTokens?: number; // Maximum tokens to generate
  topP?: number; // 0.0 - 1.0
  stopSequences?: string[]; // Stop sequences
  useLongContext?: boolean; // Enable 1M context for Sonnet 4
  useExtendedOutput?: boolean; // Enable 128K output tokens
  baseURL?: string; // Custom API base URL
  timeout?: number; // Request timeout
  maxRetries?: number; // Max retry attempts
}

🎭 Model Capabilities

// Get model capabilities
const metadata = await bridge.getMetadata();

console.log(metadata);
// {
//   name: 'Anthropic Claude Sonnet',
//   version: '4',
//   description: 'Anthropic Claude Sonnet Bridge Implementation',
//   model: 'claude-sonnet-4',
//   contextWindow: 200000,
//   maxTokens: 128000
// }

// Check specific capabilities
const manifest = bridge.getManifest();
console.log(manifest.capabilities.supportsToolCall); // true
console.log(manifest.capabilities.supportsStreaming); // true
console.log(manifest.capabilities.supportsVision); // false

💰 Token Usage Monitoring

const response = await bridge.invoke(prompt);

// Monitor token usage
if (response.usage) {
  console.log('Prompt tokens:', response.usage.promptTokens);
  console.log('Completion tokens:', response.usage.completionTokens);
  console.log('Total tokens:', response.usage.totalTokens);

  // Calculate cost for Sonnet 4
  const promptCost = (response.usage.promptTokens * 3.0) / 1000000; // $3 per 1M tokens
  const completionCost = (response.usage.completionTokens * 15.0) / 1000000; // $15 per 1M tokens
  console.log(`Approximate cost: $${(promptCost + completionCost).toFixed(6)}`);
}

🧪 Testing

# Run unit tests
pnpm test

# Run tests with coverage
pnpm test:coverage

# Run in watch mode
pnpm test:watch

# Run specific test
pnpm test anthropic-bridge.test.ts

🏗️ Architecture

anthropic-llm-bridge/
├── src/
│   ├── bridge/
│   │   ├── anthropic-bridge.ts       # Main bridge implementation
│   │   ├── anthropic-config.ts       # Configuration management
│   │   ├── anthropic-factory.ts      # Factory functions
│   │   ├── anthropic-manifest.ts     # Manifest definition
│   │   └── anthropic-models.ts       # Model definitions
│   ├── __tests__/
│   │   └── anthropic-bridge.test.ts  # Unit tests
│   └── index.ts                      # Entry point
├── package.json
└── README.md

🔗 Related Packages

📊 Performance Considerations

Model Selection

// For complex reasoning tasks
const opusBridge = createClaudeOpusBridge({
  apiKey: process.env.ANTHROPIC_API_KEY,
});

// For balanced performance
const sonnetBridge = createClaudeSonnetBridge({
  apiKey: process.env.ANTHROPIC_API_KEY,
  useLongContext: true, // Enable 1M context
});

// For quick responses
const haikuBridge = createClaudeHaikuBridge({
  apiKey: process.env.ANTHROPIC_API_KEY,
});

Context Window Optimization

// Use long context for large documents
const bridge = createAnthropicBridge({
  apiKey: process.env.ANTHROPIC_API_KEY,
  model: 'claude-sonnet-4',
  useLongContext: true, // 1M context window
  useExtendedOutput: true, // 128K output
});

🤝 기여하기

이 프로젝트는 Git Workflow Guide를 따릅니다.

  1. Issues: 새로운 기능이나 버그 리포트를 GitHub Issues에 등록
  2. 브랜치 생성: git checkout -b feature/anthropic-new-feature
  3. TODO 기반 개발: 각 작업을 TODO 단위로 커밋
  4. 품질 체크: 커밋 전 반드시 확인
    pnpm lint && pnpm test:ci && pnpm build
  5. PR 생성: GitHub에서 Pull Request 생성
  6. 코드 리뷰: 승인 후 Squash Merge

📄 라이선스

이 프로젝트는 MIT 라이선스 하에 있습니다.

🙏 Acknowledgments


Made with ❤️ by the LLM Bridge Team