Skip to main content

Overview

The init() function initializes the ZeroEval SDK with your API credentials and configuration options. You must call this function before using any other SDK features.
import * as ze from 'zeroeval';

ze.init({
  apiKey: 'your-api-key',
  workspaceName: 'My Project'
});

Function Signature

function init(opts?: InitOptions): void

Parameters

opts
InitOptions
default:"{}"
Configuration options for the SDK

Returns

void
void
This function does not return a value.

Examples

Basic initialization

import * as ze from 'zeroeval';

ze.init({
  apiKey: process.env.ZEROEVAL_API_KEY
});

Custom configuration

ze.init({
  apiKey: 'your-api-key',
  workspaceName: 'Production',
  flushInterval: 5,  // Flush every 5 seconds
  maxSpans: 200,     // Buffer up to 200 spans
  debug: true        // Enable debug logging
});

Using environment variables

// Set ZEROEVAL_API_KEY and ZEROEVAL_WORKSPACE_NAME in your environment
ze.init();

Helper Functions

isInitialized()

Check if the SDK has been initialized.
function isInitialized(): boolean
Example:
if (!ze.isInitialized()) {
  ze.init({ apiKey: process.env.ZEROEVAL_API_KEY });
}

validateInit()

Validate that the SDK has been properly initialized with required credentials. Returns false and logs an error if the API key or workspace name is missing.
function validateInit(): boolean
Example:
if (!ze.validateInit()) {
  throw new Error('ZeroEval SDK not properly initialized');
}

Environment Variables

You can configure the SDK using environment variables instead of passing options to init():
  • ZEROEVAL_API_KEY - Your API key
  • ZEROEVAL_API_URL - Custom API URL (defaults to https://api.zeroeval.com)
  • ZEROEVAL_WORKSPACE_NAME - Workspace name
  • ZEROEVAL_DEBUG - Set to true to enable debug logging

Notes

  • You should call init() once at the start of your application, before using any tracing features
  • The SDK automatically sets up integrations for OpenAI, Vercel AI SDK, and LangChain if they are installed
  • In debug mode, the SDK logs all configuration values (with API key masked) to help troubleshoot setup issues

Build docs developers (and LLMs) love