AI Toolkit
Modulesconfig

config

Validate environment variables and typed configuration with Zod

Overview

The config module provides Zod-based environment validation and toolkit initialization. Every app starts with initToolkit().

No peer dependencies required.

Quick Start

import { initToolkit } from '@jamaalbuilds/ai-toolkit/config';

// Reads from process.env by default
const { config, has } = initToolkit();

// Or pass env vars explicitly
const { config: cfg, has: hasFeature } = initToolkit({
  ANTHROPIC_API_KEY: 'sk-...',
  DATABASE_URL: 'postgresql://...',
});

console.log(hasFeature('anthropic')); // true

API Reference

initToolkit(config)

Initialize the toolkit with validated configuration.

function initToolkit(env?: Record<string, string | undefined>): ToolkitInstances
ParameterTypeDescription
envRecord<string, string | undefined>Environment variables (default: process.env)

parseConfig(env)

Parse and validate a raw config object against the toolkit schema.

function parseConfig(env: Record<string, unknown>): ToolkitConfig

toolkitConfigSchema

Zod schema for the full toolkit configuration. Use for custom validation.

Types

  • ToolkitConfig — full validated config object
  • ToolkitInstances — initialized service instances
On this page

On this page