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/sdkOr using yarn:
yarn add @guardrailz/sdkCreating 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