Docs/Configuration

Configuration

Environment variables, API key formats, provider configuration, and SDK options.

Environment Variables

VariableRequiredDescription
INVARIANCE_API_KEYYesAPI key for authentication. Formats: inv_*, dev_*, org_*
INVARIANCE_API_URLNoAPI endpoint. Default: https://api.useinvariance.com
INVARIANCE_PRIVATE_KEYNoEd25519 private key (64 hex chars) for signing receipts
ANTHROPIC_API_KEYNoRequired for Anthropic/Claude LLM judge evals
OPENAI_API_KEYNoRequired for OpenAI/GPT LLM judge evals
EVAL_JUDGE_MOCKNoSet to true for deterministic mock scoring (no API calls)

API Key Formats

Invariance uses tiered API keys with different permission levels:

PrefixTypeScope
dev_*DeveloperFull access to developer resources
org_*OrganizationAccess scoped to organization resources
inv_*Scoped API KeyPer-function access control via api_keys table
(agent key)AgentPer-agent auth, scoped to agent resources

Eval Configuration

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.

Mock mode for testingbash
# Deterministic scoring — no API calls, reproducible results
export EVAL_JUDGE_MOCK=true
invariance evals run <suite-id> --agent-id my-agent

Built-in Assertion Checks

These assertions run deterministically without API keys:

CheckParametersDescription
toHaveNoErrorsnoneNo error nodes in trace
toContainActionaction_typeTrace contains a specific action type
toHaveCountcountExact node count match
toHaveCountAtLeastminMinimum node count
toHaveDurationBelowmax_msTotal execution under threshold
toHaveChainIntegritynoneHash chain is valid and unbroken
toHaveAnomalyScoreBelowmax_scoreAll anomaly scores below threshold (default 0.5)

Provider Targets

Judge-based eval cases use a ProviderTarget to specify which LLM to use:

ProviderTargettypescript
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',
};

SDK Configuration

Full configuration object for Invariance.init():

InvarianceConfigtypescript
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
}

Example .env File

.envbash
# ── 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
On this page
Environment VariablesAPI Key FormatsEval ConfigurationProvider TargetsSDK ConfigurationExample .env File