Skip to main content

Installation

The package is published to npm as cognisafe. It ships with full TypeScript types — no @types/ package needed.

TypeScript support

The SDK is written in TypeScript and exports proper type definitions. It works with both import (ESM) and require (CJS):

Configuration

Call cognisafe.configure() once at startup, before any LLM calls:

Configuration options

* Required if the corresponding environment variable is not set.

Patching providers

OpenAI

patchOpenAI() sets the baseURL on the default OpenAI client to the Cognisafe proxy. The proxy forwards to https://api.openai.com and logs every call asynchronously.

Anthropic

Anthropic uses direct mode — the SDK wraps messages.create and ships payloads to the backend after the response is returned to your code.

The trace wrapper

For custom LLM endpoints or any call not covered by a patch method:
trace returns a wrapped version of your function. The wrapper captures inputs and outputs and sends them to /internal/log after the function resolves — your code is not blocked.
The Node SDK is published under the same package name (cognisafe) as the Python SDK but is a completely separate implementation. Install via npm install cognisafe, not pip.