Skip to main content

JavaScript SDK

Install and configure the Risicare JavaScript/TypeScript SDK.

Get started with Risicare in your Node.js or TypeScript application.

Installation

npm install risicare
# or
yarn add risicare
# or
pnpm add risicare

Requirements

Node.js 18.0.0 or later is required. The tests of the SDK run on Node.js 22. The SDK supports both ESM and CommonJS.

Quick Start

import { init } from 'risicare';
import { patchOpenAI } from 'risicare/openai';
import OpenAI from 'openai';
 
// Initialize Risicare. It reads the key from RISICARE_API_KEY (the key determines the project).
init();
 
// Patch OpenAI for auto-instrumentation
const openai = patchOpenAI(new OpenAI());
 
// All calls are now automatically traced
const response = await openai.chat.completions.create({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: 'Hello!' }],
});

Environment Variables

Configure the SDK without hardcoding options (the JS SDK still requires an init() call):

export RISICARE_API_KEY="rsk-..."
export RISICARE_ENVIRONMENT="production"
export RISICARE_SERVICE_NAME="my-agent"
export RISICARE_TRACING="true"

Sub-Path Imports

Provider patches are available via sub-path imports:

// Provider patches — always import from sub-paths
import { patchOpenAI } from 'risicare/openai';
import { patchAnthropic } from 'risicare/anthropic';
import { patchVercelAI } from 'risicare/vercel-ai';
 
// Core functions — import from main package
import { init, agent, session, traceThink } from 'risicare';

ESM vs CommonJS

The SDK supports both module systems:

import { init, agent, session } from 'risicare';
import { patchOpenAI } from 'risicare/openai';
const { init, agent, session } = require('risicare');
const { patchOpenAI } = require('risicare/openai');

TypeScript Support

Full TypeScript support with exported types:

import type { RisicareConfig, Span, SpanKind } from 'risicare';
 
const config: RisicareConfig = {
  // the key comes from RISICARE_API_KEY: do not pass it here
  serviceName: 'my-agent',
  environment: 'production',
};

Next Steps