Skip to content
reaatechREAATECH

@reaatech/llm-judge-providers

npm v0.1.0

Provides a unified interface and factory for interacting with OpenAI, Anthropic, and local OpenAI-compatible LLM APIs. It includes built-in cost calculation and health checks, lazily loading the required SDKs only when a specific provider is instantiated.

@reaatech/llm-judge-providers

npm version License: MIT CI

Status: Pre-1.0 — APIs may change in minor versions. Pin to a specific version in production.

LLM provider implementations with a factory pattern for OpenAI, Anthropic, and local (OpenAI-compatible) endpoints. All providers implement the shared LLMProvider interface with dynamic SDK loading.

Installation

terminal
npm install @reaatech/llm-judge-providers
# or
pnpm add @reaatech/llm-judge-providers

For provider SDKs (optional, lazily loaded):

terminal
npm install openai               # for OpenAIProvider
npm install @anthropic-ai/sdk    # for AnthropicProvider

Feature Overview

  • OpenAI provider — GPT-4o, GPT-4o-mini, GPT-4 Turbo with per-model pricing tables
  • Anthropic provider — Claude 3.5 Sonnet, Claude 3 Haiku with system/user message separation
  • Local provider — raw fetch to any OpenAI-compatible endpoint (Ollama, vLLM, LM Studio)
  • ProviderFactorycreate() for explicit config, fromEnv() for environment variable resolution
  • Dynamic SDK loading — SDKs only loaded when a provider is actually instantiated
  • Built-in cost calculation — per-million-token pricing in USD for every model
  • Health checkscheckHealth() returns latency and status per provider

Quick Start

typescript
import { ProviderFactory } from "@reaatech/llm-judge-providers";
 
// From environment variables (uses LLM_JUDGE_PROVIDER or defaults to 'openai')
const provider = ProviderFactory.fromEnv();
 
// Or create explicitly by name
const localProvider = ProviderFactory.create({ name: "local" });
 
const response = await provider.generateCompletion({
  model: "gpt-4o-mini",
  messages: [
    { role: "system", content: "You are an evaluator." },
    { role: "user", content: "Score this response: ..." },
  ],
  temperature: 0.1,
  maxTokens: 2000,
});
 
console.log(response.content);
console.log(provider.calculateCost(response.usage));

API Reference

OpenAIProvider

Constructor options:

PropertyTypeRequiredDescription
apiKeystringYesOpenAI API key
baseURLstringNoCustom endpoint URL
timeoutnumberNoRequest timeout in ms (default: 30000)

Supported models:

ModelContext WindowStreaming
gpt-4o128KYes
gpt-4o-mini128KYes
gpt-4-turbo128KYes

Per-model pricing (per 1M tokens):

ModelInputOutput
gpt-4o$2.50$10.00
gpt-4o-mini$0.15$0.60
gpt-4-turbo$10.00$30.00

AnthropicProvider

Constructor options:

PropertyTypeRequiredDescription
apiKeystringYesAnthropic API key
baseURLstringNoCustom endpoint URL
timeoutnumberNoRequest timeout in ms (default: 30000)

Supported models:

ModelContext WindowStreaming
claude-3-5-sonnet-20241022200KYes
claude-3-haiku-20240307200KYes

Per-model pricing (per 1M tokens):

ModelInputOutput
Claude 3.5 Sonnet$3.00$15.00
Claude 3 Haiku$0.25$1.25

LocalProvider

Constructor options:

PropertyTypeRequiredDefaultDescription
baseURLstringNohttp://localhost:11434OpenAI-compatible endpoint URL
apiKeystringNoOptional auth token
timeoutnumberNo30000Request timeout in ms

ProviderFactory

Static methods:

MethodDescription
create(options)Instantiate a provider by name (openai, anthropic, or local) with explicit config
fromEnv(providerName?)Create from environment variables. Reads LLM_JUDGE_PROVIDER, LLM_JUDGE_API_KEY, OPENAI_API_KEY, ANTHROPIC_API_KEY, LLM_JUDGE_BASE_URL, and LLM_JUDGE_TIMEOUT. Defaults to openai when no provider name is set.

LLMProvider Interface

All providers implement this shared interface from @reaatech/llm-judge-types:

MemberTypeDescription
namestringProvider identifier (openai, anthropic, local)
modelsModelInfo[]Supported models with context window and streaming info
generateCompletion(request)Promise<CompletionResponse>Send a chat completion and return content, usage, and duration
countTokens(text)numberEstimate token count for a text string (characters / 4)
calculateCost(usage)CostBreakdownReturn per-model cost breakdown in USD
checkHealth()Promise<HealthStatus>Ping the endpoint and return healthy, degraded, or unhealthy with latency

License

MIT