Skip to main content

Config Hot-Reload

The SDK watches .complior/proxy.toml (or a custom path) for changes and reloads configuration without restarting your application.
  • File changes are debounced at 100ms
  • Programmatic config takes precedence over file-based config on conflicts
  • The pipeline is rebuilt on each config change — no stale state

ConfigWatcher API

For direct access to the watcher:

Retry

Automatic retry with exponential backoff and jitter for transient errors.

Retryable Errors

Compliance errors (MiddlewareError and all subclasses) are never retried. A ProhibitedPracticeError or BiasDetectedError will always propagate immediately.

Delay Formula

Standalone Usage

The retry utility can be used independently:

Streaming

The SDK handles AsyncIterable (streaming) responses transparently:
  1. Stream chunks are yielded immediately to the caller (no buffering delay)
  2. Delta text is accumulated internally
  3. After the stream completes, post-hooks run on the accumulated text
  4. Compliance metadata is attached to the final result
Supported stream formats:
  • OpenAI: choices[0].delta.content
  • Anthropic: delta.text
Post-hook errors on streamed content are non-fatal — content has already been delivered to the caller. Errors are silently caught.

Interaction Logger

Structured JSONL logging for compliance audit trails (OBL-006, Art.12).

Log Entry Format

Each LLM call produces one JSONL line:

Behavior

  • Logging is fire-and-forget — I/O never blocks the response pipeline
  • Log write failures are silently suppressed (non-critical)
  • Auto-rotates at 100 MB — old file is renamed with timestamp suffix
  • Directory is created automatically on first write

Provider Detection

The SDK auto-detects LLM providers using a 3-step strategy:
1

Symbol Hint

Check for Symbol.for('complior:provider') property on the client — user-provided override.
2

Constructor Name

Match client.constructor.name against known providers: OpenAI, AzureOpenAI, Anthropic.
3

Property Inspection

Check for characteristic properties: chat (OpenAI), messages (Anthropic), generateContent (Google), streamText/generateText (Vercel AI).
Detection determines which methods are intercepted:

Proxy Architecture

The SDK uses a 3-layer JavaScript Proxy design:
  • The original client object is never modified
  • Non-intercepted properties pass through to the original via Reflect.get
  • Config watcher is cleaned up via Symbol.for('complior:close')

Configuration

Full MiddlewareConfig and TOML reference.

HTTP Middleware

Express, Fastify, Hono, Next.js adapters.