Environment variables, API key formats, provider configuration, and SDK options.
| Variable | Required | Description |
|---|---|---|
INVARIANCE_API_KEY | Yes | API key for authentication. Formats: inv_*, dev_*, org_* |
INVARIANCE_API_URL | No | API endpoint. Default: https://api.useinvariance.com |
INVARIANCE_PRIVATE_KEY | No | Ed25519 private key (64 hex chars) for signing receipts |
ANTHROPIC_API_KEY | No | Required for Anthropic/Claude LLM judge evals |
OPENAI_API_KEY | No | Required for OpenAI/GPT LLM judge evals |
EVAL_JUDGE_MOCK | No | Set to true for deterministic mock scoring (no API calls) |
Invariance uses tiered API keys with different permission levels:
| Prefix | Type | Scope |
|---|---|---|
dev_* | Developer | Full access to developer resources |
org_* | Organization | Access scoped to organization resources |
inv_* | Scoped API Key | Per-function access control via api_keys table |
(agent key) | Agent | Per-agent auth, scoped to agent resources |
LLM judge evals require provider API keys. If no key is available and EVAL_JUDGE_MOCK is not set, the system automatically falls back to mock mode with deterministic scoring.
# Deterministic scoring — no API calls, reproducible results
export EVAL_JUDGE_MOCK=true
invariance evals run <suite-id> --agent-id my-agentThese assertions run deterministically without API keys:
| Check | Parameters | Description |
|---|---|---|
toHaveNoErrors | none | No error nodes in trace |
toContainAction | action_type | Trace contains a specific action type |
toHaveCount | count | Exact node count match |
toHaveCountAtLeast | min | Minimum node count |
toHaveDurationBelow | max_ms | Total execution under threshold |
toHaveChainIntegrity | none | Hash chain is valid and unbroken |
toHaveAnomalyScoreBelow | max_score | All anomaly scores below threshold (default 0.5) |
Judge-based eval cases use a ProviderTarget to specify which LLM to use:
interface ProviderTarget {
provider: 'anthropic' | 'openai';
model: string;
api_key_env?: string; // Custom env var (default: ANTHROPIC_API_KEY / OPENAI_API_KEY)
base_url_env?: string; // Custom endpoint URL env var (for OpenAI-compatible APIs)
}
// Example: use Anthropic Claude
const target: ProviderTarget = {
provider: 'anthropic',
model: 'claude-sonnet-4-20250514',
};
// Example: use custom OpenAI-compatible endpoint
const customTarget: ProviderTarget = {
provider: 'openai',
model: 'gpt-4o',
api_key_env: 'MY_CUSTOM_KEY',
base_url_env: 'LM_STUDIO_URL',
};Full configuration object for Invariance.init():
interface InvarianceConfig {
apiKey: string; // Required. API key for authentication
apiUrl?: string; // Default: "https://api.useinvariance.com"
privateKey?: string; // Ed25519 private key (64 hex chars)
policies?: PolicyRule[]; // Local policy rules
flushIntervalMs?: number; // Batch flush interval (default: 5000ms)
maxBatchSize?: number; // Max batch size (default: 50)
maxQueueSize?: number; // Max queue size (default: 1000)
onError?: (err: InvarianceError) => void; // Error callback
mode?: 'DEV' | 'PROD'; // Observability mode (default: 'PROD')
sampleRate?: number; // Trace sampling rate in PROD mode
anomalyThreshold?: number; // Anomaly detection threshold
onAnomaly?: (node: TraceEvent) => void; // Anomaly callback
devOutput?: 'ui' | 'console' | 'both'; // DEV mode output
onMonitorTrigger?: (event: MonitorTriggerEvent) => void; // Monitor callback
monitorPollIntervalMs?: number; // Monitor poll interval
}# ── Invariance Core ──
INVARIANCE_API_KEY=inv_8417fb46c0f79dec84eb91ccf08e2ca20a0932ea9e4bdc7ec11cedff22914ffd
INVARIANCE_API_URL=https://api.useinvariance.com
INVARIANCE_PRIVATE_KEY=28fb14d95e2ac3126d23b82497b0d4e8e4b04473a46015d939e9979fd84fce8e
# ── LLM Providers (for judge evals) ──
ANTHROPIC_API_KEY=sk-ant-api03-...
OPENAI_API_KEY=sk-...
# ── Testing ──
# EVAL_JUDGE_MOCK=true