5-minute setup

Quickstart guide

Intercept your first AI response in under five minutes. This guide walks through installing the SDK, authenticating, activating a policy, and verifying your first compliant output.

Quickstart

This guide takes you from zero to a live intercept in four steps. Prerequisites: an active ZeroDrift account and your preferred language runtime (Python 3.9+, Node.js 18+, or Go 1.21+).

Step 1: Install the SDK

Choose the SDK for your stack. All three are thin wrappers around the REST API and add no external dependencies beyond an HTTP client.

Terminal bash
# Python
pip install zerodrift

# Node.js
npm install @zerodrift/sdk

# Go
go get github.com/zerodrift/zerodrift-go

Step 2: Set your API key

All SDK calls authenticate with a bearer token. Grab your key from the ZeroDrift dashboard under Settings > API Keys. Store it as an environment variable, never hardcode it in source.

Terminal bash
export ZERODRIFT_API_KEY="zdr_live_..."

Step 3: Activate a policy

Before you can intercept, you need at least one active policy. Use the pre-built financial-advice-guard policy to get started immediately. You can customize or create your own policies at any time.

activate_policy.py python
import zerodrift

client = zerodrift.Client()  # reads ZERODRIFT_API_KEY from env

# Activate the built-in financial advice guardrail
policy = client.policies.activate(
    template="financial-advice-guard",
    label="my-first-policy"
)

print(policy.id)  # pol_xxxxxxxxxxxxxxxx

Step 4: Intercept a response

Now wrap your model call. Pass the raw model output to client.intercept() along with the policy ID you just activated. ZeroDrift returns the policy-compliant version of the response within 30 milliseconds.

intercept_example.py python
import zerodrift
import openai

zdr = zerodrift.Client()
oai = openai.OpenAI()

# Get a raw model response
raw = oai.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": user_message}]
)
raw_text = raw.choices[0].message.content

# Pass through ZeroDrift
result = zdr.intercept(
    text=raw_text,
    policies=["pol_xxxxxxxxxxxxxxxx"],
    context={"user_role": "anonymous", "channel": "web-chat"}
)

# result.text is the policy-compliant output
# result.triggered_rules lists any rules that fired
return result.text

What happens if a rule triggers?

The result object always contains a clean, deliverable text field. If no rules triggered, that is the original model output. If one or more rules fired, text is the rewritten or blocked version depending on how the rule is configured. Check result.triggered_rules if you want to log or audit which rules were applied.

Node.js example

intercept.js javascript
import { Client } from '@zerodrift/sdk';

const zdr = new Client();  // reads ZERODRIFT_API_KEY from env

const result = await zdr.intercept({
  text: rawModelOutput,
  policies: ['pol_xxxxxxxxxxxxxxxx'],
  context: { userRole: 'anonymous' }
});

console.log(result.text);           // compliant output
console.log(result.triggeredRules);  // [] if clean

Go example

main.go go
package main

import (
    "fmt"
    zerodrift "github.com/zerodrift/zerodrift-go"
)

func main() {
    client := zerodrift.NewClient()  // reads ZERODRIFT_API_KEY from env

    result, err := client.Intercept(zerodrift.InterceptRequest{
        Text:     rawModelOutput,
        Policies: []string{"pol_xxxxxxxxxxxxxxxx"},
        Context:  map[string]string{"userRole": "anonymous"},
    })
    if err != nil {
        panic(err)
    }

    fmt.Println(result.Text)           // compliant output
    fmt.Println(result.TriggeredRules)  // empty slice if clean
}

Next steps

You are now intercepting AI responses with a live policy. From here you can:

  • Browse the API Reference for the full intercept schema and all available endpoints.
  • Create a custom policy from the dashboard or via the Policies API.
  • Query the Audit Log to review every intercept event in your account.
  • Configure webhooks to receive real-time notifications when high-severity rules trigger.