VernLLMVernLLM

VernLLM

A lightweight resilience layer for OpenAI-compatible chat completions

Production-grade LLM calls, without the bloat

vern-llm is a resilience layer for LLM applications. A lightweight wrapper that adds retries, timeouts, circuit breakers, caching, structured outputs, schema validation, usage tracking, and observability with sensible defaults and minimal dependencies.

import OpenAI from 'openai';
import { VernLLM } from 'vern-llm';

const llm = new VernLLM({
  client: new OpenAI({ apiKey: process.env.OPENAI_API_KEY }),
  model: 'gpt-4o',

  // Reliability defaults
  maxRetries: 3,
  timeoutMs: 10_000,
  circuitBreaker: true,

  // Observability
  onUsage: ({ totalTokens }) => {
    console.log(`Used ${totalTokens} tokens`);
  },
});

const summary = await llm.cachedLLMCall({
  cacheKey: `resume:${resumeId}`,
  ttl: 3600,

  call: {
    systemPrompt: 'Analyze this resume and return structured hiring insights.',
    userContent: resumeText,
    schema: HiringSummarySchema, // Zod Schema
  },
});

// Typed, validated, cached, retried, timeout-protected LLM output.

Why vern-llm?

  • Retries with backoff: transient failures get retried automatically. Parse errors, validation errors, and non retryable status codes fail fast instead
  • Structured output: pass a Zod schema and get a typed, validated result back
  • Provider native JSON Schema mode: constrain generation itself, not just validate after the fact
  • Caching: wrap any call with cachedCall or cachedLLMCall, and bring your own adapter such as Redis or Upstash
  • Circuit breaker: trips after repeated failures and recovers automatically once the provider is healthy again
  • One interface, every provider: OpenAI, Groq, Mistral, DeepSeek, Cerebras, Together, Fireworks, Ollama, Anthropic, Gemini, Bedrock, or raw HTTP through fromFetch
  • Zero bundled dependencies: zod and provider SDKs are peer dependencies. The package only depends on compatible interfaces rather than specific provider implementations

On this page