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.
# 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.
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.
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.
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
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
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.