Skip to main content

JS Configuration

Configure the Risicare JavaScript SDK.

Complete configuration reference for the JavaScript/TypeScript SDK.

RisicareConfig Interface

interface RisicareConfig {
  // Required
  apiKey?: string;          // Each key is scoped to one project
 
  // Deprecated
  projectId?: string;       // DEPRECATED — emits console.warn. Will be removed in v1.0.
 
  // Optional
  endpoint?: string;        // Where spans go
  apiEndpoint?: string;     // Where scores go
  environment?: string;     // Within-project organization
  serviceName?: string;     // Within-project organization
  serviceVersion?: string;
  enabled?: boolean;
  traceContent?: boolean;
  errorText?: boolean | 'auto';
  flushOnCrash?: boolean;
  streamUsage?: boolean | 'auto';
  traceStreamHelpers?: boolean;
  compress?: boolean;
  sampleRate?: number;
  batchSize?: number;
  batchTimeoutMs?: number;
  maxQueueSize?: number;
  retryHorizonS?: number;
  shutdownTimeoutS?: number;
  maxInputMessagesBytes?: number;
  debug?: boolean;
  fixRuntime?: boolean;
  metadata?: Record<string, unknown>;
  mask?: (key: string, value: unknown) => unknown;
}

Configuration Options

OptionTypeDefaultDescription
apiKeystringenvAPI key (or RISICARE_API_KEY). Each key is scoped to one project.
projectIdstringenvDeprecated — emits console.warn. Project is derived from the API key; will be removed in v1.0.
endpointstring"https://ingest.risicare.ai"Ingest gateway URL. The SDK sends spans to this host.
apiEndpointstring"https://api.risicare.ai"API URL. The SDK sends scores, prompt pulls, evaluation runs and fix reads to this host. If you pass endpoint (not the default ingest host) and no apiEndpoint, these requests go to endpoint, also when RISICARE_API_ENDPOINT is set.
environmentstring"development"Environment name (within-project org)
serviceNamestringundefinedService name (within-project org). The SDK writes it as service.name on every span that it makes, also on the spans made inside agent() (since 0.19.0)
serviceVersionstringundefinedService version. The SDK puts it on every span as service.version
enabledbooleantrueEnable tracing (true if apiKey provided)
traceContentbooleantrueCapture prompts, completions and the arguments of tool calls. On by default since 0.10.0. Pass traceContent: false (or set RISICARE_TRACE_CONTENT=false) to keep content in your process. With it off, the text of an error is withheld too (see errorText). You can also turn content off in the project settings. The gateway then drops the content of that project, but the text has already left your process
errorTextboolean | 'auto''auto'Whether the text of an error leaves your process. The error text is the status message, the exception messages, error.message, exception.message and error.stack. 'auto' follows traceContent: with content capture off, each such value is replaced with <risicare:content-omitted>. true sends it also with content capture off: use it only when you need the messages and accept that an error message can carry prompt or model output. false withholds it also with content capture on. The error type, error.code, the status and the frame lines of a stack stay
flushOnCrashbooleanfalseNode.js only. Send the queued spans when Node.js is about to end the process for an uncaught exception or an unhandled rejection. The main thread waits at most 2,000 ms. The SDK never takes the crash from your code. See Uncaught exceptions in Node.js
streamUsageboolean | 'auto''auto'Whether the SDK asks OpenAI for the token counts of a streamed Chat Completions call when your call does not set stream_options. true asks on any host. 'auto' and false do not ask in JavaScript, because asResponse(), toReadableStream() and tee() hand over the raw stream, where the extra usage chunk would show. A host that refuses the field fails that one call, with one warning
traceStreamHelpersbooleantrueTrace the stream helpers of the openai package: responses.stream(), chat.completions.stream() and beta.chat.completions.stream(). With false, a helper runs exactly as without Risicare and makes no span. create({ stream: true }) stays traced
compressbooleanfalseEnable gzip compression for exports
sampleRatenumber1.0Trace sampling rate (0-1)
batchSizenumber500Spans per batch
batchTimeoutMsnumber1000Milliseconds between flushes
maxQueueSizenumber10000Max queued spans. When the queue is full, the SDK drops the oldest queued span and keeps the new one (the new span was dropped through 0.10.0). The queue also has a byte bound, maxQueueBytes (default 64 MiB, from 1 MiB to 4 GiB) since 0.19.0. It is an option of BatchSpanProcessor, and init() does not take it
retryHorizonSnumber300How long the HTTP exporter retries one batch, in seconds from its first attempt. A batch that the gateway does not take in that time is dropped (retry_exhausted). 0 sends each batch once. It has no environment variable
shutdownTimeoutSnumber10The budget of shutdown(), in seconds. It is also the budget of the SDK's own teardown at beforeExit, and at SIGTERM and SIGINT when your application has no listener for the signal. When it has a listener, the SDK shuts down shutdownTimeoutS after the signal if the process still runs. Spans that the SDK cannot send in that time are counted as shutdown_residue. It has no environment variable. Through 0.10.0 the budget was 5 s
maxInputMessagesBytesnumber49152The cap of gen_ai.input.messages (the whole message list of an OpenAI or Anthropic call), in UTF-8 bytes. A value below 1,024 or above 65,535 is clamped, with one warning. A list above the cap is cut: the first and last messages stay. Raise it for long prompts. It has no environment variable. See OpenAI
debugbooleanfalseEnable debug logging
fixRuntimebooleanfalseStart the fix runtime. It is off by default since 0.7.0. During the beta the Risicare service gives no fixes to customer projects, so keep it off.
metadataobjectGlobal metadata for all traces
maskfunctionundefinedFunction mask(key, value) that returns the value to export. It runs on content-bearing fields before export. If it throws, the field becomes "<risicare:mask-error>" and the span is still exported. It has no environment variable.

With no API key the SDK sends nothing

With no key (also a key of only whitespace; the SDK trims the key), tracing is off: no span is created, nothing is sent to Risicare, isEnabled() and flush() return false, and nothing is counted as exported or dropped. init() writes one WARNING that says so and names the RISICARE_API_KEY environment variable (none when you turned tracing off on purpose). Since npm 0.19.1, the WARNING names the environment variable only; through 0.19.0 it also said to pass apiKey to init(). Keep the key out of your code: set RISICARE_API_KEY, and call init() with no apiKey. RISICARE_TRACING=true, enabled: true and enable() cannot turn tracing on without a key, and debug: true prints no span. An apiKey option that is empty counts as not given, so RISICARE_API_KEY applies. In 0.8.0 and earlier, with RISICARE_TRACING=true and no key, the SDK created spans and dropped them after four export rounds.

Environment Variable Mapping

ConfigEnvironment Variable
apiKeyRISICARE_API_KEY
projectId (deprecated)RISICARE_PROJECT_ID
endpointRISICARE_ENDPOINT
apiEndpointRISICARE_API_ENDPOINT
environmentRISICARE_ENVIRONMENT
enabledRISICARE_TRACING
traceContentRISICARE_TRACE_CONTENT
errorTextRISICARE_ERROR_TEXT
flushOnCrashRISICARE_FLUSH_ON_CRASH
streamUsageRISICARE_STREAM_USAGE
traceStreamHelpersRISICARE_TRACE_STREAM_HELPERS
sampleRateRISICARE_SAMPLE_RATE
compressRISICARE_COMPRESS
batchSizeRISICARE_BATCH_SIZE
batchTimeoutMsRISICARE_BATCH_TIMEOUT_MS
maxQueueSizeRISICARE_MAX_QUEUE_SIZE
serviceNameRISICARE_SERVICE_NAME
serviceVersionRISICARE_SERVICE_VERSION
debugRISICARE_DEBUG
fixRuntimeRISICARE_FIX_RUNTIME

The JavaScript SDK reads these twenty variables. It also reads four variables for prompts and evaluations: RISICARE_PROMPT_CACHE_TTL_S, RISICARE_PROMPT_TIMEOUT_S, RISICARE_PROMPT_LABEL and RISICARE_EVAL_STATE. metadata, mask, retryHorizonS, shutdownTimeoutS and maxInputMessagesBytes have no environment variable.

Since 0.19.0, one parser reads every boolean variable: RISICARE_TRACING, RISICARE_TRACE_CONTENT, RISICARE_TRACE_STREAM_HELPERS, RISICARE_DEBUG, RISICARE_COMPRESS, RISICARE_FIX_RUNTIME and RISICARE_FLUSH_ON_CRASH. The words for on are true, 1, yes and on. The words for off are false, 0, no and off. The SDK trims the value and ignores the case. on, off and no are new for the switches other than RISICARE_TRACING: before, RISICARE_TRACE_CONTENT=on read as off.

A value that is not one of these words writes one WARNING. For a switch that sends data or makes requests when it is on, such a value means off. For the other switches, it keeps the default. An empty RISICARE_TRACE_CONTENT or RISICARE_TRACE_STREAM_HELPERS is off, as before, now with one WARNING. For RISICARE_TRACING, an empty value is the same as no value, and an unknown value turns tracing off. Each WARNING is written one time for each value.

RISICARE_ERROR_TEXT and RISICARE_STREAM_USAGE have their own rule too: they take auto, true or false (also 1, yes, on, 0, no and off). An empty value is auto. Any other value writes one warning, and the option stays auto.

Runtime Control

Enable/Disable

import { enable, disable, isEnabled } from 'risicare';
 
// Check status: false before init(), with tracing off, with no API key,
// and after the SDK's own SIGTERM or SIGINT drain
if (isEnabled()) {
  console.log('Tracing is active');
}
 
// Disable temporarily
disable();
 
// Re-enable
enable();

Flush and Shutdown

import { flush, shutdown } from 'risicare';
 
// Send the spans queued so far. Resolves true only when every span and score
// that the SDK accepted was acknowledged; false for a loss (once), before init(),
// with tracing off, and with no API key. Also exact in a SIGTERM listener.
const delivered = await flush();
 
// Graceful shutdown. The budget is the shutdownTimeoutS of init(), default 10 s.
await shutdown();
 
// Or give a budget in milliseconds
await shutdown(1000);

At SIGTERM and SIGINT, the SDK does not shut down when your application has a listener for the signal (since 0.19.0). See SIGTERM and SIGINT. A shutdown() that cannot send every span in its budget counts the rest as shutdown_residue. A span that starts after shutdown() is not made. The SDK counts it as after_shutdown, and the next flush() resolves false. In a serverless function, call await flush() at the end of each invocation, and await shutdown() only where the process ends. See Serverless functions. docker stop waits 10 s by default, so set shutdownTimeoutS lower when your application needs time for its own cleanup.

Configuration Precedence

Configuration is resolved in order (highest priority first):

  1. Explicit init() parameters
  2. Environment variables
  3. Default values

Advanced Configuration

Custom Endpoint

Override the default gateway endpoint (https://ingest.risicare.ai) — for example, to send spans through an outbound proxy your network requires:

init({
  endpoint: 'https://llm-egress-proxy.internal.example.com', // the key comes from RISICARE_API_KEY
});

endpoint sets where the SDK sends spans. If you do not also pass apiEndpoint, the SDK sends scores, prompt pulls, evaluation runs and fix reads to the same host as endpoint, unless endpoint is the default ingest host. To send them to a different host, pass apiEndpoint: when endpoint is passed as an option, RISICARE_API_ENDPOINT does not override it.

Do not set endpoint to the dashboard address

https://app.risicare.ai is the dashboard. It is not the ingest gateway. Leave endpoint and apiEndpoint unset to use the defaults.

Risicare is a hosted service

Risicare runs as a managed service. There is no self-hosted or on-premise Risicare instance to point this at — endpoint and apiEndpoint retarget where the SDK sends its requests (a proxy or a non-default host), not where Risicare itself runs.

Sampling

Control trace sampling rate:

init({
  sampleRate: 0.1, // Sample 10% of traces; the key comes from RISICARE_API_KEY
});

Next Steps