Guardrailz
HomeHubBlogsPricingDocs

Introduction

  • Overview
  • Architecture
  • Core Concepts

Getting Started

  • Installation
  • Quickstart
  • Playground

API

  • Validate API
  • Profiles API
  • Analytics API
  • Error Handling

SDK

  • Overview
  • Client
  • Guardrails
  • Examples

Guardrails

  • Overview
  • Input Guardrails
  • Output Guardrails
  • Tool Guardrails
  • Custom Guardrails

Profiles

  • Overview
  • Built-in Profiles
  • Custom Profiles
  • Profile Compilation

Analytics

  • Overview
  • Events
  • Queries
  • Dashboards

Deployment

  • Environment
  • Security
  • Scaling
  1. Docs
  2. /sdk
  3. /client

Client Setup

The GuardrailsClient is the main entry point to the SDK.

It manages authentication, retries, timeouts, and communication with the Guardrails API.

Installation

Install the SDK via npm:

npm install @guardrailz/sdk

Or using yarn:

yarn add @guardrailz/sdk

Creating a client

import { GuardrailsClient } from '@guardrailz/sdk';
 
const client = new GuardrailsClient({
  apiKey: process.env.GUARDRAILS_API_KEY!,
  baseUrl: 'https://api.guardrails.dev',
});

Configuration options

| Option    | Type   | Description             |
|--         |-       |                         |
| apiKey    | string | Your Guardrails API key |
| baseUrl   | string | API base URL            |
| timeoutMs | number | Request timeout         |
| retries   | number | Retry attempts          |

All options are optional except apiKey.

Client lifecycle

The client is stateless and safe to reuse.

Recommended pattern:

export const guardrails = new GuardrailsClient({
  apiKey: process.env.GUARDRAILS_API_KEY!,
});

Error handling

Errors are returned as structured SDK errors:

try {
  await client.validate(...);
} catch (err) {
  console.error(err.code, err.message);
}

Next steps

  • Learn how validation works → Guardrails