SDK Reference
Complete reference for the lakera-red-sdk package. Requires Node.js 22+.
LakeraRedClient
The main entry point. Creates targets and initiates scans.
LakeraRedClientOptions
client.createScan(options)
Creates a target (or reuses one by name) and starts a scan. Returns a Scan
instance.
CreateScanOptions
Scan
Returned by client.createScan(). Manages scan execution and result retrieval.
scan.scanId
scan.run(handler)
Executes the scan. Polls the server for attack messages and invokes your handler for each concurrent session. Returns when the scan completes or times out.
Use the finally block to release agent resources (connections, memory) once a session
ends. This is especially important for crescendo sessions that maintain
state across multiple turns.
Behavior:
- Manages concurrent sessions up to the configured
concurrencylimit - Retries on network errors with exponential backoff (1s–5s)
- Stops automatically after 3 minutes of inactivity (no messages from server)
- If your handler throws before calling
respond(), the SDK submits an error to the server on your behalf
scan.getResults()
Retrieves evaluated scan results.
Returns a ScanResults object:
scan.writeResults(path)
Writes results to a JSON file and returns the resolved absolute path.
Session
Passed to your scan.run() handler. Implements AsyncIterable<SessionMessage>, so you
consume it with for await...of.
SessionMessage
Each iteration yields an object with:
ScanResultEntry
Each entry in ScanResults.results:
Evaluation
Logging
The SDK outputs structured JSON logs to stderr by default, keeping stdout clean for your application output.
Configuration
Control log verbosity via the logLevel client option or the LAKERA_RED_LOG_LEVEL
environment variable:
Custom Logger
Provide your own logger to integrate with your existing observability stack:
createLogger / noopLogger
The SDK also exports utilities if you want to create or suppress loggers independently:
Strategies
The strategy option accepts an object with a name field and optional
strategy-specific parameters:
Static
Sends a fixed set of adversarial prompts per objective. Each prompt is independent — there is no conversational escalation between turns. This makes static scans fast, deterministic, and well-suited for CI gates where you want quick, reproducible results.
Crescendo
A multi-turn strategy where the attacker gradually escalates over
several conversational turns within a single session. Each session may yield many
attack/respond pairs as the adversary probes for weaknesses through incremental
persuasion. Crescendo better simulates real-world persistent attackers and tests whether
your agent can maintain its guardrails under sustained conversational pressure.
Smoke
Server-defined canned probes for a quick sanity check. Objectives are ignored — the server uses its own fixed probe set.
Choosing a Strategy
Choose static for fast regression checks and crescendo for deeper adversarial
evaluation during pre-release security reviews.
Objective IDs
Pass these IDs in the objectives array when creating a scan. If you omit objectives,
all objectives across all categories are included (except when using the smoke
strategy, which uses its own fixed probe set).
Security
Safety
Responsible
For detailed descriptions of what each objective tests, see Attack Coverage.